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