Split out privacy settings into separate category

This commit is contained in:
str4d
2015-05-29 06:40:26 +00:00
parent 801655b1a9
commit 95df77cef6
6 changed files with 117 additions and 64 deletions

View File

@@ -2,8 +2,6 @@ package i2p.bote.android.config;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.v4.preference.PreferenceFragment;
@@ -18,7 +16,6 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
addPreferencesFromResource(R.xml.settings_general);
setupGeneralSettings();
}
@Override
@@ -41,16 +38,6 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
config.setMailCheckInterval(prefs.getInt(x, 30));
else if ("deliveryCheckEnabled".equals(x))
config.setDeliveryCheckEnabled(prefs.getBoolean(x, true));
else if ("hideLocale".equals(x))
config.setHideLocale(prefs.getBoolean(x, true));
else if ("includeSentTime".equals(x))
config.setIncludeSentTime(prefs.getBoolean(x, true));
else if ("numSendHops".equals(x))
config.setNumStoreHops(Integer.parseInt(prefs.getString(x, "0")));
else if ("relayMinDelay".equals(x))
config.setRelayMinDelay(prefs.getInt(x, 5));
else if ("relayMaxDelay".equals(x))
config.setRelayMaxDelay(prefs.getInt(x, 40));
}
config.save();
@@ -58,20 +45,4 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
// Store the settings in Android
super.onPause();
}
private void setupGeneralSettings() {
ListPreference numSendHops = (ListPreference) findPreference("numSendHops");
int value = Integer.valueOf(numSendHops.getValue());
numSendHops.setSummary(getResources().getQuantityString(R.plurals.pref_summ_numHops,
value, value));
numSendHops.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int value = Integer.valueOf((String) newValue);
preference.setSummary(getResources().getQuantityString(R.plurals.pref_summ_numHops,
value, value));
return true;
}
});
}
}

View File

@@ -0,0 +1,71 @@
package i2p.bote.android.config;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.support.v4.preference.PreferenceFragment;
import java.util.Map;
import i2p.bote.Configuration;
import i2p.bote.I2PBote;
import i2p.bote.android.R;
public class PrivacyPreferenceFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
addPreferencesFromResource(R.xml.settings_privacy);
setupPrivacySettings();
}
@Override
public void onResume() {
super.onResume();
//noinspection ConstantConditions
((SettingsActivity) getActivity()).getSupportActionBar().setTitle(R.string.pref_title_privacy);
}
@Override
public void onPause() {
Configuration config = I2PBote.getInstance().getConfiguration();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
Map<String, ?> all = prefs.getAll();
for (String x : all.keySet()) {
if ("hideLocale".equals(x))
config.setHideLocale(prefs.getBoolean(x, true));
else if ("includeSentTime".equals(x))
config.setIncludeSentTime(prefs.getBoolean(x, true));
else if ("numSendHops".equals(x))
config.setNumStoreHops(Integer.parseInt(prefs.getString(x, "0")));
else if ("relayMinDelay".equals(x))
config.setRelayMinDelay(prefs.getInt(x, 5));
else if ("relayMaxDelay".equals(x))
config.setRelayMaxDelay(prefs.getInt(x, 40));
}
config.save();
// Store the settings in Android
super.onPause();
}
private void setupPrivacySettings() {
ListPreference numSendHops = (ListPreference) findPreference("numSendHops");
int value = Integer.valueOf(numSendHops.getValue());
numSendHops.setSummary(getResources().getQuantityString(R.plurals.pref_summ_numHops,
value, value));
numSendHops.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
int value = Integer.valueOf((String) newValue);
preference.setSummary(getResources().getQuantityString(R.plurals.pref_summ_numHops,
value, value));
return true;
}
});
}
}

View File

