Merge pull request #515 from stefan-niedermann/rdtt

Condensed code in PreferencesFragment
This commit is contained in:
dan0xii 2019-01-19 11:56:02 +00:00 committed by GitHub
commit 81c881d5a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,9 +32,9 @@ public class PreferencesFragment extends PreferenceFragment {
final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme)); final SwitchPreference themePref = (SwitchPreference) findPreference(getString(R.string.pref_key_theme));
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
Boolean darkTheme = sp.getBoolean(getString(R.string.pref_key_theme), false);
setThemePreferenceSummary(themePref, darkTheme); themePref.setSummary(sp.getBoolean(getString(R.string.pref_key_theme), false) ?
getString(R.string.pref_value_theme_dark) : getString(R.string.pref_value_theme_light));
themePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { themePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
@ -47,12 +47,4 @@ public class PreferencesFragment extends PreferenceFragment {
} }
}); });
} }
private void setThemePreferenceSummary(SwitchPreference themePref, Boolean darkTheme) {
if (darkTheme) {
themePref.setSummary(getString(R.string.pref_value_theme_dark));
} else {
themePref.setSummary(getString(R.string.pref_value_theme_light));
}
}
} }