diff --git a/CHANGELOG.md b/CHANGELOG.md index 9701e8c6..0104d95a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Version 31 + +* Default theme configuration has been fixed. + ## Version 30 * Links to the project page and tip jar were added to settings. diff --git a/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java b/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java index 7535e408..48336678 100644 --- a/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java +++ b/app/src/main/java/me/tsukanov/counter/activities/SettingsActivity.java @@ -68,10 +68,7 @@ private void initSettingsFragment() { } private String getCurrentThemeName() { - return getResources() - .getString( - Themes.findOrGetDefault(sharedPrefs.getString(SharedPrefKeys.THEME.getName(), null)) - .getLabelId()); + return getResources().getString(Themes.getCurrent(sharedPrefs).getLabelId()); } private OnPreferenceClickListener getOnRemoveCountersClickListener() { @@ -99,14 +96,17 @@ private OnPreferenceClickListener getOnExportClickListener() { private OnPreferenceClickListener getOnHomepageClickListener() { return preference -> { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://counter.roman.zone?utm_source=app"))); + startActivity( + new Intent(Intent.ACTION_VIEW, Uri.parse("https://counter.roman.zone?utm_source=app"))); return true; }; } private OnPreferenceClickListener getOnTipClickListener() { return preference -> { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://counter.roman.zone/tip?utm_source=app"))); + startActivity( + new Intent( + Intent.ACTION_VIEW, Uri.parse("https://counter.roman.zone/tip?utm_source=app"))); return true; }; } diff --git a/app/src/main/java/me/tsukanov/counter/view/Themes.java b/app/src/main/java/me/tsukanov/counter/view/Themes.java index 75b3fc57..241add58 100644 --- a/app/src/main/java/me/tsukanov/counter/view/Themes.java +++ b/app/src/main/java/me/tsukanov/counter/view/Themes.java @@ -2,7 +2,6 @@ import android.content.SharedPreferences; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatDelegate; import me.tsukanov.counter.R; import me.tsukanov.counter.SharedPrefKeys; @@ -31,12 +30,11 @@ public int getLabelId() { } @NonNull - public static Themes findOrGetDefault(final @Nullable String identifier) { - if (identifier != null) { - for (final Themes t : values()) { - if (t.getIdentifier().equals(identifier)) { - return t; - } + public static Themes getCurrent(final @NonNull SharedPreferences sharedPrefs) { + final String identifier = sharedPrefs.getString(SharedPrefKeys.THEME.getName(), SYSTEM.name()); + for (final Themes t : values()) { + if (t.getIdentifier().equals(identifier)) { + return t; } } return SYSTEM; @@ -47,9 +45,8 @@ public static Themes findOrGetDefault(final @Nullable String identifier) { * * @param sharedPrefs {@link SharedPreferences} that contain the theme preference. */ - public static void initCurrentTheme(@NonNull final SharedPreferences sharedPrefs) { - final Themes currentTheme = - Themes.findOrGetDefault(sharedPrefs.getString(SharedPrefKeys.THEME.getName(), null)); + public static void initCurrentTheme(final @NonNull SharedPreferences sharedPrefs) { + final Themes currentTheme = Themes.getCurrent(sharedPrefs); switch (currentTheme) { case LIGHT: diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index 9d886e2d..a8bff179 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -3,16 +3,16 @@ + @string/settings_theme_system @string/settings_theme_light @string/settings_theme_dark @string/settings_theme_auto_battery - @string/settings_theme_system + system light dark auto - system diff --git a/app/src/main/res/xml/settings.xml b/app/src/main/res/xml/settings.xml index 865e1123..37dadf54 100644 --- a/app/src/main/res/xml/settings.xml +++ b/app/src/main/res/xml/settings.xml @@ -31,7 +31,7 @@