Skip to content

Commit

Permalink
优化首页界面如果因为内存不足等特殊原因导致界面重启,再次恢复界面时,优化专辑下拉列表恢复上次选中
Browse files Browse the repository at this point in the history
  • Loading branch information
hht20 committed Oct 11, 2022
1 parent f5a3058 commit 0aae07f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,6 @@ class Album internal constructor(
bucketDisplayName ?: "",
count
)
// 设置默认第一个是选择所有
if (album.isAll) {
album.isChecked = true
}
return album
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
* 初始化配置
*/
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -517,6 +517,9 @@ public void onSuccess(ArrayList<Album> result) {
mAlbumSpinner.bindFolder(result);
// 可能因为别的原因销毁当前界面,回到当前选择的位置
Album album = result.get(mAlbumCollection.getCurrentSelection());
ArrayList<Album> albumChecks = new ArrayList<>();
albumChecks.add(album);
mAlbumSpinner.updateCheckStatus(albumChecks);
String displayName = album.getDisplayName(mContext);
if (mViewHolder.tvAlbumTitle.getVisibility() == View.VISIBLE) {
mViewHolder.tvAlbumTitle.setText(displayName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,7 @@
import com.zhongjh.common.utils.AnimUtils;
import com.zhongjh.common.utils.DisplayMetricsUtils;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -33,15 +35,16 @@
*/
public class AlbumSpinner extends PopupWindow {
private static final int FOLDER_MAX_COUNT = 8;

private final Context context;
private final View window;
private RecyclerView mRecyclerView;
private AlbumSpinnerAdapter adapter;
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;

Expand Down Expand Up @@ -150,7 +153,7 @@ public void dismiss() {
}

/**
* 设置选中状态
* 设置选中状态 - 红色圆点
*/
public void updateFolderCheckStatus(List<Album> result) {
try {
Expand All @@ -175,6 +178,22 @@ public void updateFolderCheckStatus(List<Album> result) {
}
}

/**
* 设置选中状态
*/
public void updateCheckStatus(List<Album> selects) {
List<Album> 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显示本身
*/
Expand Down

0 comments on commit 0aae07f

Please sign in to comment.