commit 76a349a7e9b5f4948a8342c5f44fd3c7d809a562 Author: Hashik Donthineni HashikDonthineni@gmail.com Date: Sun Jun 28 21:37:18 2020 +0530
Bug fix: Settings showing as using default servers on app restart even tho they are not --- .../snowflake/constants/SettingsConstants.java | 6 ++++-- .../snowflake/fragments/AppSettingsFragment.java | 23 ++++++++++++---------- app/src/main/res/xml/app_settings.xml | 4 ---- 3 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/app/src/main/java/org/torproject/snowflake/constants/SettingsConstants.java b/app/src/main/java/org/torproject/snowflake/constants/SettingsConstants.java index 6b6026e..95b3ede 100644 --- a/app/src/main/java/org/torproject/snowflake/constants/SettingsConstants.java +++ b/app/src/main/java/org/torproject/snowflake/constants/SettingsConstants.java @@ -14,8 +14,10 @@ public class SettingsConstants { public static final String BROKER_ET = "broker_edit_text"; public static final String RELAY_ET = "relay_edit_text";
- public static Map<String, String> getSettingMap(){ - return new HashMap<String, String>(){{ + public static final String DEFAULT = "Using Default"; + + public static Map<String, String> getSettingMap() { + return new HashMap<String, String>() {{ put(STUN_SWITCH, STUN_ET); put(BROKER_SWITCH, BROKER_ET); put(RELAY_SWITCH, RELAY_ET); diff --git a/app/src/main/java/org/torproject/snowflake/fragments/AppSettingsFragment.java b/app/src/main/java/org/torproject/snowflake/fragments/AppSettingsFragment.java index 87c2df9..409625a 100644 --- a/app/src/main/java/org/torproject/snowflake/fragments/AppSettingsFragment.java +++ b/app/src/main/java/org/torproject/snowflake/fragments/AppSettingsFragment.java @@ -10,7 +10,6 @@ import androidx.preference.PreferenceFragmentCompat; import org.torproject.snowflake.R; import org.torproject.snowflake.constants.SettingsConstants;
-import java.util.Iterator; import java.util.Map;
public class AppSettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { @@ -30,13 +29,17 @@ public class AppSettingsFragment extends PreferenceFragmentCompat implements Sha
//When the fragment is started we have to check and set the EditTexts' to active. Map<String, String> settingMap = SettingsConstants.getSettingMap(); - for(String button: settingMap.keySet()){ - String editT = settingMap.get(button); + for (String settingSwitch : settingMap.keySet()) { + String editT = settingMap.get(settingSwitch);
- boolean isEnabled = sharedPreferences.getBoolean(button, false); - findPreference(editT).setEnabled(isEnabled); - findPreference(editT).setSummary( - sharedPreferences.getString(editT, "Default Value")); + boolean isEnabled = sharedPreferences.getBoolean(settingSwitch, false); + if (!isEnabled) + findPreference(settingSwitch).setSummary(SettingsConstants.DEFAULT); + + Preference editText = findPreference(editT); + editText.setEnabled(isEnabled); + editText.setSummary( + sharedPreferences.getString(editT, SettingsConstants.DEFAULT)); } }
@@ -57,9 +60,9 @@ public class AppSettingsFragment extends PreferenceFragmentCompat implements Sha if (!previousValue.equals("")) editTextPreference.setSummary(previousValue); //When Switch is turned on set the summary to previously set Value. else - editTextPreference.setSummary("Using Default"); //If there is no previous value, then using null. + editTextPreference.setSummary(SettingsConstants.DEFAULT); //If there is no previous value, then using null. } else { - findPreference(key).setSummary("Using Default"); //Default is shown when switch is off. + findPreference(key).setSummary(SettingsConstants.DEFAULT); //Default is shown when switch is off. } } else { //It's an Edit Text @@ -67,7 +70,7 @@ public class AppSettingsFragment extends PreferenceFragmentCompat implements Sha if (!editValue.equals("")) findPreference(key).setSummary(editValue.trim()); //Setting Edit text to edited value else - findPreference(key).setSummary("Using Default"); //Setting Edit text to Default because user left it empty. + findPreference(key).setSummary(SettingsConstants.DEFAULT); //Setting Edit text to Default because user left it empty. } }
diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index a8d08d8..d3a110e 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -7,7 +7,6 @@ app:iconSpaceReserved="false"> <SwitchPreference android:key="stun_switch" - android:summary="Using Default" android:title="Set STUN server" app:iconSpaceReserved="false" /> <EditTextPreference @@ -21,7 +20,6 @@
<SwitchPreference android:key="broker_switch" - android:summary="Using Default" android:title="Set broker URL" app:iconSpaceReserved="false" /> <EditTextPreference @@ -35,7 +33,6 @@
<SwitchPreference android:key="relay_switch" - android:summary="Using Default" android:title="Set relay URL" app:iconSpaceReserved="false" /> <EditTextPreference @@ -43,7 +40,6 @@ android:key="relay_edit_text" android:selectAllOnFocus="true" android:singleLine="true" - android:summary="Using Default" android:title="Custom relay URL" app:iconSpaceReserved="false" />
tor-commits@lists.torproject.org