Merge pull request #134 from andOTP/tags-options

Add setting to select different tags behaviour
This commit is contained in:
Jakob Nixdorf 2018-02-21 10:25:29 +01:00 committed by GitHub
commit 4ec136cf37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 72 additions and 4 deletions

View file

@ -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());

View file

@ -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;

View file

@ -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);
}

View file

@ -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<EntryViewHolder>
//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) {

View file

@ -79,6 +79,7 @@ public class TagsAdapter extends ArrayAdapter<String> {
public void setTagState(String tag, Boolean state) {
if(tagsState.containsKey(tag))
tagsState.put(tag, state);
notifyDataSetChanged();
}
public List<String> getActiveTags() {

View file

@ -23,6 +23,7 @@
<string name="settings_key_label_scroll" translatable="false">pref_label_scroll</string>
<string name="settings_key_thumbnail_size" translatable="false">pref_thumbnail_size</string>
<string name="settings_key_split_group_size" translatable="false">pref_split_group_size</string>
<string name="settings_key_tag_functionality" translatable="false">pref_tag_functionality</string>
<string name="settings_key_backup_append_date_time" translatable="false">pref_backup_append_date_time</string>
<string name="settings_key_backup_ask" translatable="false">pref_backup_ask</string>
@ -54,6 +55,8 @@
<integer name="settings_default_label_size">18</integer>
<string name="settings_default_thumbnail_size">46dp</string>
<string name="settings_default_split_group_size">3</string>
<string name="settings_default_tag_functionality">or</string>
<!-- All of the possible tile background colors -->
<array name="letter_tile_colors">
@ -113,6 +116,12 @@
<item>3</item>
</string-array>
<string-array name="settings_values_tag_functionality" translatable="false">
<item>or</item>
<item>and</item>
<item>single</item>
</string-array>
<string-array name="settings_entries_lang" translatable="false">
<item>@string/settings_lang_sys_default</item>
<item>Català</item>

View file

@ -22,6 +22,7 @@
<string name="settings_title_label_scroll">Scroll label</string>
<string name="settings_title_thumbnail_size_ask">Thumbnail size</string>
<string name="settings_title_split_group_size">Split Token with space</string>
<string name="settings_title_tag_functionality">Tag menu functionality</string>
<string name="settings_title_backup_append_date">Append date to filename</string>
<string name="settings_title_backup_ask">Ask for filename</string>
@ -147,6 +148,12 @@
<item>After three characters</item>
</string-array>
<string-array name="settings_entries_tag_functionality">
<item>Or (Default)</item>
<item>And</item>
<item>Single</item>
</string-array>
<!-- Special -->
<string name="settings_lang_sys_default">System default</string>

View file

@ -91,6 +91,14 @@
android:entryValues="@array/settings_values_split_group_size"
android:defaultValue="@string/settings_default_split_group_size" />
<ListPreference
android:key="@string/settings_key_tag_functionality"
android:title="@string/settings_title_tag_functionality"
android:summary="%s"
android:entries="@array/settings_entries_tag_functionality"
android:entryValues="@array/settings_values_tag_functionality"
android:defaultValue="@string/settings_default_tag_functionality" />
</PreferenceCategory>
<PreferenceCategory