From 0aae07fd609827ca09aabb7d8f1980647bb468a0 Mon Sep 17 00:00:00 2001 From: "740798908@qq.com" <740798908@qq.com> Date: Tue, 11 Oct 2022 14:23:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=A6=96=E9=A1=B5=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E5=A6=82=E6=9E=9C=E5=9B=A0=E4=B8=BA=E5=86=85=E5=AD=98?= =?UTF-8?q?=E4=B8=8D=E8=B6=B3=E7=AD=89=E7=89=B9=E6=AE=8A=E5=8E=9F=E5=9B=A0?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=95=8C=E9=9D=A2=E9=87=8D=E5=90=AF=EF=BC=8C?= =?UTF-8?q?=E5=86=8D=E6=AC=A1=E6=81=A2=E5=A4=8D=E7=95=8C=E9=9D=A2=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B8=93=E8=BE=91=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=81=A2=E5=A4=8D=E4=B8=8A=E6=AC=A1=E9=80=89?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../albumcamerarecorder/album/entity/Album.kt | 4 --- .../album/ui/MatissFragment.java | 17 +++++++------ .../widget/albumspinner/AlbumSpinner.java | 25 ++++++++++++++++--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt index 6fcd887a..09efb0f1 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/entity/Album.kt @@ -104,10 +104,6 @@ class Album internal constructor( bucketDisplayName ?: "", count ) - // 设置默认第一个是选择所有 - if (album.isAll) { - album.isChecked = true - } return album } } diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/ui/MatissFragment.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/ui/MatissFragment.java index d53b369e..a12cbe49 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/ui/MatissFragment.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/ui/MatissFragment.java @@ -183,6 +183,13 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, return view; } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + mSelectedCollection.onSaveInstanceState(outState); + mAlbumCollection.onSaveInstanceState(outState); + } + /** * 初始化配置 */ @@ -388,13 +395,6 @@ private void initActivityResult() { }); } - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - mSelectedCollection.onSaveInstanceState(outState); - mAlbumCollection.onSaveInstanceState(outState); - } - @Override public void onDestroy() { Log.d(TAG, "MatissFragment onDestroy"); @@ -517,6 +517,9 @@ public void onSuccess(ArrayList result) { mAlbumSpinner.bindFolder(result); // 可能因为别的原因销毁当前界面,回到当前选择的位置 Album album = result.get(mAlbumCollection.getCurrentSelection()); + ArrayList albumChecks = new ArrayList<>(); + albumChecks.add(album); + mAlbumSpinner.updateCheckStatus(albumChecks); String displayName = album.getDisplayName(mContext); if (mViewHolder.tvAlbumTitle.getVisibility() == View.VISIBLE) { mViewHolder.tvAlbumTitle.setText(displayName); diff --git a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/widget/albumspinner/AlbumSpinner.java b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/widget/albumspinner/AlbumSpinner.java index 5d6cfb5a..eead1d91 100644 --- a/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/widget/albumspinner/AlbumSpinner.java +++ b/multilibrary/src/main/java/com/zhongjh/albumcamerarecorder/album/widget/albumspinner/AlbumSpinner.java @@ -4,6 +4,7 @@ import android.content.Context; import android.graphics.drawable.Drawable; import android.os.Build; +import android.os.Bundle; import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; @@ -23,6 +24,7 @@ import com.zhongjh.common.utils.AnimUtils; import com.zhongjh.common.utils.DisplayMetricsUtils; +import java.util.ArrayList; import java.util.List; /** @@ -33,6 +35,7 @@ */ public class AlbumSpinner extends PopupWindow { private static final int FOLDER_MAX_COUNT = 8; + private final Context context; private final View window; private RecyclerView mRecyclerView; @@ -40,8 +43,8 @@ public class AlbumSpinner extends PopupWindow { private boolean isDismiss = false; private ImageView ivArrowView; private TextView tvAlbumTitle; - private Drawable drawableUp; - private Drawable drawableDown; + private final Drawable drawableUp; + private final Drawable drawableDown; private final int maxHeight; private View rootViewBg; @@ -150,7 +153,7 @@ public void dismiss() { } /** - * 设置选中状态 + * 设置选中状态 - 红色圆点 */ public void updateFolderCheckStatus(List result) { try { @@ -175,6 +178,22 @@ public void updateFolderCheckStatus(List result) { } } + /** + * 设置选中状态 + */ + public void updateCheckStatus(List selects) { + List albums = adapter.getAlbums(); + for (Album album : albums) { + for (Album select : selects) { + if (select.getDisplayName().equals(album.getDisplayName())) { + album.setChecked(true); + break; + } + } + } + adapter.bindAlbums(albums); + } + /** * 自动绑定相关View显示本身 */