Clean up
This commit is contained in:
parent
ffa33fced7
commit
30dd66e788
3 changed files with 24 additions and 25 deletions
|
|
@ -39,8 +39,10 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHo
|
|||
holder.title.setText(holder.title.getResources().getString(category.id.key));
|
||||
|
||||
holder.itemView.setOnClickListener(v -> {
|
||||
category.visible = !category.visible;
|
||||
holder.checkBox.setChecked(category.visible);
|
||||
if (!(category.visible && isLastCheckedCategory(category))) {
|
||||
category.visible = !category.visible;
|
||||
holder.checkBox.setChecked(category.visible);
|
||||
}
|
||||
});
|
||||
|
||||
holder.dragView.setOnTouchListener((view, event) -> {
|
||||
|
|
@ -79,6 +81,15 @@ public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.ViewHo
|
|||
return categories;
|
||||
}
|
||||
|
||||
private boolean isLastCheckedCategory(Category category) {
|
||||
if (category.visible) {
|
||||
for (Category c : categories) {
|
||||
if (c != category && c.visible) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public CheckBox checkBox;
|
||||
public TextView title;
|
||||
|
|
|
|||
|
|
@ -41,39 +41,28 @@ public class LibraryPreferenceDialog extends DialogFragment {
|
|||
categoriesView.setAdapter(adapter);
|
||||
touchHelper.attachToRecyclerView(categoriesView);
|
||||
|
||||
MaterialDialog dialog = new MaterialDialog.Builder(getContext())
|
||||
return new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.library_categories)
|
||||
.customView(view, false)
|
||||
.positiveText(android.R.string.ok)
|
||||
.negativeText(android.R.string.cancel)
|
||||
.neutralText(R.string.reset_action)
|
||||
.autoDismiss(false)
|
||||
.onNeutral((dialog1, action) -> {
|
||||
.onNeutral((dialog, action) -> {
|
||||
adapter.setCategories(PreferenceUtil.getInstance(getContext()).getDefaultLibraryCategories());
|
||||
})
|
||||
.onNegative((dialog12, action) -> dismiss())
|
||||
.onPositive((dialog13, action) -> {
|
||||
if (!updateCategories(adapter.getCategories())) {
|
||||
new MaterialDialog.Builder(getContext())
|
||||
.title(R.string.edit_categories)
|
||||
.content(R.string.at_least_one_category_must_be_enabled)
|
||||
.positiveText(android.R.string.ok)
|
||||
.show();
|
||||
} else {
|
||||
dismiss();
|
||||
}
|
||||
.onNegative((dialog, action) -> dismiss())
|
||||
.onPositive((dialog, action) -> {
|
||||
updateCategories(adapter.getCategories());
|
||||
dismiss();
|
||||
})
|
||||
.build();
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private boolean updateCategories(ArrayList<Category> categories) {
|
||||
if (getSelected(categories) == 0) return false;
|
||||
private void updateCategories(ArrayList<Category> categories) {
|
||||
if (getSelected(categories) == 0) return;
|
||||
|
||||
PreferenceUtil.getInstance(getContext()).setLibraryCategories(categories);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getSelected(ArrayList<Category> categories) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.preference.PreferenceManager;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StyleRes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.SortOrder;
|
||||
import com.kabouzeid.gramophone.model.Category;
|
||||
|
|
@ -14,13 +15,11 @@ import com.kabouzeid.gramophone.ui.fragments.mainactivity.folders.FoldersFragmen
|
|||
import com.kabouzeid.gramophone.ui.fragments.player.NowPlayingScreen;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
public final class PreferenceUtil {
|
||||
public static final String GENERAL_THEME = "general_theme";
|
||||
public static final String DEFAULT_START_PAGE = "default_start_page";
|
||||
|
|
@ -449,7 +448,7 @@ public final class PreferenceUtil {
|
|||
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putStringSet(LIBRARY_CATEGORIES, data);
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public ArrayList<Category> getLibraryCategories() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue