From 84c0674e1e46aa57d821b8a112d2895af78fee83 Mon Sep 17 00:00:00 2001 From: RichyHBM Date: Mon, 13 Nov 2017 20:25:53 +0000 Subject: [PATCH] Add no tags toggle --- .../andotp/Activities/MainActivity.java | 16 ++++++++++++ .../flocke/andotp/Utilities/Settings.java | 8 ++++++ .../andotp/View/EntriesCardAdapter.java | 5 +++- app/src/main/res/layout/component_tags.xml | 25 ++++++++++++++++++- app/src/main/res/values/settings.xml | 1 + app/src/main/res/values/strings_main.xml | 1 + 6 files changed, 54 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index 394abccf..3888ea61 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -603,7 +603,9 @@ public class MainActivity extends BaseActivity tagsToggle.setDrawerIndicatorEnabled(true); tagsDrawerLayout.addDrawerListener(tagsToggle); + final CheckedTextView noTagsButton = (CheckedTextView)findViewById(R.id.no_tags_entries); CheckedTextView allTagsButton = (CheckedTextView)findViewById(R.id.all_tags_in_drawer); + allTagsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -616,6 +618,8 @@ public class MainActivity extends BaseActivity CheckedTextView childCheckBox = (CheckedTextView)tagsDrawerListView.getChildAt(i); childCheckBox.setChecked(checkedTextView.isChecked()); } + noTagsButton.setChecked(checkedTextView.isChecked()); + settings.setNoTagsToggle(noTagsButton.isChecked()); if(checkedTextView.isChecked()) { adapter.filterByTags(adapter.getTags()); @@ -626,6 +630,18 @@ public class MainActivity extends BaseActivity }); allTagsButton.setChecked(settings.getAllTagsToggle()); + noTagsButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + CheckedTextView checkedTextView = ((CheckedTextView)view); + checkedTextView.setChecked(!checkedTextView.isChecked()); + + settings.setNoTagsToggle(checkedTextView.isChecked()); + adapter.filterByTags(adapter.getTags()); + } + }); + noTagsButton.setChecked(settings.getNoTagsToggle()); + tagsDrawerListView.setAdapter(tagsDrawerAdapter); tagsDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java index db9f1783..709ca2f5 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Settings.java @@ -294,6 +294,14 @@ public class Settings { setBoolean(R.string.settings_key_all_tags_toggle, value); } + public boolean getNoTagsToggle() { + return getBoolean(R.string.settings_key_no_tags_toggle, true); + } + + public void setNoTagsToggle(Boolean value) { + setBoolean(R.string.settings_key_no_tags_toggle, value); + } + public boolean getTagToggle(String tag) { //The tag toggle holds tags that are unchecked in order to default to checked. Set toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet()); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java index d8b395f6..a4d3c3da 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/EntriesCardAdapter.java @@ -44,6 +44,7 @@ import android.widget.Toast; import org.shadowice.flocke.andotp.Database.Entry; import org.shadowice.flocke.andotp.Utilities.DatabaseHelper; +import org.shadowice.flocke.andotp.Utilities.Settings; import org.shadowice.flocke.andotp.Utilities.TagDialogHelper; import org.shadowice.flocke.andotp.View.ItemTouchHelper.ItemTouchHelperAdapter; import org.shadowice.flocke.andotp.R; @@ -70,11 +71,13 @@ public class EntriesCardAdapter extends RecyclerView.Adapter private SortMode sortMode = SortMode.UNSORTED; private TagsAdapter tagsFilterAdapter; + private Settings settings; public EntriesCardAdapter(Context context, TagsAdapter tagsFilterAdapter) { this.context = context; this.sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); this.tagsFilterAdapter = tagsFilterAdapter; + this.settings = new Settings(context); loadEntries(); } @@ -117,7 +120,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter for(Entry e : entries) { //Entries with no tags will always be shown - Boolean foundMatchingTag = e.getTags().isEmpty(); + Boolean foundMatchingTag = e.getTags().isEmpty() && settings.getNoTagsToggle(); for(String tag : tags) { if(e.getTags().contains(tag)) { diff --git a/app/src/main/res/layout/component_tags.xml b/app/src/main/res/layout/component_tags.xml index 458a8acc..e92844a1 100644 --- a/app/src/main/res/layout/component_tags.xml +++ b/app/src/main/res/layout/component_tags.xml @@ -20,6 +20,29 @@ android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:text="@string/button_all_tags"/> + + + + + + + + diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index fcb7f3c1..113ce137 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -27,6 +27,7 @@ pref_sort_mode pref_special_features pref_all_tags_toggle + pref_no_tags_toggle pref_tags_toggles diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index ae2a0044..4d27a5cc 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -9,6 +9,7 @@ New tag You have been warned! All tags + No tags %d s