From f506bfb14aca5c2cdeeb95b0b80475bd72a8e1d6 Mon Sep 17 00:00:00 2001 From: Morgan Lim Date: Thu, 9 Jul 2020 15:54:27 -0400 Subject: [PATCH 1/3] Rename Day/Night and Day/Black to "Dynamic". On v28/Android Pie and lower, themes still change based on time of day. On Android 10 and up, theme changes in accordance with system dark mode setting. --- .../net/nullsum/audinaut/activity/SubsonicActivity.java | 9 ++++++++- app/src/main/res/values/strings.xml | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java index 33fe394..f687a68 100644 --- a/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java +++ b/app/src/main/java/net/nullsum/audinaut/activity/SubsonicActivity.java @@ -24,6 +24,7 @@ import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.media.AudioManager; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; @@ -85,7 +86,13 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte private static ImageLoader IMAGE_LOADER; static { - AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); + // If Android Pie or older, set night mode by system clock + if (Build.VERSION.SDK_INT<29) { + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO); + } else { + // Else, for Android 10+, follow system dark mode setting + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); + } } final List backStack = new ArrayList<>(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index de4dfa7..25ca90c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -162,8 +162,8 @@ Light Dark Black - Day/Night - Day/Black Night + Dynamic (Light/Dark) + Dynamic (Light/Black) Fullscreen Hide as many UI elements as Android will allow Display Track # From d37a72b2a06fb52e5c7e6c6c9b2c8cbe7ca3d576 Mon Sep 17 00:00:00 2001 From: Morgan Lim Date: Thu, 9 Jul 2020 17:01:34 -0400 Subject: [PATCH 2/3] Remove default "light" value for theme in settings_appearance.xml. Change getTheme logic to give a default of day/night on Android 10+. --- .../java/net/nullsum/audinaut/util/ThemeUtil.java | 13 ++++++++++++- app/src/main/res/xml/settings_appearance.xml | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java b/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java index 27efe6d..81fe62a 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java +++ b/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java @@ -18,8 +18,11 @@ package net.nullsum.audinaut.util; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.os.Build; import android.util.Log; +import androidx.appcompat.app.AppCompatDelegate; + import net.nullsum.audinaut.R; import net.nullsum.audinaut.activity.SettingsActivity; import net.nullsum.audinaut.activity.SubsonicFragmentActivity; @@ -33,7 +36,15 @@ public final class ThemeUtil { public static String getTheme(Context context) { SharedPreferences prefs = Util.getPreferences(context); - String theme = prefs.getString(Constants.PREFERENCES_KEY_THEME, null); + String theme; + + if (Build.VERSION.SDK_INT<29) { + // If Android Pie or older, default to null (handled below as light) + theme = prefs.getString(Constants.PREFERENCES_KEY_THEME, null); + } else { + // Else, for Android 10+, default to follow system dark mode setting + theme = prefs.getString(Constants.PREFERENCES_KEY_THEME, THEME_DAY_NIGHT); + } if (THEME_DAY_NIGHT.equals(theme)) { int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; diff --git a/app/src/main/res/xml/settings_appearance.xml b/app/src/main/res/xml/settings_appearance.xml index 548cf25..597fc5d 100644 --- a/app/src/main/res/xml/settings_appearance.xml +++ b/app/src/main/res/xml/settings_appearance.xml @@ -3,7 +3,6 @@ android:title="@string/settings.appearance_title"> Date: Thu, 9 Jul 2020 17:03:47 -0400 Subject: [PATCH 3/3] remove unused import added by IDE --- app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java b/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java index 81fe62a..7df24d7 100644 --- a/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java +++ b/app/src/main/java/net/nullsum/audinaut/util/ThemeUtil.java @@ -21,8 +21,6 @@ import android.content.res.Configuration; import android.os.Build; import android.util.Log; -import androidx.appcompat.app.AppCompatDelegate; - import net.nullsum.audinaut.R; import net.nullsum.audinaut.activity.SettingsActivity; import net.nullsum.audinaut.activity.SubsonicFragmentActivity;