inline-ttl: use ttl preference in ttl spinner
This commit is contained in:
@@ -93,7 +93,7 @@ public class PassphraseCacheService extends Service {
|
|||||||
public static final String EXTRA_MESSENGER = "messenger";
|
public static final String EXTRA_MESSENGER = "messenger";
|
||||||
public static final String EXTRA_USER_ID = "user_id";
|
public static final String EXTRA_USER_ID = "user_id";
|
||||||
|
|
||||||
private static final long DEFAULT_TTL = 15;
|
private static final int DEFAULT_TTL = 15;
|
||||||
|
|
||||||
private static final int MSG_PASSPHRASE_CACHE_GET_OKAY = 1;
|
private static final int MSG_PASSPHRASE_CACHE_GET_OKAY = 1;
|
||||||
private static final int MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND = 2;
|
private static final int MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND = 2;
|
||||||
@@ -121,7 +121,7 @@ public class PassphraseCacheService extends Service {
|
|||||||
public static void addCachedPassphrase(Context context, long masterKeyId, long subKeyId,
|
public static void addCachedPassphrase(Context context, long masterKeyId, long subKeyId,
|
||||||
Passphrase passphrase,
|
Passphrase passphrase,
|
||||||
String primaryUserId,
|
String primaryUserId,
|
||||||
long timeToLiveSeconds) {
|
int timeToLiveSeconds) {
|
||||||
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
|
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
|
||||||
|
|
||||||
Intent intent = new Intent(context, PassphraseCacheService.class);
|
Intent intent = new Intent(context, PassphraseCacheService.class);
|
||||||
@@ -237,8 +237,6 @@ public class PassphraseCacheService extends Service {
|
|||||||
if (cachedPassphrase == null) {
|
if (cachedPassphrase == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
addCachedPassphrase(this, Constants.key.symmetric, Constants.key.symmetric,
|
|
||||||
cachedPassphrase.getPassphrase(), getString(R.string.passp_cache_notif_pwd), 180);
|
|
||||||
return cachedPassphrase.getPassphrase();
|
return cachedPassphrase.getPassphrase();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,7 +343,7 @@ public class PassphraseCacheService extends Service {
|
|||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case ACTION_PASSPHRASE_CACHE_ADD: {
|
case ACTION_PASSPHRASE_CACHE_ADD: {
|
||||||
long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL);
|
long ttl = intent.getIntExtra(EXTRA_TTL, DEFAULT_TTL);
|
||||||
long masterKeyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
|
long masterKeyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
|
||||||
long subKeyId = intent.getLongExtra(EXTRA_SUBKEY_ID, -1);
|
long subKeyId = intent.getLongExtra(EXTRA_SUBKEY_ID, -1);
|
||||||
|
|
||||||
|
|||||||
@@ -419,7 +419,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
|||||||
CryptoInputParcel cryptoInputParcel =
|
CryptoInputParcel cryptoInputParcel =
|
||||||
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
|
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
|
||||||
|
|
||||||
final long timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
|
final int timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
|
||||||
|
|
||||||
// Early breakout if we are dealing with a symmetric key
|
// Early breakout if we are dealing with a symmetric key
|
||||||
if (mSecretRing == null) {
|
if (mSecretRing == null) {
|
||||||
|
|||||||
@@ -19,61 +19,56 @@ package org.sufficientlysecure.keychain.ui.widget;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources.Theme;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.MatrixCursor;
|
import android.database.MatrixCursor;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Parcelable;
|
|
||||||
import android.support.annotation.NonNull;
|
|
||||||
import android.support.annotation.StringRes;
|
|
||||||
import android.support.v4.widget.SimpleCursorAdapter;
|
import android.support.v4.widget.SimpleCursorAdapter;
|
||||||
import android.support.v7.widget.AppCompatSpinner;
|
import android.support.v7.widget.AppCompatSpinner;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.BaseAdapter;
|
|
||||||
import android.widget.SpinnerAdapter;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
import org.sufficientlysecure.keychain.util.Preferences.CacheTTLPrefs;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem;
|
|
||||||
|
|
||||||
|
|
||||||
public class CacheTTLSpinner extends AppCompatSpinner {
|
public class CacheTTLSpinner extends AppCompatSpinner {
|
||||||
|
|
||||||
public CacheTTLSpinner(Context context, AttributeSet attrs) {
|
public CacheTTLSpinner(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
initView();
|
initView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheTTLSpinner(Context context, AttributeSet attrs, int defStyle) {
|
public CacheTTLSpinner(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
initView();
|
initView(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initView() {
|
private void initView(Context context) {
|
||||||
|
|
||||||
|
CacheTTLPrefs prefs = Preferences.getPreferences(context).getPassphraseCacheTtl();
|
||||||
MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "TTL", "description" }, 5);
|
MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "TTL", "description" }, 5);
|
||||||
cursor.addRow(new Object[] { 0, 60*5, getContext().getString(R.string.cache_ttl_five_minutes) });
|
int i = 0, defaultPosition = 0;
|
||||||
cursor.addRow(new Object[] { 1, 60*60, getContext().getString(R.string.cache_ttl_one_hour) });
|
for (int ttl : CacheTTLPrefs.CACHE_TTLS) {
|
||||||
cursor.addRow(new Object[] { 2, 60*60*3, getContext().getString(R.string.cache_ttl_three_hours) });
|
if ( ! prefs.ttlTimes.contains(ttl)) {
|
||||||
cursor.addRow(new Object[] { 3, 60*60*24, getContext().getString(R.string.cache_ttl_one_day) });
|
continue;
|
||||||
cursor.addRow(new Object[] { 4, 60*60*24*3, getContext().getString(R.string.cache_ttl_three_days) });
|
}
|
||||||
|
if (ttl == prefs.defaultTtl) {
|
||||||
|
defaultPosition = i;
|
||||||
|
}
|
||||||
|
cursor.addRow(new Object[] { i++, ttl, getContext().getString(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl)) });
|
||||||
|
}
|
||||||
|
|
||||||
setAdapter(new SimpleCursorAdapter(getContext(), R.layout.simple_item, cursor,
|
setAdapter(new SimpleCursorAdapter(getContext(), R.layout.simple_item, cursor,
|
||||||
new String[] { "description" },
|
new String[] { "description" },
|
||||||
new int[] { R.id.simple_item_text },
|
new int[] { R.id.simple_item_text },
|
||||||
0));
|
0));
|
||||||
|
|
||||||
|
setSelection(defaultPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSelectedTimeToLive() {
|
public int getSelectedTimeToLive() {
|
||||||
int selectedItemPosition = getSelectedItemPosition();
|
int selectedItemPosition = getSelectedItemPosition();
|
||||||
Object item = getAdapter().getItem(selectedItemPosition);
|
Object item = getAdapter().getItem(selectedItemPosition);
|
||||||
return ((Cursor) item).getLong(1);
|
return ((Cursor) item).getInt(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user