Improve theme based texts

This commit is contained in:
Michael Schättgen 2019-03-28 01:27:07 +01:00
parent 59c0ca947d
commit f7c32bc28b
4 changed files with 26 additions and 12 deletions

View file

@ -16,4 +16,24 @@ public enum Theme {
}
return null;
}
public static String getThemeName(int x) {
switch(x) {
case 0:
return "Light theme";
case 1:
return "Dark theme";
case 2:
return "Amoled theme";
}
return null;
}
public static String[] getThemeNames() {
return new String[] {
"Light theme",
"Dark theme",
"Amoled theme"
};
}
}

View file

@ -91,24 +91,20 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
// set the result intent in advance
setResult(new Intent());
int currentTheme = app.getPreferences().getCurrentTheme();
Preference darkModePreference = findPreference("pref_dark_mode");
darkModePreference.setSummary("Selected: " + Theme.getThemeName(currentTheme));
darkModePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
String[] themeNames = {"Light theme", "Dark theme", "Amoled theme"};
String[] themeNames = Theme.getThemeNames();
int checkedTheme = app.getPreferences().getCurrentTheme();
Dialogs.showSecureDialog(new AlertDialog.Builder(getActivity())
.setTitle(getString(R.string.choose_theme))
.setSingleChoiceItems(themeNames, checkedTheme, (dialog, which) -> {
int i = ((AlertDialog) dialog).getListView().getCheckedItemPosition();
Theme selectedTheme = Theme.fromInteger(i);
app.getPreferences().setCurrentTheme(selectedTheme);
if (selectedTheme == Theme.AMOLED)
{
Toast.makeText(app, "Due to a bug in a third party library, the amoled theme is not visible here.", Toast.LENGTH_LONG).show();
}
app.getPreferences().setCurrentTheme(Theme.fromInteger(i));
_result.putExtra("needsRecreate", true);
getActivity().recreate();

View file

@ -11,8 +11,7 @@
<string name="title_activity_intro">IntroActivity</string>
<string name="settings">Preferences</string>
<string name="pref_dark_mode_title">Dark mode</string>
<string name="pref_dark_mode_summary">Enable this to use darker colors</string>
<string name="pref_select_theme_title">Theme</string>
<string name="pref_account_name_title">Show the account name</string>
<string name="pref_account_name_summary">Enable this to show the account name next to the issuer</string>
<string name="pref_timeout_title">Timeout</string>

View file

@ -10,8 +10,7 @@
<Preference
android:defaultValue="false"
android:key="pref_dark_mode"
android:title="@string/pref_dark_mode_title"
android:summary="@string/pref_dark_mode_summary"
android:title="@string/pref_select_theme_title"
app:iconSpaceReserved="false"/>
<androidx.preference.SwitchPreferenceCompat