Save tag toggle as string set
This commit is contained in:
parent
ecfa3f0696
commit
43907a172e
1 changed files with 20 additions and 6 deletions
|
@ -36,6 +36,7 @@ import java.io.File;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.shadowice.flocke.andotp.Preferences.PasswordEncryptedPreference.KEY_ALIAS;
|
import static org.shadowice.flocke.andotp.Preferences.PasswordEncryptedPreference.KEY_ALIAS;
|
||||||
|
@ -124,6 +125,10 @@ public class Settings {
|
||||||
return settings.getLong(getResString(keyId), defaultValue);
|
return settings.getLong(getResString(keyId), defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> getStringSet(int keyId, Set<String> defaultValue) {
|
||||||
|
return settings.getStringSet(getResString(keyId), defaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
private void setBoolean(int keyId, boolean value) {
|
private void setBoolean(int keyId, boolean value) {
|
||||||
settings.edit()
|
settings.edit()
|
||||||
.putBoolean(getResString(keyId), value)
|
.putBoolean(getResString(keyId), value)
|
||||||
|
@ -136,6 +141,12 @@ public class Settings {
|
||||||
.apply();
|
.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setStringSet(int keyId, Set<String> value) {
|
||||||
|
settings.edit()
|
||||||
|
.putStringSet(getResString(keyId), value)
|
||||||
|
.apply();
|
||||||
|
}
|
||||||
|
|
||||||
private void remove(int keyId) {
|
private void remove(int keyId) {
|
||||||
settings.edit()
|
settings.edit()
|
||||||
.remove(getResString(keyId))
|
.remove(getResString(keyId))
|
||||||
|
@ -284,14 +295,17 @@ public class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getTagToggle(String tag) {
|
public boolean getTagToggle(String tag) {
|
||||||
String settingsKey = getResString(R.string.settings_key_tags_toggles) + "_" + tag;
|
//The tag toggle holds tags that are unchecked in order to default to checked.
|
||||||
return settings.getBoolean(settingsKey, true);
|
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<String>());
|
||||||
|
return !toggledTags.contains(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTagToggle(String tag, Boolean value) {
|
public void setTagToggle(String tag, Boolean value) {
|
||||||
String settingsKey = getResString(R.string.settings_key_tags_toggles) + "_" + tag;
|
Set<String> toggledTags = getStringSet(R.string.settings_key_tags_toggles, new HashSet<String>());
|
||||||
settings.edit()
|
if(value)
|
||||||
.putBoolean(settingsKey, value)
|
toggledTags.remove(tag);
|
||||||
.apply();
|
else
|
||||||
|
toggledTags.add(tag);
|
||||||
|
setStringSet(R.string.settings_key_tags_toggles, toggledTags);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue