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_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_KEY_NOT_FOUND = 2;
|
||||
@@ -121,7 +121,7 @@ public class PassphraseCacheService extends Service {
|
||||
public static void addCachedPassphrase(Context context, long masterKeyId, long subKeyId,
|
||||
Passphrase passphrase,
|
||||
String primaryUserId,
|
||||
long timeToLiveSeconds) {
|
||||
int timeToLiveSeconds) {
|
||||
Log.d(Constants.TAG, "PassphraseCacheService.addCachedPassphrase() for " + masterKeyId);
|
||||
|
||||
Intent intent = new Intent(context, PassphraseCacheService.class);
|
||||
@@ -237,8 +237,6 @@ public class PassphraseCacheService extends Service {
|
||||
if (cachedPassphrase == null) {
|
||||
return null;
|
||||
}
|
||||
addCachedPassphrase(this, Constants.key.symmetric, Constants.key.symmetric,
|
||||
cachedPassphrase.getPassphrase(), getString(R.string.passp_cache_notif_pwd), 180);
|
||||
return cachedPassphrase.getPassphrase();
|
||||
}
|
||||
|
||||
@@ -345,7 +343,7 @@ public class PassphraseCacheService extends Service {
|
||||
String action = intent.getAction();
|
||||
switch (action) {
|
||||
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 subKeyId = intent.getLongExtra(EXTRA_SUBKEY_ID, -1);
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
CryptoInputParcel cryptoInputParcel =
|
||||
((PassphraseDialogActivity) getActivity()).mCryptoInputParcel;
|
||||
|
||||
final long timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
|
||||
final int timeToLiveSeconds = mTimeToLiveSpinner.getSelectedTimeToLive();
|
||||
|
||||
// Early breakout if we are dealing with a symmetric key
|
||||
if (mSecretRing == null) {
|
||||
|
||||
@@ -19,61 +19,56 @@ package org.sufficientlysecure.keychain.ui.widget;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources.Theme;
|
||||
import android.database.Cursor;
|
||||
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.v7.widget.AppCompatSpinner;
|
||||
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.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.Preferences.CacheTTLPrefs;
|
||||
|
||||
|
||||
public class CacheTTLSpinner extends AppCompatSpinner {
|
||||
|
||||
public CacheTTLSpinner(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
initView();
|
||||
initView(context);
|
||||
}
|
||||
|
||||
public CacheTTLSpinner(Context context, AttributeSet attrs, int 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);
|
||||
cursor.addRow(new Object[] { 0, 60*5, getContext().getString(R.string.cache_ttl_five_minutes) });
|
||||
cursor.addRow(new Object[] { 1, 60*60, getContext().getString(R.string.cache_ttl_one_hour) });
|
||||
cursor.addRow(new Object[] { 2, 60*60*3, getContext().getString(R.string.cache_ttl_three_hours) });
|
||||
cursor.addRow(new Object[] { 3, 60*60*24, getContext().getString(R.string.cache_ttl_one_day) });
|
||||
cursor.addRow(new Object[] { 4, 60*60*24*3, getContext().getString(R.string.cache_ttl_three_days) });
|
||||
int i = 0, defaultPosition = 0;
|
||||
for (int ttl : CacheTTLPrefs.CACHE_TTLS) {
|
||||
if ( ! prefs.ttlTimes.contains(ttl)) {
|
||||
continue;
|
||||
}
|
||||
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,
|
||||
new String[] { "description" },
|
||||
new int[] { R.id.simple_item_text },
|
||||
0));
|
||||
|
||||
setSelection(defaultPosition);
|
||||
}
|
||||
|
||||
public long getSelectedTimeToLive() {
|
||||
public int getSelectedTimeToLive() {
|
||||
int selectedItemPosition = getSelectedItemPosition();
|
||||
Object item = getAdapter().getItem(selectedItemPosition);
|
||||
return ((Cursor) item).getLong(1);
|
||||
return ((Cursor) item).getInt(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user