inline-ttl: save changes in ttl settings

This commit is contained in:
Vincent Breitmoser
2015-11-17 14:33:08 +01:00
parent 1754a88ac3
commit 0c7c58f376
2 changed files with 60 additions and 25 deletions

View File

@@ -98,21 +98,6 @@ public class Preferences {
editor.commit();
}
public CacheTTLPrefs getPassphraseCacheTtl() {
Set<String> pref = mSharedPreferences.getStringSet(Constants.Pref.PASSPHRASE_CACHE_TTLS, null);
if (pref == null) {
return CacheTTLPrefs.getDefault();
}
int def = mSharedPreferences.getInt(Pref.PASSPHRASE_CACHE_DEFAULT, 0);
return new CacheTTLPrefs(pref, def);
}
public void setPassphraseCacheTtl(int value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(Constants.Pref.PASSPHRASE_CACHE_TTLS, value);
editor.commit();
}
public boolean getPassphraseCacheSubs() {
return mSharedPreferences.getBoolean(Pref.PASSPHRASE_CACHE_SUBS, false);
}
@@ -315,6 +300,22 @@ public class Preferences {
}
public CacheTTLPrefs getPassphraseCacheTtl() {
Set<String> pref = mSharedPreferences.getStringSet(Constants.Pref.PASSPHRASE_CACHE_TTLS, null);
if (pref == null) {
return CacheTTLPrefs.getDefault();
}
int def = mSharedPreferences.getInt(Pref.PASSPHRASE_CACHE_DEFAULT, 300);
return new CacheTTLPrefs(pref, def);
}
public void setPassphraseCacheTtl(CacheTTLPrefs prefs) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putStringSet(Constants.Pref.PASSPHRASE_CACHE_TTLS, prefs.getStringSet());
editor.putInt(Pref.PASSPHRASE_CACHE_DEFAULT, prefs.defaultTtl);
editor.commit();
}
public static class CacheTTLPrefs implements Serializable {
public static final Map<Integer,Integer> CACHE_TTL_NAMES;
public static final ArrayList<Integer> CACHE_TTLS;
@@ -331,7 +332,6 @@ public class Preferences {
Collections.sort(CACHE_TTLS);
}
public HashSet<Integer> ttlTimes;
public int defaultTtl;
@@ -343,6 +343,14 @@ public class Preferences {
}
}
public HashSet<String> getStringSet() {
HashSet<String> ttlTimeStrings = new HashSet<>();
for (Integer ttlTime : ttlTimes) {
ttlTimeStrings.add(Integer.toString(ttlTime));
}
return ttlTimeStrings;
}
public static CacheTTLPrefs getDefault() {
ArrayList<String> ttlStrings = new ArrayList<>();
ttlStrings.add(Integer.toString(60 * 5));