From 7f91d250beac3c6368d814e18d1bbf490574ca7b Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Wed, 2 Apr 2014 11:31:36 +0200 Subject: [PATCH] Show the user-entered values in server, RSS and search site settings. Fixes #32. --- core/res/xml/pref_server.xml | 3 +- .../settings/KeyBoundPreferencesActivity.java | 37 ++++++++++++++++++- .../gui/settings/ServerSettingsActivity.java | 2 +- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/core/res/xml/pref_server.xml b/core/res/xml/pref_server.xml index 28308db2..c05416cf 100644 --- a/core/res/xml/pref_server.xml +++ b/core/res/xml/pref_server.xml @@ -78,8 +78,7 @@ android:key="server_timeout" android:title="@string/pref_timeout" android:summary="@string/pref_timeout_info" - android:inputType="numberSigned" - android:defaultValue="8" /> + android:inputType="numberSigned" /> originalSummaries = new HashMap(); /** * Should be called during the activity {@link #onCreate(android.os.Bundle)} (but after super.onCreate(Bundle)) to @@ -85,6 +91,7 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi private OnSharedPreferenceChangeListener onPreferenceChangeListener = new OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + showValueOnSummary(key); onPreferencesChanged(); } }; @@ -131,9 +138,12 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi // Update the loaded Preference with the actual preference key to load/store with EditTextPreference pref = (EditTextPreference) findPreference(baseName); pref.setKey(baseName + "_" + key); - pref.setDependency(dependency == null? null: dependency + "_" + key); + pref.setDependency(dependency == null ? null : dependency + "_" + key); // Update the Preference by loading the current stored value into the EditText, if it exists pref.setText(sharedPrefs.getString(baseName + "_" + key, defValue)); + // Remember the original descriptive summary and if we have a value, show that instead + originalSummaries.put(baseName + "_" + key, pref.getSummary() == null ? null : pref.getSummary().toString()); + showValueOnSummary(baseName + "_" + key); return pref; } @@ -171,7 +181,7 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi // Update the loaded Preference with the actual preference key to load/store with CheckBoxPreference pref = (CheckBoxPreference) findPreference(baseName); pref.setKey(baseName + "_" + key); - pref.setDependency(dependency == null? null: dependency + "_" + key); + pref.setDependency(dependency == null ? null : dependency + "_" + key); // Update the Preference by loading the current stored value into the Checkbox, if it exists pref.setChecked(sharedPrefs.getBoolean(baseName + "_" + key, defValue)); return pref; @@ -201,7 +211,30 @@ public abstract class KeyBoundPreferencesActivity extends SherlockPreferenceActi pref.setKey(baseName + "_" + key); // Update the Preference by selecting the current stored value in the list, if it exists pref.setValue(sharedPrefs.getString(baseName + "_" + key, defValue)); + // Remember the original descriptive summary and if we have a value, show that instead + originalSummaries.put(baseName + "_" + key, pref.getSummary() == null ? null : pref.getSummary().toString()); + showValueOnSummary(baseName + "_" + key); return pref; } + @SuppressWarnings("deprecation") + protected void showValueOnSummary(String prefKey) { + Preference pref = findPreference(prefKey); + if (sharedPrefs.contains(prefKey) + && pref instanceof EditTextPreference + && !(((EditTextPreference) pref).getEditText().getTransformationMethod() instanceof PasswordTransformationMethod)) { + // Non-password edit preferences show the user-entered value + pref.setSummary(sharedPrefs.getString(prefKey, "")); + return; + } else if (sharedPrefs.contains(prefKey) && pref instanceof ListPreference + && ((ListPreference) pref).getValue() != null) { + // List preferences show the selected list value + ListPreference listPreference = (ListPreference) pref; + pref.setSummary(listPreference.getEntries()[listPreference.findIndexOfValue(listPreference.getValue())]); + return; + } + if (originalSummaries.containsKey(prefKey)) + pref.setSummary(originalSummaries.get(prefKey)); + } + } diff --git a/core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java b/core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java index 624f0724..fcbc3421 100644 --- a/core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java +++ b/core/src/org/transdroid/core/gui/settings/ServerSettingsActivity.java @@ -61,7 +61,7 @@ public class ServerSettingsActivity extends KeyBoundPreferencesActivity { initTextPreference("server_localaddress"); initTextPreference("server_localport"); folder = initTextPreference("server_folder"); - initTextPreference("server_timeout", "8"); + initTextPreference("server_timeout"); initBooleanPreference("server_alarmfinished", true); initBooleanPreference("server_alarmnew"); initListPreference("server_os", "type_linux");