[tor-commits] [snowflake-mobile/master] Fixed the bug of EditText deactivated when app restarts
cohosh at torproject.org
cohosh at torproject.org
Fri Jul 10 16:27:27 UTC 2020
commit 5078bbb0325b25c01c58bbf7a282f6218fd9ddb1
Author: Hashik Donthineni <HashikDonthineni at gmail.com>
Date: Sun Jun 28 18:46:14 2020 +0530
Fixed the bug of EditText deactivated when app restarts
---
.../snowflake/constants/SettingsConstants.java | 24 ++++++++++++++++++++++
.../snowflake/fragments/AppSettingsFragment.java | 20 ++++++++++++++++--
2 files changed, 42 insertions(+), 2 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
new file mode 100644
index 0000000..6b6026e
--- /dev/null
+++ b/app/src/main/java/org/torproject/snowflake/constants/SettingsConstants.java
@@ -0,0 +1,24 @@
+package org.torproject.snowflake.constants;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SettingsConstants {
+ //Switches
+ public static final String STUN_SWITCH = "stun_switch";
+ public static final String BROKER_SWITCH = "broker_switch";
+ public static final String RELAY_SWITCH = "relay_switch";
+
+ //Edit Texts
+ public static final String STUN_ET = "stun_edit_text";
+ 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>(){{
+ 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 526f0c8..87c2df9 100644
--- a/app/src/main/java/org/torproject/snowflake/fragments/AppSettingsFragment.java
+++ b/app/src/main/java/org/torproject/snowflake/fragments/AppSettingsFragment.java
@@ -8,6 +8,10 @@ import androidx.preference.Preference;
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 {
@@ -21,7 +25,19 @@ public class AppSettingsFragment extends PreferenceFragmentCompat implements Sha
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.app_settings, rootKey);
- getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+ SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
+ sharedPreferences.registerOnSharedPreferenceChangeListener(this);
+
+ //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);
+
+ boolean isEnabled = sharedPreferences.getBoolean(button, false);
+ findPreference(editT).setEnabled(isEnabled);
+ findPreference(editT).setSummary(
+ sharedPreferences.getString(editT, "Default Value"));
+ }
}
@Override
@@ -49,7 +65,7 @@ public class AppSettingsFragment extends PreferenceFragmentCompat implements Sha
//It's an Edit Text
String editValue = sharedPreferences.getString(key, "");
if (!editValue.equals(""))
- findPreference(key).setSummary(editValue); //Setting Edit text to edited value
+ 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.
}
More information about the tor-commits
mailing list