Skip to content

Commit

Permalink
Fix default theme setting
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlecat committed Dec 28, 2024
1 parent 65683c4 commit 68d9f57
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
};
}
Expand Down
17 changes: 7 additions & 10 deletions app/src/main/java/me/tsukanov/counter/view/Themes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/values.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

<!-- Theme variants -->
<string-array name="themeSelectionEntries">
<item>@string/settings_theme_system</item>
<item>@string/settings_theme_light</item>
<item>@string/settings_theme_dark</item>
<item>@string/settings_theme_auto_battery</item>
<item>@string/settings_theme_system</item>
</string-array>
<string-array name="themeSelectionValues">
<item>system</item>
<item>light</item>
<item>dark</item>
<item>auto</item>
<item>system</item>
</string-array>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<PreferenceCategory android:title="@string/settings_display">
<ListPreference
android:defaultValue="light"
android:defaultValue="system"
android:entries="@array/themeSelectionEntries"
android:entryValues="@array/themeSelectionValues"
android:icon="@drawable/ic_palette"
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ext {
compileSdkVersion = 35
minSdkVersion = 24

appVersion = 30
appVersion = 31
}

tasks.withType(JavaCompile).configureEach {
Expand Down

0 comments on commit 68d9f57

Please sign in to comment.