Persist library dialog state between invocations
This commit is contained in:
parent
b468897b89
commit
2daf5f3c4f
2 changed files with 41 additions and 2 deletions
|
|
@ -1,8 +1,11 @@
|
|||
package com.kabouzeid.gramophone.model;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import com.kabouzeid.gramophone.R;
|
||||
|
||||
public class CategoryInfo {
|
||||
public class CategoryInfo implements Parcelable {
|
||||
public Category category;
|
||||
public boolean visible;
|
||||
|
||||
|
|
@ -11,6 +14,32 @@ public class CategoryInfo {
|
|||
this.visible = visible;
|
||||
}
|
||||
|
||||
public CategoryInfo(Parcel source) {
|
||||
category = (Category) source.readSerializable();
|
||||
visible = source.readInt() == 1 ? true : false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeSerializable(category);
|
||||
dest.writeInt(visible ? 1 : 0);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<CategoryInfo> CREATOR = new Parcelable.Creator<CategoryInfo>() {
|
||||
public CategoryInfo createFromParcel(Parcel source) {
|
||||
return new CategoryInfo(source);
|
||||
}
|
||||
|
||||
public CategoryInfo[] newArray(int size) {
|
||||
return new CategoryInfo[size];
|
||||
}
|
||||
};
|
||||
|
||||
public enum Category {
|
||||
SONGS(R.string.songs),
|
||||
ALBUMS(R.string.albums),
|
||||
|
|
|
|||
|
|
@ -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