Persist library dialog state between invocations
This commit is contained in:
parent
b468897b89
commit
2daf5f3c4f
2 changed files with 41 additions and 2 deletions
|
|
@ -22,12 +22,16 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
|||
return new LibraryPreferenceDialog();
|
||||
}
|
||||
|
||||
private CategoryInfoAdapter adapter;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.preference_dialog_library_categories, null);
|
||||
|
||||
CategoryInfoAdapter adapter = new CategoryInfoAdapter(PreferenceUtil.getInstance(getContext()).getLibraryCategoryInfos());
|
||||
adapter = new CategoryInfoAdapter(savedInstanceState != null ?
|
||||
savedInstanceState.getParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES) :
|
||||
PreferenceUtil.getInstance(getContext()).getLibraryCategoryInfos());
|
||||
|
||||
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
|
|
@ -51,6 +55,12 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
|||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES, adapter.getCategoryInfos());
|
||||
}
|
||||
|
||||
private void updateCategories(ArrayList<CategoryInfo> categories) {
|
||||
if (getSelected(categories) == 0) return;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue