From 43907a172ed90788564eeb041c7db4a241ef1482 Mon Sep 17 00:00:00 2001 From: RichyHBM Date: Mon, 13 Nov 2017 19:21:55 +0000 Subject: [PATCH] Save tag toggle as string set --- .../flocke/andotp/Utilities/Settings.java | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) 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 f218c13e..db9f1783 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 @@ -36,6 +36,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.security.KeyPair; import java.util.Collections; +import java.util.HashSet; import java.util.Set; import static org.shadowice.flocke.andotp.Preferences.PasswordEncryptedPreference.KEY_ALIAS; @@ -124,6 +125,10 @@ public class Settings { return settings.getLong(getResString(keyId), defaultValue); } + private Set getStringSet(int keyId, Set defaultValue) { + return settings.getStringSet(getResString(keyId), defaultValue); + } + private void setBoolean(int keyId, boolean value) { settings.edit() .putBoolean(getResString(keyId), value) @@ -136,6 +141,12 @@ public class Settings { .apply(); } + private void setStringSet(int keyId, Set value) { + settings.edit() + .putStringSet(getResString(keyId), value) + .apply(); + } + private void remove(int keyId) { settings.edit() .remove(getResString(keyId)) @@ -284,14 +295,17 @@ public class Settings { } public boolean getTagToggle(String tag) { - String settingsKey = getResString(R.string.settings_key_tags_toggles) + "_" + tag; - return settings.getBoolean(settingsKey, true); + //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()); + return !toggledTags.contains(tag); } public void setTagToggle(String tag, Boolean value) { - String settingsKey = getResString(R.string.settings_key_tags_toggles) + "_" + tag; - settings.edit() - .putBoolean(settingsKey, value) - .apply(); + Set toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet()); + if(value) + toggledTags.remove(tag); + else + toggledTags.add(tag); + setStringSet(R.string.settings_key_tags_toggles, toggledTags); } }