inline-ttl: save changes in ttl settings
This commit is contained in:
@@ -19,10 +19,10 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -37,6 +37,7 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
import org.sufficientlysecure.keychain.ui.util.recyclerview.DividerItemDecoration;
|
import org.sufficientlysecure.keychain.ui.util.recyclerview.DividerItemDecoration;
|
||||||
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences.CacheTTLPrefs;
|
import org.sufficientlysecure.keychain.util.Preferences.CacheTTLPrefs;
|
||||||
|
|
||||||
|
|
||||||
@@ -80,8 +81,13 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveKeyserverList() {
|
private void savePreference() {
|
||||||
// Preferences.getPreferences(getActivity()).setKeyServers(servers);
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CacheTTLPrefs prefs = mAdapter.getPrefs();
|
||||||
|
Preferences.getPreferences(activity).setPassphraseCacheTtl(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CacheTTLListAdapter extends RecyclerView.Adapter<CacheTTLListAdapter.ViewHolder> {
|
public class CacheTTLListAdapter extends RecyclerView.Adapter<CacheTTLListAdapter.ViewHolder> {
|
||||||
@@ -100,6 +106,20 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CacheTTLPrefs getPrefs() {
|
||||||
|
ArrayList<String> ttls = new ArrayList<>();
|
||||||
|
int defaultTtl = 0;
|
||||||
|
for (int i = 0; i < mPositionIsChecked.size(); i++) {
|
||||||
|
if (mPositionIsChecked.get(i)) {
|
||||||
|
ttls.add(Integer.toString(CacheTTLPrefs.CACHE_TTLS.get(i)));
|
||||||
|
if (i == mDefaultPosition) {
|
||||||
|
defaultTtl = CacheTTLPrefs.CACHE_TTLS.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new CacheTTLPrefs(ttls, defaultTtl);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
@@ -144,21 +164,28 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
boolean isDefault = position == mDefaultPosition;
|
boolean isDefault = position == mDefaultPosition;
|
||||||
|
|
||||||
mTitle.setText(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl));
|
mTitle.setText(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl));
|
||||||
mChecked.setChecked(isChecked);
|
// avoid some ui flicker by skipping unnecessary updates
|
||||||
|
if (mChecked.isChecked() != isChecked) {
|
||||||
|
mChecked.setChecked(isChecked);
|
||||||
|
}
|
||||||
|
if (mIsDefault.isChecked() != isDefault) {
|
||||||
|
mIsDefault.setChecked(isDefault);
|
||||||
|
}
|
||||||
mIsDefault.setEnabled(isChecked);
|
mIsDefault.setEnabled(isChecked);
|
||||||
mIsDefault.setChecked(isDefault);
|
|
||||||
|
|
||||||
mChecked.setOnClickListener(new OnClickListener() {
|
mChecked.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
setTtlChecked(position);
|
setTtlChecked(position);
|
||||||
|
savePreference();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mIsDefault.setOnClickListener(!isChecked ? null : new OnClickListener() {
|
mIsDefault.setOnClickListener(!isChecked ? null : new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
setDefault(position);
|
setTtlDefault(position);
|
||||||
|
savePreference();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -191,7 +218,7 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
int i = mDefaultPosition;
|
int i = mDefaultPosition;
|
||||||
while (--i >= 0) {
|
while (--i >= 0) {
|
||||||
if (mPositionIsChecked.get(i)) {
|
if (mPositionIsChecked.get(i)) {
|
||||||
setDefault(i);
|
setTtlDefault(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -200,7 +227,7 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
i = mDefaultPosition;
|
i = mDefaultPosition;
|
||||||
while (++i < mPositionIsChecked.size()) {
|
while (++i < mPositionIsChecked.size()) {
|
||||||
if (mPositionIsChecked.get(i)) {
|
if (mPositionIsChecked.get(i)) {
|
||||||
setDefault(i);
|
setTtlDefault(i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -210,7 +237,7 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefault(int position) {
|
private void setTtlDefault(int position) {
|
||||||
int previousDefaultPosition = mDefaultPosition;
|
int previousDefaultPosition = mDefaultPosition;
|
||||||
mDefaultPosition = position;
|
mDefaultPosition = position;
|
||||||
notifyItemChanged(previousDefaultPosition);
|
notifyItemChanged(previousDefaultPosition);
|
||||||
|
|||||||
@@ -98,21 +98,6 @@ public class Preferences {
|
|||||||
editor.commit();
|
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() {
|
public boolean getPassphraseCacheSubs() {
|
||||||
return mSharedPreferences.getBoolean(Pref.PASSPHRASE_CACHE_SUBS, false);
|
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 class CacheTTLPrefs implements Serializable {
|
||||||
public static final Map<Integer,Integer> CACHE_TTL_NAMES;
|
public static final Map<Integer,Integer> CACHE_TTL_NAMES;
|
||||||
public static final ArrayList<Integer> CACHE_TTLS;
|
public static final ArrayList<Integer> CACHE_TTLS;
|
||||||
@@ -331,7 +332,6 @@ public class Preferences {
|
|||||||
Collections.sort(CACHE_TTLS);
|
Collections.sort(CACHE_TTLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public HashSet<Integer> ttlTimes;
|
public HashSet<Integer> ttlTimes;
|
||||||
public int defaultTtl;
|
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() {
|
public static CacheTTLPrefs getDefault() {
|
||||||
ArrayList<String> ttlStrings = new ArrayList<>();
|
ArrayList<String> ttlStrings = new ArrayList<>();
|
||||||
ttlStrings.add(Integer.toString(60 * 5));
|
ttlStrings.add(Integer.toString(60 * 5));
|
||||||
|
|||||||
Reference in New Issue
Block a user