Add no tags toggle

This commit is contained in:
RichyHBM 2017-11-13 20:25:53 +00:00
parent 43907a172e
commit 84c0674e1e
6 changed files with 54 additions and 2 deletions

View file

@ -603,7 +603,9 @@ public class MainActivity extends BaseActivity
tagsToggle.setDrawerIndicatorEnabled(true); tagsToggle.setDrawerIndicatorEnabled(true);
tagsDrawerLayout.addDrawerListener(tagsToggle); tagsDrawerLayout.addDrawerListener(tagsToggle);
final CheckedTextView noTagsButton = (CheckedTextView)findViewById(R.id.no_tags_entries);
CheckedTextView allTagsButton = (CheckedTextView)findViewById(R.id.all_tags_in_drawer); CheckedTextView allTagsButton = (CheckedTextView)findViewById(R.id.all_tags_in_drawer);
allTagsButton.setOnClickListener(new View.OnClickListener() { allTagsButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -616,6 +618,8 @@ public class MainActivity extends BaseActivity
CheckedTextView childCheckBox = (CheckedTextView)tagsDrawerListView.getChildAt(i); CheckedTextView childCheckBox = (CheckedTextView)tagsDrawerListView.getChildAt(i);
childCheckBox.setChecked(checkedTextView.isChecked()); childCheckBox.setChecked(checkedTextView.isChecked());
} }
noTagsButton.setChecked(checkedTextView.isChecked());
settings.setNoTagsToggle(noTagsButton.isChecked());
if(checkedTextView.isChecked()) { if(checkedTextView.isChecked()) {
adapter.filterByTags(adapter.getTags()); adapter.filterByTags(adapter.getTags());
@ -626,6 +630,18 @@ public class MainActivity extends BaseActivity
}); });
allTagsButton.setChecked(settings.getAllTagsToggle()); 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.setAdapter(tagsDrawerAdapter);
tagsDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { tagsDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

View file

@ -294,6 +294,14 @@ public class Settings {
setBoolean(R.string.settings_key_all_tags_toggle, value); 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) { public boolean getTagToggle(String tag) {
//The tag toggle holds tags that are unchecked in order to default to checked. //The tag toggle holds tags that are unchecked in order to default to checked.
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<String>()); Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<String>());

View file

@ -44,6 +44,7 @@ import android.widget.Toast;
import org.shadowice.flocke.andotp.Database.Entry; import org.shadowice.flocke.andotp.Database.Entry;
import org.shadowice.flocke.andotp.Utilities.DatabaseHelper; 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.Utilities.TagDialogHelper;
import org.shadowice.flocke.andotp.View.ItemTouchHelper.ItemTouchHelperAdapter; import org.shadowice.flocke.andotp.View.ItemTouchHelper.ItemTouchHelperAdapter;
import org.shadowice.flocke.andotp.R; import org.shadowice.flocke.andotp.R;
@ -70,11 +71,13 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
private SortMode sortMode = SortMode.UNSORTED; private SortMode sortMode = SortMode.UNSORTED;
private TagsAdapter tagsFilterAdapter; private TagsAdapter tagsFilterAdapter;
private Settings settings;
public EntriesCardAdapter(Context context, TagsAdapter tagsFilterAdapter) { public EntriesCardAdapter(Context context, TagsAdapter tagsFilterAdapter) {
this.context = context; this.context = context;
this.sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); this.sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
this.tagsFilterAdapter = tagsFilterAdapter; this.tagsFilterAdapter = tagsFilterAdapter;
this.settings = new Settings(context);
loadEntries(); loadEntries();
} }
@ -117,7 +120,7 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
for(Entry e : entries) { for(Entry e : entries) {
//Entries with no tags will always be shown //Entries with no tags will always be shown
Boolean foundMatchingTag = e.getTags().isEmpty(); Boolean foundMatchingTag = e.getTags().isEmpty() && settings.getNoTagsToggle();
for(String tag : tags) { for(String tag : tags) {
if(e.getTags().contains(tag)) { if(e.getTags().contains(tag)) {

View file

@ -20,6 +20,29 @@
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="@string/button_all_tags"/> android:text="@string/button_all_tags"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center_horizontal">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider" />
</LinearLayout>
<CheckedTextView
android:id="@+id/no_tags_entries"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:text="@string/button_no_tags"/>
<LinearLayout <LinearLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,7 +58,7 @@
<ListView <ListView
android:id="@+id/tags_list_in_drawer" android:id="@+id/tags_list_in_drawer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:dividerHeight="0dp" android:dividerHeight="1dp"
android:headerDividersEnabled="false" android:headerDividersEnabled="false"
android:footerDividersEnabled="true" android:footerDividersEnabled="true"
android:layout_height="match_parent" /> android:layout_height="match_parent" />

View file

@ -27,6 +27,7 @@
<string name="settings_key_sort_mode" translatable="false">pref_sort_mode</string> <string name="settings_key_sort_mode" translatable="false">pref_sort_mode</string>
<string name="settings_key_special_features" translatable="false">pref_special_features</string> <string name="settings_key_special_features" translatable="false">pref_special_features</string>
<string name="settings_key_all_tags_toggle" translatable="false">pref_all_tags_toggle</string> <string name="settings_key_all_tags_toggle" translatable="false">pref_all_tags_toggle</string>
<string name="settings_key_no_tags_toggle" translatable="false">pref_no_tags_toggle</string>
<string name="settings_key_tags_toggles" translatable="false">pref_tags_toggles</string> <string name="settings_key_tags_toggles" translatable="false">pref_tags_toggles</string>
<!-- Default values --> <!-- Default values -->

View file

@ -9,6 +9,7 @@
<string name="button_new_tag">New tag</string> <string name="button_new_tag">New tag</string>
<string name="button_warned">You have been warned!</string> <string name="button_warned">You have been warned!</string>
<string name="button_all_tags">All tags</string> <string name="button_all_tags">All tags</string>
<string name="button_no_tags">No tags</string>
<!-- Custom formatting --> <!-- Custom formatting -->
<string name="format_custom_period">%d s</string> <string name="format_custom_period">%d s</string>