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 09d49a3a..4549f81e 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 @@ -346,7 +346,8 @@ public class MainActivity extends BaseActivity } else if (key.equals(getString(R.string.settings_key_tap_to_reveal)) || key.equals(getString(R.string.settings_key_theme)) || key.equals(getString(R.string.settings_key_locale)) || - key.equals(getString(R.string.settings_key_enable_screenshot))) { + key.equals(getString(R.string.settings_key_enable_screenshot)) || + key.equals(getString(R.string.settings_key_tag_functionality)) ) { recreate(); } } @@ -619,6 +620,17 @@ public class MainActivity extends BaseActivity CheckedTextView checkedTextView = ((CheckedTextView)view); checkedTextView.setChecked(!checkedTextView.isChecked()); + if(settings.getTagFunctionality() == Constants.TagFunctionality.SINGLE) { + checkedTextView.setChecked(true); + allTagsButton.setChecked(false); + settings.setAllTagsToggle(false); + + for (String tag: tagsDrawerAdapter.getTags()) { + settings.setTagToggle(tag, false); + tagsDrawerAdapter.setTagState(tag, false); + } + } + settings.setNoTagsToggle(checkedTextView.isChecked()); adapter.filterByTags(tagsDrawerAdapter.getActiveTags()); } @@ -630,7 +642,21 @@ public class MainActivity extends BaseActivity @Override public void onItemClick(AdapterView parent, View view, int position, long id) { CheckedTextView checkedTextView = ((CheckedTextView)view); - checkedTextView.setChecked(!checkedTextView.isChecked()); + + if(settings.getTagFunctionality() == Constants.TagFunctionality.SINGLE) { + allTagsButton.setChecked(false); + settings.setAllTagsToggle(false); + noTagsButton.setChecked(false); + settings.setNoTagsToggle(false); + + for (String tag: tagsDrawerAdapter.getTags()) { + settings.setTagToggle(tag, false); + tagsDrawerAdapter.setTagState(tag, false); + } + checkedTextView.setChecked(true); + }else { + checkedTextView.setChecked(!checkedTextView.isChecked()); + } settings.setTagToggle(checkedTextView.getText().toString(), checkedTextView.isChecked()); tagsDrawerAdapter.setTagState(checkedTextView.getText().toString(), checkedTextView.isChecked()); diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java index 2e459f1b..3d114f38 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Utilities/Constants.java @@ -44,6 +44,10 @@ public class Constants { PLAIN_TEXT, ENCRYPTED, OPEN_PGP } + public enum TagFunctionality { + OR, AND, SINGLE + } + // Intents (Format: A0x with A = parent Activity, x = number of the intent) public final static int INTENT_MAIN_AUTHENTICATE = 100; public final static int INTENT_MAIN_SETTINGS = 101; 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 c7f69f43..9c33bf46 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 @@ -451,6 +451,12 @@ public class Settings { ); } + public Constants.TagFunctionality getTagFunctionality() { + String tagFunctionality = getString(R.string.settings_key_tag_functionality, R.string.settings_default_tag_functionality); + return Constants.TagFunctionality.valueOf(tagFunctionality.toUpperCase()); + } + + public boolean getScreenshotsEnabled() { return getBoolean(R.string.settings_key_enable_screenshot, false); } 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 8a530cb4..1ac6c244 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 @@ -48,6 +48,7 @@ import android.widget.Toast; import org.shadowice.flocke.andotp.Database.Entry; import org.shadowice.flocke.andotp.R; +import org.shadowice.flocke.andotp.Utilities.Constants; import org.shadowice.flocke.andotp.Utilities.DatabaseHelper; import org.shadowice.flocke.andotp.Utilities.EntryThumbnail; import org.shadowice.flocke.andotp.Utilities.Settings; @@ -145,10 +146,16 @@ public class EntriesCardAdapter extends RecyclerView.Adapter //Entries with no tags will always be shown Boolean foundMatchingTag = e.getTags().isEmpty() && settings.getNoTagsToggle(); - for(String tag : tags) { - if(e.getTags().contains(tag)) { + if(settings.getTagFunctionality() == Constants.TagFunctionality.AND) { + if(e.getTags().containsAll(tags)) { foundMatchingTag = true; } + } else { + for (String tag : tags) { + if (e.getTags().contains(tag)) { + foundMatchingTag = true; + } + } } if(foundMatchingTag) { diff --git a/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java b/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java index 0ba79038..1df7db73 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/View/TagsAdapter.java @@ -79,6 +79,7 @@ public class TagsAdapter extends ArrayAdapter { public void setTagState(String tag, Boolean state) { if(tagsState.containsKey(tag)) tagsState.put(tag, state); + notifyDataSetChanged(); } public List getActiveTags() { diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index 1a4af210..0f153347 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -23,6 +23,7 @@ pref_label_scroll pref_thumbnail_size pref_split_group_size + pref_tag_functionality pref_backup_append_date_time pref_backup_ask @@ -54,6 +55,8 @@ 18 46dp 3 + or + @@ -113,6 +116,12 @@ 3 + + or + and + single + + @string/settings_lang_sys_default CatalĂ  diff --git a/app/src/main/res/values/strings_settings.xml b/app/src/main/res/values/strings_settings.xml index f5a8f77b..75f8cb12 100644 --- a/app/src/main/res/values/strings_settings.xml +++ b/app/src/main/res/values/strings_settings.xml @@ -22,6 +22,7 @@ Scroll label Thumbnail size Split Token with space + Tag menu functionality Append date to filename Ask for filename @@ -147,6 +148,12 @@ After three characters + + Or (Default) + And + Single + + System default diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e59feb08..3878ae6b 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -91,6 +91,14 @@ android:entryValues="@array/settings_values_split_group_size" android:defaultValue="@string/settings_default_split_group_size" /> + +