Merge pull request #90 from the-salami/dark-mode

change day/night themes to support dark mode setting on Android 10+
This commit is contained in:
Andrew Rabert 2020-07-09 18:54:56 -04:00 committed by GitHub
commit a861e035ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View File

@ -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<SubsonicFragment> backStack = new ArrayList<>();

View File

@ -18,6 +18,7 @@ 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 net.nullsum.audinaut.R;
@ -33,7 +34,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;

View File

@ -162,8 +162,8 @@
<string name="settings.theme_light">Light</string>
<string name="settings.theme_dark">Dark</string>
<string name="settings.theme_black">Black</string>
<string name="settings.theme_day_night">Day/Night</string>
<string name="settings.theme_day_black_night">Day/Black Night</string>
<string name="settings.theme_day_night">Dynamic (Light/Dark)</string>
<string name="settings.theme_day_black_night">Dynamic (Light/Black)</string>
<string name="settings.theme_fullscreen">Fullscreen</string>
<string name="settings.theme_fullscreen_summary">Hide as many UI elements as Android will allow</string>
<string name="settings.track_title">Display Track #</string>

View File

@ -3,7 +3,6 @@
android:title="@string/settings.appearance_title">
<ListPreference
android:defaultValue="light"
android:entries="@array/themeNames"
android:entryValues="@array/themeValues"
android:key="theme"