@@ -22,6 +22,7 @@ public class SettingsActivity extends BoteActivityBase implements
public static final String PREFERENCE_CATEGORY_GENERAL = "preference_category_general";
public static final String PREFERENCE_CATEGORY_CHANGE_PASSWORD = "preference_category_change_password";
public static final String PREFERENCE_CATEGORY_IDENTITIES = "preference_category_identities";
public static final String PREFERENCE_CATEGORY_PRIVACY = "preference_category_privacy";
public static final String PREFERENCE_CATEGORY_APPEARANCE = "preference_category_appearance";
public static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced";
@@ -93,6 +94,8 @@ public class SettingsActivity extends BoteActivityBase implements
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_CHANGE_PASSWORD));
findPreference(PREFERENCE_CATEGORY_IDENTITIES)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_IDENTITIES));
findPreference(PREFERENCE_CATEGORY_PRIVACY)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_PRIVACY));
findPreference(PREFERENCE_CATEGORY_APPEARANCE)
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APPEARANCE));
findPreference(PREFERENCE_CATEGORY_ADVANCED)
@@ -143,6 +146,8 @@ public class SettingsActivity extends BoteActivityBase implements
switch (category) {
case PREFERENCE_CATEGORY_GENERAL:
return new GeneralPreferenceFragment();
case PREFERENCE_CATEGORY_PRIVACY:
return new PrivacyPreferenceFragment();
case PREFERENCE_CATEGORY_APPEARANCE:
return new AppearancePreferenceFragment();
case PREFERENCE_CATEGORY_ADVANCED:

View File

@@ -9,6 +9,9 @@
<Preference
android:key="preference_category_identities"
android:title="@string/pref_title_identities"/>
<Preference
android:key="preference_category_privacy"
android:title="@string/pref_title_privacy" />
<Preference
android:key="preference_category_appearance"
android:title="@string/settings_label_appearance" />

View File

@@ -19,39 +19,4 @@
android:summary="@string/pref_summ_delivery"
android:title="@string/pref_title_delivery" />
<PreferenceCategory android:title="@string/pref_title_privacy" >
<CheckBoxPreference
android:defaultValue="true"
android:key="hideLocale"
android:summaryOn="@string/pref_summ_hideLocale"
android:summaryOff="@string/pref_summ_hideLocale_off"
android:title="@string/pref_title_hideLocale" />
<CheckBoxPreference
android:defaultValue="true"
android:key="includeSentTime"
android:summary="@string/pref_summ_sentTime"
android:title="@string/pref_title_sentTime" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_title_routing" >
<ListPreference
android:defaultValue="0"
android:entries="@array/setting0to3"
android:entryValues="@array/setting0to3"
android:key="numSendHops"
android:title="@string/pref_title_numSendHops" />
<i2p.bote.android.widget.IntEditTextPreference
android:defaultValue="5"
android:dependency="numSendHops"
android:key="relayMinDelay"
android:summary="@string/pref_summ_minDelay"
android:title="@string/pref_title_minDelay" />
<i2p.bote.android.widget.IntEditTextPreference
android:defaultValue="40"
android:dependency="numSendHops"
android:key="relayMaxDelay"
android:summary="@string/pref_summ_maxDelay"
android:title="@string/pref_title_maxDelay" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="true"
android:key="hideLocale"
android:summaryOff="@string/pref_summ_hideLocale_off"
android:summaryOn="@string/pref_summ_hideLocale"
android:title="@string/pref_title_hideLocale"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="includeSentTime"
android:summary="@string/pref_summ_sentTime"
android:title="@string/pref_title_sentTime"/>
<PreferenceCategory android:title="@string/pref_title_routing">
<ListPreference
android:defaultValue="0"
android:entries="@array/setting0to3"
android:entryValues="@array/setting0to3"
android:key="numSendHops"
android:title="@string/pref_title_numSendHops"/>
<i2p.bote.android.widget.IntEditTextPreference
android:defaultValue="5"
android:dependency="numSendHops"
android:key="relayMinDelay"
android:summary="@string/pref_summ_minDelay"
android:title="@string/pref_title_minDelay"/>
<i2p.bote.android.widget.IntEditTextPreference
android:defaultValue="40"
android:dependency="numSendHops"
android:key="relayMaxDelay"
android:summary="@string/pref_summ_maxDelay"
android:title="@string/pref_title_maxDelay"/>
</PreferenceCategory>
</PreferenceScreen>