Skip to content

Commit

Permalink
Merge pull request google#869 from cco3/preffragsearch
Browse files Browse the repository at this point in the history
Hide custom PWS settings when not in use
  • Loading branch information
cco3 authored Dec 14, 2016
2 parents 79eac72 + 56cf946 commit 82148f0
Showing 1 changed file with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.widget.Toast;
Expand All @@ -42,6 +43,7 @@ public class SettingsFragment extends PreferenceFragment

private static final String TAG = SettingsFragment.class.getSimpleName();
private static final int MAX_ENDPOINT_OPTIONS = 3;
private PreferenceGroup mCustomEndpointCategory;

public SettingsFragment() {
}
Expand All @@ -54,6 +56,9 @@ public void onCreate(Bundle savedInstanceState) {
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.settings);
updatePwsList();
mCustomEndpointCategory =
(PreferenceGroup) findPreference(getString(R.string.custom_pws_endpoint_key));
updatePwsPreference();
updateAllSettingSummaries();
}

Expand Down Expand Up @@ -97,6 +102,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
updatePwsPreference();
updatePwsList();
} else if (key.equals(getString(R.string.pws_endpoint_setting_key))) {
updatePwsPreference();
Utils.deleteCache(getActivity());
}
}
Expand Down Expand Up @@ -128,21 +134,31 @@ private void updatePwsPreference() {
ListPreference listPreference = (ListPreference) findPreference(
getString(R.string.pws_endpoint_setting_key));
String entry = (String) listPreference.getEntry();
if (entry != null && entry.equals(getString(R.string.custom_pws))) {
if (entry == null) {
return;
}

if (entry.equals(getString(R.string.custom_pws))) {
// User selected custom PWS therefore need to update it accordingly
EditTextPreference customPwsUrlPreference = (EditTextPreference) findPreference(
getString(R.string.custom_pws_url_key));
ListPreference customPwsVersionPreference = (ListPreference) findPreference(
getString(R.string.custom_pws_version_key));
EditTextPreference customPwsApiKeyPreference = (EditTextPreference) findPreference(
getString(R.string.custom_pws_api_key_key));
EditTextPreference customPwsUrlPreference =
(EditTextPreference) mCustomEndpointCategory.findPreference(
getString(R.string.custom_pws_url_key));
ListPreference customPwsVersionPreference =
(ListPreference) mCustomEndpointCategory.findPreference(
getString(R.string.custom_pws_version_key));
EditTextPreference customPwsApiKeyPreference =
(EditTextPreference) mCustomEndpointCategory.findPreference(
getString(R.string.custom_pws_api_key_key));
String customPwsUrl = customPwsUrlPreference.getText();
int customPwsVersion = Integer.parseInt(customPwsVersionPreference.getValue());
String customPwsApiKey = customPwsApiKeyPreference.getText();
customPwsUrl = customPwsUrl == null ? "" : customPwsUrl;
customPwsApiKey = customPwsApiKey == null ? "" : customPwsApiKey;
listPreference.setValue(Utils.formatEndpointForSharedPrefernces(customPwsUrl,
customPwsVersion, customPwsApiKey));
getPreferenceScreen().addPreference(mCustomEndpointCategory);
} else {
getPreferenceScreen().removePreference(mCustomEndpointCategory);
}
}

Expand Down

0 comments on commit 82148f0

Please sign in to comment.