remember last selected passphrase cache ttl

This commit is contained in:
Vincent Breitmoser 2017-09-20 17:01:49 +02:00
parent d04439df6b
commit 03ca1292fa
4 changed files with 25 additions and 0 deletions

View file

@ -115,6 +115,7 @@ public final class Constants {
public static final class Pref {
public static final String PASSPHRASE_CACHE_SUBS = "passphraseCacheSubs";
public static final String PASSPHRASE_CACHE_LAST_TTL = "passphraseCacheLastTtl";
public static final String LANGUAGE = "language";
public static final String KEY_SERVERS = "keyServers";
public static final String PREF_VERSION = "keyServersDefaultVersion";

View file

@ -210,6 +210,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
vTimeToLiveLayout.setVisibility(mRequiredInput.mSkipCaching ? View.GONE : View.VISIBLE);
mTimeToLiveSpinner = (CacheTTLSpinner) mLayout.findViewById(R.id.ttl_spinner);
int ttlSeconds = Preferences.getPreferences(getContext()).getCacheTtlSeconds();
mTimeToLiveSpinner.setSelectedTimeToLive(ttlSeconds);
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@ -426,6 +428,8 @@ public class PassphraseDialogActivity extends FragmentActivity {
final Passphrase passphrase = new Passphrase(mPassphraseEditText);
final int timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
Preferences.getPreferences(getContext()).setCacheTtlSeconds(timeToLiveSeconds);
// Early breakout if we are dealing with a symmetric key
if (mRequiredInput.mType == RequiredInputType.PASSPHRASE_SYMMETRIC) {
if (!mRequiredInput.mSkipCaching) {

View file

@ -67,4 +67,14 @@ public class CacheTTLSpinner extends AppCompatSpinner {
Object item = getAdapter().getItem(selectedItemPosition);
return ((Cursor) item).getInt(1);
}
public void setSelectedTimeToLive(int ttlSeconds) {
for (int i = 0; i < TTL_TIMES.length; i++) {
boolean isSelectedOrLast = ttlSeconds <= TTL_TIMES[i] || (i == TTL_TIMES.length - 1);
if (isSelectedOrLast) {
setSelection(i);
break;
}
}
}
}

View file

@ -96,6 +96,16 @@ public class Preferences {
return mSharedPreferences.getBoolean(Pref.PASSPHRASE_CACHE_SUBS, false);
}
public int getCacheTtlSeconds() {
return mSharedPreferences.getInt(Pref.PASSPHRASE_CACHE_LAST_TTL, 0);
}
public void setCacheTtlSeconds(int ttlSeconds) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(Pref.PASSPHRASE_CACHE_LAST_TTL, ttlSeconds);
editor.commit();
}
public boolean getCachedConsolidate() {
return mSharedPreferences.getBoolean(Pref.CACHED_CONSOLIDATE, false);
}