inline-ttl: remove "default" setting
This commit is contained in:
@@ -30,7 +30,6 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@@ -93,31 +92,23 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
public class CacheTTLListAdapter extends RecyclerView.Adapter<CacheTTLListAdapter.ViewHolder> {
|
public class CacheTTLListAdapter extends RecyclerView.Adapter<CacheTTLListAdapter.ViewHolder> {
|
||||||
|
|
||||||
private final ArrayList<Boolean> mPositionIsChecked;
|
private final ArrayList<Boolean> mPositionIsChecked;
|
||||||
private int mDefaultPosition;
|
|
||||||
|
|
||||||
public CacheTTLListAdapter(CacheTTLPrefs prefs) {
|
public CacheTTLListAdapter(CacheTTLPrefs prefs) {
|
||||||
this.mPositionIsChecked = new ArrayList<>();
|
this.mPositionIsChecked = new ArrayList<>();
|
||||||
for (int ttlTime : CacheTTLPrefs.CACHE_TTLS) {
|
for (int ttlTime : CacheTTLPrefs.CACHE_TTLS) {
|
||||||
mPositionIsChecked.add(prefs.ttlTimes.contains(ttlTime));
|
mPositionIsChecked.add(prefs.ttlTimes.contains(ttlTime));
|
||||||
if (ttlTime == prefs.defaultTtl) {
|
|
||||||
mDefaultPosition = mPositionIsChecked.size() -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheTTLPrefs getPrefs() {
|
public CacheTTLPrefs getPrefs() {
|
||||||
ArrayList<String> ttls = new ArrayList<>();
|
ArrayList<String> ttls = new ArrayList<>();
|
||||||
int defaultTtl = 0;
|
|
||||||
for (int i = 0; i < mPositionIsChecked.size(); i++) {
|
for (int i = 0; i < mPositionIsChecked.size(); i++) {
|
||||||
if (mPositionIsChecked.get(i)) {
|
if (mPositionIsChecked.get(i)) {
|
||||||
ttls.add(Integer.toString(CacheTTLPrefs.CACHE_TTLS.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);
|
return new CacheTTLPrefs(ttls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -141,13 +132,11 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
|
|
||||||
CheckBox mChecked;
|
CheckBox mChecked;
|
||||||
TextView mTitle;
|
TextView mTitle;
|
||||||
RadioButton mIsDefault;
|
|
||||||
|
|
||||||
public ViewHolder(View itemView) {
|
public ViewHolder(View itemView) {
|
||||||
super(itemView);
|
super(itemView);
|
||||||
mChecked = (CheckBox) itemView.findViewById(R.id.ttl_selected);
|
mChecked = (CheckBox) itemView.findViewById(R.id.ttl_selected);
|
||||||
mTitle = (TextView) itemView.findViewById(R.id.ttl_title);
|
mTitle = (TextView) itemView.findViewById(R.id.ttl_title);
|
||||||
mIsDefault = (RadioButton) itemView.findViewById(R.id.ttl_default);
|
|
||||||
|
|
||||||
itemView.setOnClickListener(new OnClickListener() {
|
itemView.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -161,17 +150,12 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
|
|
||||||
int ttl = CacheTTLPrefs.CACHE_TTLS.get(position);
|
int ttl = CacheTTLPrefs.CACHE_TTLS.get(position);
|
||||||
boolean isChecked = mPositionIsChecked.get(position);
|
boolean isChecked = mPositionIsChecked.get(position);
|
||||||
boolean isDefault = position == mDefaultPosition;
|
|
||||||
|
|
||||||
mTitle.setText(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl));
|
mTitle.setText(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl));
|
||||||
// avoid some ui flicker by skipping unnecessary updates
|
// avoid some ui flicker by skipping unnecessary updates
|
||||||
if (mChecked.isChecked() != isChecked) {
|
if (mChecked.isChecked() != isChecked) {
|
||||||
mChecked.setChecked(isChecked);
|
mChecked.setChecked(isChecked);
|
||||||
}
|
}
|
||||||
if (mIsDefault.isChecked() != isDefault) {
|
|
||||||
mIsDefault.setChecked(isDefault);
|
|
||||||
}
|
|
||||||
mIsDefault.setEnabled(isChecked);
|
|
||||||
|
|
||||||
mChecked.setOnClickListener(new OnClickListener() {
|
mChecked.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -181,14 +165,6 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mIsDefault.setOnClickListener(!isChecked ? null : new OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
setTtlDefault(position);
|
|
||||||
savePreference();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTtlChecked(int position) {
|
private void setTtlChecked(int position) {
|
||||||
@@ -203,47 +179,10 @@ public class SettingsCacheTTLFragment extends Fragment {
|
|||||||
Notify.create(getActivity(), R.string.settings_cache_ttl_max_three, Style.ERROR).show();
|
Notify.create(getActivity(), R.string.settings_cache_ttl_max_three, Style.ERROR).show();
|
||||||
} else {
|
} else {
|
||||||
mPositionIsChecked.set(position, !isChecked);
|
mPositionIsChecked.set(position, !isChecked);
|
||||||
repositionDefault();
|
|
||||||
}
|
}
|
||||||
notifyItemChanged(position);
|
notifyItemChanged(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repositionDefault() {
|
|
||||||
boolean defaultPositionIsChecked = mPositionIsChecked.get(mDefaultPosition);
|
|
||||||
if (defaultPositionIsChecked) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prefer moving default up
|
|
||||||
int i = mDefaultPosition;
|
|
||||||
while (--i >= 0) {
|
|
||||||
if (mPositionIsChecked.get(i)) {
|
|
||||||
setTtlDefault(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if that didn't work, move it down
|
|
||||||
i = mDefaultPosition;
|
|
||||||
while (++i < mPositionIsChecked.size()) {
|
|
||||||
if (mPositionIsChecked.get(i)) {
|
|
||||||
setTtlDefault(i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// we should never get here - if we do, leave default as is (there is a sanity check in the
|
|
||||||
// set preference method, so no biggie)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTtlDefault(int position) {
|
|
||||||
int previousDefaultPosition = mDefaultPosition;
|
|
||||||
mDefaultPosition = position;
|
|
||||||
notifyItemChanged(previousDefaultPosition);
|
|
||||||
notifyItemChanged(mDefaultPosition);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int countCheckedItems() {
|
private int countCheckedItems() {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
for (boolean isChecked : mPositionIsChecked) {
|
for (boolean isChecked : mPositionIsChecked) {
|
||||||
|
|||||||
@@ -46,23 +46,16 @@ public class CacheTTLSpinner extends AppCompatSpinner {
|
|||||||
|
|
||||||
CacheTTLPrefs prefs = Preferences.getPreferences(context).getPassphraseCacheTtl();
|
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);
|
||||||
int i = 0, defaultPosition = 0;
|
int i = 0;
|
||||||
for (int ttl : CacheTTLPrefs.CACHE_TTLS) {
|
for (int ttl : CacheTTLPrefs.CACHE_TTLS) {
|
||||||
if ( ! prefs.ttlTimes.contains(ttl)) {
|
if ( ! prefs.ttlTimes.contains(ttl)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ttl == prefs.defaultTtl) {
|
|
||||||
defaultPosition = i;
|
|
||||||
}
|
|
||||||
cursor.addRow(new Object[] { i++, ttl, getContext().getString(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl)) });
|
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 }, 0));
|
||||||
new int[] { R.id.simple_item_text },
|
|
||||||
0));
|
|
||||||
|
|
||||||
setSelection(defaultPosition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSelectedTimeToLive() {
|
public int getSelectedTimeToLive() {
|
||||||
|
|||||||
@@ -307,14 +307,12 @@ public class Preferences {
|
|||||||
if (pref == null) {
|
if (pref == null) {
|
||||||
return CacheTTLPrefs.getDefault();
|
return CacheTTLPrefs.getDefault();
|
||||||
}
|
}
|
||||||
int def = mSharedPreferences.getInt(Pref.PASSPHRASE_CACHE_DEFAULT, 300);
|
return new CacheTTLPrefs(pref);
|
||||||
return new CacheTTLPrefs(pref, def);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassphraseCacheTtl(CacheTTLPrefs prefs) {
|
public void setPassphraseCacheTtl(CacheTTLPrefs prefs) {
|
||||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||||
editor.putStringSet(Constants.Pref.PASSPHRASE_CACHE_TTLS, prefs.getStringSet());
|
editor.putStringSet(Constants.Pref.PASSPHRASE_CACHE_TTLS, prefs.getStringSet());
|
||||||
editor.putInt(Pref.PASSPHRASE_CACHE_DEFAULT, prefs.defaultTtl);
|
|
||||||
editor.commit();
|
editor.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,10 +334,8 @@ public class Preferences {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HashSet<Integer> ttlTimes;
|
public HashSet<Integer> ttlTimes;
|
||||||
public int defaultTtl;
|
|
||||||
|
|
||||||
public CacheTTLPrefs(Collection<String> ttlStrings, int defaultTtl) {
|
public CacheTTLPrefs(Collection<String> ttlStrings) {
|
||||||
this.defaultTtl = defaultTtl;
|
|
||||||
ttlTimes = new HashSet<>();
|
ttlTimes = new HashSet<>();
|
||||||
for (String ttlString : ttlStrings) {
|
for (String ttlString : ttlStrings) {
|
||||||
ttlTimes.add(Integer.parseInt(ttlString));
|
ttlTimes.add(Integer.parseInt(ttlString));
|
||||||
@@ -356,11 +352,10 @@ public class Preferences {
|
|||||||
|
|
||||||
public static CacheTTLPrefs getDefault() {
|
public static CacheTTLPrefs getDefault() {
|
||||||
ArrayList<String> ttlStrings = new ArrayList<>();
|
ArrayList<String> ttlStrings = new ArrayList<>();
|
||||||
ttlStrings.add(Integer.toString(0));
|
|
||||||
ttlStrings.add(Integer.toString(60 * 5));
|
ttlStrings.add(Integer.toString(60 * 5));
|
||||||
ttlStrings.add(Integer.toString(60 * 60));
|
ttlStrings.add(Integer.toString(60 * 60));
|
||||||
ttlStrings.add(Integer.toString(60 * 60 * 24));
|
ttlStrings.add(Integer.toString(60 * 60 * 24));
|
||||||
return new CacheTTLPrefs(ttlStrings, 0);
|
return new CacheTTLPrefs(ttlStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,44 +20,6 @@
|
|||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:text="@string/settings_cache_select_three"/>
|
android:text="@string/settings_cache_select_three"/>
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_margin="8dp"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:text="@string/setting_cache_select_default"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginLeft="12dp"
|
|
||||||
android:src="@drawable/ic_expand_more_black_24dp"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginRight="12dp"
|
|
||||||
android:src="@drawable/ic_expand_more_black_24dp"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View style="@style/Divider"/>
|
<View style="@style/Divider"/>
|
||||||
|
|||||||
@@ -26,11 +26,4 @@
|
|||||||
tools:text="One Hour"
|
tools:text="One Hour"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<RadioButton
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:id="@+id/ttl_default"
|
|
||||||
android:padding="4dp"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -1716,8 +1716,7 @@
|
|||||||
<string name="cache_ttl_three_hours">"for Three Hours"</string>
|
<string name="cache_ttl_three_hours">"for Three Hours"</string>
|
||||||
<string name="cache_ttl_one_day">"for One Day"</string>
|
<string name="cache_ttl_one_day">"for One Day"</string>
|
||||||
<string name="cache_ttl_three_days">"for Three Days"</string>
|
<string name="cache_ttl_three_days">"for Three Days"</string>
|
||||||
<string name="settings_cache_select_three">"Pick up to three"</string>
|
<string name="settings_cache_select_three">"Pick up to three."</string>
|
||||||
<string name="setting_cache_select_default">"and one default"</string>
|
|
||||||
<string name="settings_cache_ttl_at_least_one">"At least one item must be selected!"</string>
|
<string name="settings_cache_ttl_at_least_one">"At least one item must be selected!"</string>
|
||||||
<string name="settings_cache_ttl_max_three">"Can\'t select more than three items!"</string>
|
<string name="settings_cache_ttl_max_three">"Can\'t select more than three items!"</string>
|
||||||
<string name="remember">"Remember"</string>
|
<string name="remember">"Remember"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user