Extract I2P router config to advanced settings
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
package i2p.bote.android.config;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.widget.SummaryEditTextPreference;
|
||||
|
||||
public class AdvancedPreferenceFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle paramBundle) {
|
||||
super.onCreate(paramBundle);
|
||||
addPreferencesFromResource(R.xml.settings_advanced);
|
||||
setupAdvancedSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
//noinspection ConstantConditions
|
||||
((SettingsActivity) getActivity()).getSupportActionBar().setTitle(R.string.settings_label_advanced);
|
||||
}
|
||||
|
||||
private void setupAdvancedSettings() {
|
||||
final PreferenceCategory i2pCat = (PreferenceCategory) findPreference("i2pCategory");
|
||||
CheckBoxPreference routerAuto = (CheckBoxPreference) findPreference("i2pbote.router.auto");
|
||||
|
||||
if (!routerAuto.isChecked()) {
|
||||
setupI2PCategory(getActivity(), i2pCat);
|
||||
}
|
||||
|
||||
routerAuto.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final Boolean checked = (Boolean) newValue;
|
||||
if (!checked) {
|
||||
setupI2PCategory(getActivity(), i2pCat);
|
||||
} else {
|
||||
Preference p1 = i2pCat.findPreference("i2pbote.router.use");
|
||||
Preference p2 = i2pCat.findPreference("i2pbote.i2cp.tcp.host");
|
||||
Preference p3 = i2pCat.findPreference("i2pbote.i2cp.tcp.port");
|
||||
if (p1 != null)
|
||||
i2pCat.removePreference(p1);
|
||||
if (p2 != null)
|
||||
i2pCat.removePreference(p2);
|
||||
if (p3 != null)
|
||||
i2pCat.removePreference(p3);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setupI2PCategory(Context context, PreferenceCategory i2pCat) {
|
||||
final ListPreference routerChoice = createRouterChoice(context);
|
||||
final EditTextPreference hostField = createHostField(context);
|
||||
final EditTextPreference portField = createPortField(context);
|
||||
i2pCat.addPreference(routerChoice);
|
||||
i2pCat.addPreference(hostField);
|
||||
i2pCat.addPreference(portField);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
|
||||
routerChoice.setSummary(routerChoice.getEntry());
|
||||
|
||||
if ("remote".equals(routerChoice.getValue())) {
|
||||
hostField.setEnabled(true);
|
||||
portField.setEnabled(true);
|
||||
}
|
||||
|
||||
routerChoice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String val = newValue.toString();
|
||||
int index = routerChoice.findIndexOfValue(val);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
|
||||
routerChoice.setSummary(routerChoice.getEntries()[index]);
|
||||
if (index == 2) {
|
||||
hostField.setEnabled(true);
|
||||
hostField.setText("127.0.0.1");
|
||||
portField.setEnabled(true);
|
||||
portField.setText("7654");
|
||||
} else {
|
||||
hostField.setEnabled(false);
|
||||
hostField.setText("internal");
|
||||
portField.setEnabled(false);
|
||||
portField.setText("internal");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ListPreference createRouterChoice(Context context) {
|
||||
ListPreference routerChoice = new ListPreference(context);
|
||||
routerChoice.setKey("i2pbote.router.use");
|
||||
routerChoice.setEntries(R.array.routerOptionNames);
|
||||
routerChoice.setEntryValues(R.array.routerOptions);
|
||||
routerChoice.setTitle(R.string.pref_title_router);
|
||||
routerChoice.setSummary("%s");
|
||||
routerChoice.setDialogTitle(R.string.pref_dialog_title_router);
|
||||
routerChoice.setDefaultValue("internal");
|
||||
return routerChoice;
|
||||
}
|
||||
|
||||
private static EditTextPreference createHostField(Context context) {
|
||||
EditTextPreference p = new SummaryEditTextPreference(context);
|
||||
p.setKey("i2pbote.i2cp.tcp.host");
|
||||
p.setTitle(R.string.pref_title_i2cp_host);
|
||||
p.setSummary("%s");
|
||||
p.setDefaultValue("internal");
|
||||
p.setEnabled(false);
|
||||
return p;
|
||||
}
|
||||
|
||||
private static EditTextPreference createPortField(Context context) {
|
||||
EditTextPreference p = new SummaryEditTextPreference(context);
|
||||
p.setKey("i2pbote.i2cp.tcp.port");
|
||||
p.setTitle(R.string.pref_title_i2cp_port);
|
||||
p.setSummary("%s");
|
||||
p.setDefaultValue("internal");
|
||||
p.setEnabled(false);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
package i2p.bote.android.config;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
|
||||
@@ -17,7 +12,6 @@ import java.util.Map;
|
||||
import i2p.bote.Configuration;
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.android.R;
|
||||
import i2p.bote.android.widget.SummaryEditTextPreference;
|
||||
|
||||
public class GeneralPreferenceFragment extends PreferenceFragment {
|
||||
@Override
|
||||
@@ -30,6 +24,7 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
//noinspection ConstantConditions
|
||||
((SettingsActivity) getActivity()).getSupportActionBar().setTitle(R.string.pref_title_general);
|
||||
}
|
||||
|
||||
@@ -78,101 +73,5 @@ public class GeneralPreferenceFragment extends PreferenceFragment {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
final PreferenceCategory i2pCat = (PreferenceCategory) findPreference("i2pCategory");
|
||||
CheckBoxPreference routerAuto = (CheckBoxPreference) findPreference("i2pbote.router.auto");
|
||||
|
||||
if (!routerAuto.isChecked()) {
|
||||
setupI2PCategory(getActivity(), i2pCat);
|
||||
}
|
||||
|
||||
routerAuto.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final Boolean checked = (Boolean) newValue;
|
||||
if (!checked) {
|
||||
setupI2PCategory(getActivity(), i2pCat);
|
||||
} else {
|
||||
Preference p1 = i2pCat.findPreference("i2pbote.router.use");
|
||||
Preference p2 = i2pCat.findPreference("i2pbote.i2cp.tcp.host");
|
||||
Preference p3 = i2pCat.findPreference("i2pbote.i2cp.tcp.port");
|
||||
if (p1 != null)
|
||||
i2pCat.removePreference(p1);
|
||||
if (p2 != null)
|
||||
i2pCat.removePreference(p2);
|
||||
if (p3 != null)
|
||||
i2pCat.removePreference(p3);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setupI2PCategory(Context context, PreferenceCategory i2pCat) {
|
||||
final ListPreference routerChoice = createRouterChoice(context);
|
||||
final EditTextPreference hostField = createHostField(context);
|
||||
final EditTextPreference portField = createPortField(context);
|
||||
i2pCat.addPreference(routerChoice);
|
||||
i2pCat.addPreference(hostField);
|
||||
i2pCat.addPreference(portField);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
|
||||
routerChoice.setSummary(routerChoice.getEntry());
|
||||
|
||||
if ("remote".equals(routerChoice.getValue())) {
|
||||
hostField.setEnabled(true);
|
||||
portField.setEnabled(true);
|
||||
}
|
||||
|
||||
routerChoice.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final String val = newValue.toString();
|
||||
int index = routerChoice.findIndexOfValue(val);
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
|
||||
routerChoice.setSummary(routerChoice.getEntries()[index]);
|
||||
if (index == 2) {
|
||||
hostField.setEnabled(true);
|
||||
hostField.setText("127.0.0.1");
|
||||
portField.setEnabled(true);
|
||||
portField.setText("7654");
|
||||
} else {
|
||||
hostField.setEnabled(false);
|
||||
hostField.setText("internal");
|
||||
portField.setEnabled(false);
|
||||
portField.setText("internal");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static ListPreference createRouterChoice(Context context) {
|
||||
ListPreference routerChoice = new ListPreference(context);
|
||||
routerChoice.setKey("i2pbote.router.use");
|
||||
routerChoice.setEntries(R.array.routerOptionNames);
|
||||
routerChoice.setEntryValues(R.array.routerOptions);
|
||||
routerChoice.setTitle(R.string.pref_title_router);
|
||||
routerChoice.setSummary("%s");
|
||||
routerChoice.setDialogTitle(R.string.pref_dialog_title_router);
|
||||
routerChoice.setDefaultValue("internal");
|
||||
return routerChoice;
|
||||
}
|
||||
|
||||
private static EditTextPreference createHostField(Context context) {
|
||||
EditTextPreference p = new SummaryEditTextPreference(context);
|
||||
p.setKey("i2pbote.i2cp.tcp.host");
|
||||
p.setTitle(R.string.pref_title_i2cp_host);
|
||||
p.setSummary("%s");
|
||||
p.setDefaultValue("internal");
|
||||
p.setEnabled(false);
|
||||
return p;
|
||||
}
|
||||
|
||||
private static EditTextPreference createPortField(Context context) {
|
||||
EditTextPreference p = new SummaryEditTextPreference(context);
|
||||
p.setKey("i2pbote.i2cp.tcp.port");
|
||||
p.setTitle(R.string.pref_title_i2cp_port);
|
||||
p.setSummary("%s");
|
||||
p.setDefaultValue("internal");
|
||||
p.setEnabled(false);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class SettingsActivity extends BoteActivityBase implements
|
||||
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_APPEARANCE = "preference_category_appearance";
|
||||
public static final String PREFERENCE_CATEGORY_ADVANCED = "preference_category_advanced";
|
||||
|
||||
|
||||
//
|
||||
@@ -94,6 +95,8 @@ public class SettingsActivity extends BoteActivityBase implements
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_IDENTITIES));
|
||||
findPreference(PREFERENCE_CATEGORY_APPEARANCE)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_APPEARANCE));
|
||||
findPreference(PREFERENCE_CATEGORY_ADVANCED)
|
||||
.setOnPreferenceClickListener(new CategoryClickListener(PREFERENCE_CATEGORY_ADVANCED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -142,6 +145,8 @@ public class SettingsActivity extends BoteActivityBase implements
|
||||
return new GeneralPreferenceFragment();
|
||||
case PREFERENCE_CATEGORY_APPEARANCE:
|
||||
return new AppearancePreferenceFragment();
|
||||
case PREFERENCE_CATEGORY_ADVANCED:
|
||||
return new AdvancedPreferenceFragment();
|
||||
default:
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
@@ -204,6 +204,10 @@
|
||||
<string name="pref_summ_minDelay">%s minutes</string>
|
||||
<string name="pref_title_maxDelay">Maximum delay per hop</string>
|
||||
<string name="pref_summ_maxDelay">%s minutes</string>
|
||||
<string name="settings_label_appearance">Appearance</string>
|
||||
<string name="settings_label_language">Language</string>
|
||||
<string name="settings_default">Default</string>
|
||||
<string name="settings_label_advanced">Advanced</string>
|
||||
<string name="router_settings">Router settings</string>
|
||||
<string name="auto">Auto</string>
|
||||
<string name="manual">Manual</string>
|
||||
@@ -213,9 +217,6 @@
|
||||
<string name="pref_dialog_title_router">Router to use</string>
|
||||
<string name="pref_title_i2cp_host">I2CP host</string>
|
||||
<string name="pref_title_i2cp_port">I2CP port</string>
|
||||
<string name="settings_label_appearance">Appearance</string>
|
||||
<string name="settings_label_language">Language</string>
|
||||
<string name="settings_default">Default</string>
|
||||
<string name="pref_title_change_password">Change password</string>
|
||||
<string name="old_password">Old password</string>
|
||||
<string name="new_password">New password</string>
|
||||
|
||||
@@ -12,4 +12,7 @@
|
||||
<Preference
|
||||
android:key="preference_category_appearance"
|
||||
android:title="@string/settings_label_appearance" />
|
||||
<Preference
|
||||
android:key="preference_category_advanced"
|
||||
android:title="@string/settings_label_advanced" />
|
||||
</PreferenceScreen>
|
||||
16
app/src/main/res/xml/settings_advanced.xml
Normal file
16
app/src/main/res/xml/settings_advanced.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="i2pCategory"
|
||||
android:title="I2P" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:disableDependentsState="true"
|
||||
android:key="i2pbote.router.auto"
|
||||
android:summaryOff="@string/manual"
|
||||
android:summaryOn="@string/auto"
|
||||
android:title="@string/router_settings" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -53,16 +53,5 @@
|
||||
android:summary="@string/pref_summ_maxDelay"
|
||||
android:title="@string/pref_title_maxDelay" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="i2pCategory"
|
||||
android:title="I2P" >
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:disableDependentsState="true"
|
||||
android:key="i2pbote.router.auto"
|
||||
android:summaryOff="@string/manual"
|
||||
android:summaryOn="@string/auto"
|
||||
android:title="@string/router_settings" />
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user