Merge branch 'persist-library-dialog' of https://github.com/doompadee/Phonograph into doompadee-persist-library-dialog
This commit is contained in:
commit
6dcbfa0b72
2 changed files with 41 additions and 2 deletions
|
|
@ -1,8 +1,11 @@
|
||||||
package com.kabouzeid.gramophone.model;
|
package com.kabouzeid.gramophone.model;
|
||||||
|
|
||||||
|
import android.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
|
||||||
public class CategoryInfo {
|
public class CategoryInfo implements Parcelable {
|
||||||
public Category category;
|
public Category category;
|
||||||
public boolean visible;
|
public boolean visible;
|
||||||
|
|
||||||
|
|
@ -11,6 +14,32 @@ public class CategoryInfo {
|
||||||
this.visible = visible;
|
this.visible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CategoryInfo(Parcel source) {
|
||||||
|
category = (Category) source.readSerializable();
|
||||||
|
visible = source.readInt() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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 {
|
public enum Category {
|
||||||
SONGS(R.string.songs),
|
SONGS(R.string.songs),
|
||||||
ALBUMS(R.string.albums),
|
ALBUMS(R.string.albums),
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,16 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
||||||
return new LibraryPreferenceDialog();
|
return new LibraryPreferenceDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CategoryInfoAdapter adapter;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
View view = getActivity().getLayoutInflater().inflate(R.layout.preference_dialog_library_categories, null);
|
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 recyclerView = view.findViewById(R.id.recycler_view);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||||
|
|
@ -51,6 +55,12 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putParcelableArrayList(PreferenceUtil.LIBRARY_CATEGORIES, adapter.getCategoryInfos());
|
||||||
|
}
|
||||||
|
|
||||||
private void updateCategories(ArrayList<CategoryInfo> categories) {
|
private void updateCategories(ArrayList<CategoryInfo> categories) {
|
||||||
if (getSelected(categories) == 0) return;
|
if (getSelected(categories) == 0) return;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue