23
23
import android .preference .ListPreference ;
24
24
import android .preference .Preference ;
25
25
import android .preference .PreferenceFragment ;
26
+ import android .preference .PreferenceGroup ;
26
27
import android .preference .PreferenceManager ;
27
28
import android .view .Menu ;
28
29
import android .widget .Toast ;
@@ -42,6 +43,7 @@ public class SettingsFragment extends PreferenceFragment
42
43
43
44
private static final String TAG = SettingsFragment .class .getSimpleName ();
44
45
private static final int MAX_ENDPOINT_OPTIONS = 3 ;
46
+ private PreferenceGroup mCustomEndpointCategory ;
45
47
46
48
public SettingsFragment () {
47
49
}
@@ -54,6 +56,9 @@ public void onCreate(Bundle savedInstanceState) {
54
56
// Load the preferences from an XML resource
55
57
addPreferencesFromResource (R .xml .settings );
56
58
updatePwsList ();
59
+ mCustomEndpointCategory =
60
+ (PreferenceGroup ) findPreference (getString (R .string .custom_pws_endpoint_key ));
61
+ updatePwsPreference ();
57
62
updateAllSettingSummaries ();
58
63
}
59
64
@@ -97,6 +102,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
97
102
updatePwsPreference ();
98
103
updatePwsList ();
99
104
} else if (key .equals (getString (R .string .pws_endpoint_setting_key ))) {
105
+ updatePwsPreference ();
100
106
Utils .deleteCache (getActivity ());
101
107
}
102
108
}
@@ -128,21 +134,31 @@ private void updatePwsPreference() {
128
134
ListPreference listPreference = (ListPreference ) findPreference (
129
135
getString (R .string .pws_endpoint_setting_key ));
130
136
String entry = (String ) listPreference .getEntry ();
131
- if (entry != null && entry .equals (getString (R .string .custom_pws ))) {
137
+ if (entry == null ) {
138
+ return ;
139
+ }
140
+
141
+ if (entry .equals (getString (R .string .custom_pws ))) {
132
142
// User selected custom PWS therefore need to update it accordingly
133
- EditTextPreference customPwsUrlPreference = (EditTextPreference ) findPreference (
134
- getString (R .string .custom_pws_url_key ));
135
- ListPreference customPwsVersionPreference = (ListPreference ) findPreference (
136
- getString (R .string .custom_pws_version_key ));
137
- EditTextPreference customPwsApiKeyPreference = (EditTextPreference ) findPreference (
138
- getString (R .string .custom_pws_api_key_key ));
143
+ EditTextPreference customPwsUrlPreference =
144
+ (EditTextPreference ) mCustomEndpointCategory .findPreference (
145
+ getString (R .string .custom_pws_url_key ));
146
+ ListPreference customPwsVersionPreference =
147
+ (ListPreference ) mCustomEndpointCategory .findPreference (
148
+ getString (R .string .custom_pws_version_key ));
149
+ EditTextPreference customPwsApiKeyPreference =
150
+ (EditTextPreference ) mCustomEndpointCategory .findPreference (
151
+ getString (R .string .custom_pws_api_key_key ));
139
152
String customPwsUrl = customPwsUrlPreference .getText ();
140
153
int customPwsVersion = Integer .parseInt (customPwsVersionPreference .getValue ());
141
154
String customPwsApiKey = customPwsApiKeyPreference .getText ();
142
155
customPwsUrl = customPwsUrl == null ? "" : customPwsUrl ;
143
156
customPwsApiKey = customPwsApiKey == null ? "" : customPwsApiKey ;
144
157
listPreference .setValue (Utils .formatEndpointForSharedPrefernces (customPwsUrl ,
145
158
customPwsVersion , customPwsApiKey ));
159
+ getPreferenceScreen ().addPreference (mCustomEndpointCategory );
160
+ } else {
161
+ getPreferenceScreen ().removePreference (mCustomEndpointCategory );
146
162
}
147
163
}
148
164
0 commit comments