diff --git a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java index 8126bd2c5..6d1cd3687 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/AppearanceSettingsFragment.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.settings; +import android.app.Activity; import android.content.ActivityNotFoundException; import android.content.Intent; import android.os.Build; @@ -38,6 +39,20 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { return false; } }; + private final Preference.OnPreferenceChangeListener deviceThemePreferenceChange + = new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(final Preference preference, final Object newValue) { + defaultPreferences.edit().putBoolean(Constants.KEY_THEME_CHANGE, true).apply(); + + final Activity activity = getActivity(); + if (activity != null) { + activity.recreate(); + } + + return true; + } + }; private String captionSettingsKey; @Override @@ -48,6 +63,9 @@ public class AppearanceSettingsFragment extends BasePreferenceFragment { .getString(themeKey, getString(R.string.default_theme_value)); findPreference(themeKey).setOnPreferenceChangeListener(themePreferenceChange); + findPreference(getString(R.string.use_device_theme_key)) + .setOnPreferenceChangeListener(deviceThemePreferenceChange); + captionSettingsKey = getString(R.string.caption_settings_key); if (!CAPTIONING_SETTINGS_ACCESSIBLE) { final Preference captionSettings = findPreference(captionSettingsKey); diff --git a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java index b8246f0b2..8129b3295 100644 --- a/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java +++ b/app/src/main/java/org/schabi/newpipe/util/ThemeHelper.java @@ -77,9 +77,7 @@ public final class ThemeHelper { final Resources res = context.getResources(); return selectedThemeString.equals(res.getString(R.string.light_theme_key)) - || (selectedThemeString.equals(res.getString(R.string.device_dark_theme_key)) - || selectedThemeString.equals(res.getString(R.string.device_black_theme_key)) - && !isDeviceDarkThemeEnabled(context)); + || (shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context)); } @@ -142,8 +140,6 @@ public final class ThemeHelper { final String lightTheme = res.getString(R.string.light_theme_key); final String darkTheme = res.getString(R.string.dark_theme_key); final String blackTheme = res.getString(R.string.black_theme_key); - final String deviceDarkTheme = res.getString(R.string.device_dark_theme_key); - final String deviceBlackTheme = res.getString(R.string.device_black_theme_key); final String selectedTheme = getSelectedThemeString(context); @@ -151,19 +147,11 @@ public final class ThemeHelper { if (selectedTheme.equals(lightTheme)) { defaultTheme = R.style.LightTheme; } else if (selectedTheme.equals(blackTheme)) { - defaultTheme = R.style.BlackTheme; - } else if (selectedTheme.equals(deviceDarkTheme)) { - if (isDeviceDarkThemeEnabled(context)) { - defaultTheme = R.style.DarkTheme; - } else { - defaultTheme = R.style.LightTheme; - } - } else if (selectedTheme.equals(deviceBlackTheme)) { - if (isDeviceDarkThemeEnabled(context)) { - defaultTheme = R.style.BlackTheme; - } else { - defaultTheme = R.style.LightTheme; - } + defaultTheme = shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context) + ? R.style.LightTheme : R.style.BlackTheme; + } else if (selectedTheme.equals(darkTheme)) { + defaultTheme = shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context) + ? R.style.LightTheme : R.style.DarkTheme; } if (serviceId <= -1) { @@ -202,29 +190,17 @@ public final class ThemeHelper { final String lightTheme = res.getString(R.string.light_theme_key); final String darkTheme = res.getString(R.string.dark_theme_key); final String blackTheme = res.getString(R.string.black_theme_key); - final String deviceDarkTheme = res.getString(R.string.device_dark_theme_key); - final String deviceBlackTheme = res.getString(R.string.device_black_theme_key); final String selectedTheme = getSelectedThemeString(context); if (selectedTheme.equals(lightTheme)) { return R.style.LightSettingsTheme; } else if (selectedTheme.equals(blackTheme)) { - return R.style.BlackSettingsTheme; + return shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context) + ? R.style.LightSettingsTheme : R.style.BlackSettingsTheme; } else if (selectedTheme.equals(darkTheme)) { - return R.style.DarkSettingsTheme; - } else if (selectedTheme.equals(deviceDarkTheme)) { - if (isDeviceDarkThemeEnabled(context)) { - return R.style.DarkSettingsTheme; - } else { - return R.style.LightSettingsTheme; - } - } else if (selectedTheme.equals(deviceBlackTheme)) { - if (isDeviceDarkThemeEnabled(context)) { - return R.style.BlackSettingsTheme; - } else { - return R.style.LightSettingsTheme; - } + return shouldFollowDeviceTheme(context) && !isDeviceDarkThemeEnabled(context) + ? R.style.LightSettingsTheme : R.style.DarkSettingsTheme; } else { // Fallback return R.style.DarkSettingsTheme; @@ -297,8 +273,8 @@ public final class ThemeHelper { * @param context the context to use * @return true:dark theme, false:light or unknown */ - private static boolean isDeviceDarkThemeEnabled(final Context context) { - int deviceTheme = context.getResources().getConfiguration().uiMode + public static boolean isDeviceDarkThemeEnabled(final Context context) { + final int deviceTheme = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; switch (deviceTheme) { case Configuration.UI_MODE_NIGHT_YES: @@ -310,4 +286,15 @@ public final class ThemeHelper { return false; } } + + /** + * Tells if the user wants the theme to follow the device theme. + * + * @param context the context to use + * @return whether the user wants the theme to follow the device's theme + */ + public static boolean shouldFollowDeviceTheme(final Context context) { + return PreferenceManager.getDefaultSharedPreferences(context) + .getBoolean(context.getString(R.string.use_device_theme_key), false); + } } diff --git a/app/src/main/res/values-eo/strings.xml b/app/src/main/res/values-eo/strings.xml index cb190ea91..4245700cd 100644 --- a/app/src/main/res/values-eo/strings.xml +++ b/app/src/main/res/values-eo/strings.xml @@ -24,8 +24,6 @@ Malluma Luma Nigra - Etoson (Malluma) - Etoson de la aparato (Nigra) Elŝuti Ligilo ne subtenita Preferata enhavlingvo @@ -581,4 +579,6 @@ Artistoj Albumoj Kantoj + Sekvi la etoson de la aparato + La apo sekvos la etoson de la aparato. Ĝi povus malfunkcii se via Android versiono malsupras Android 10. \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index a538c2721..8525538ab 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -44,8 +44,6 @@ Sombre Clair Noir - Thème de l\'appareil (Sombre) - Thème de l\'appareil (Noir) Apparence Erreur réseau Dossier de téléchargement audio @@ -671,4 +669,6 @@ Ce contenu n\'est disponible que pour les abonnés, il ne peut donc pas être diffusé en continu ni téléchargé par NewPipe. Cette vidéo n\'est disponible que pour les membres de YouTube Music Premium, elle ne peut donc pas être diffusée en continu ni téléchargée par NewPipe. Ce contenu est privé, il ne peut donc pas être diffusé en continu ni téléchargé par NewPipe. + Suivre le thème de l\'appareil + L\'application suivera le thème de votre appareil. Il se peut que ça ne marche pas si vous utiliser une version d\'Android inférieure à 10. \ No newline at end of file diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 195e43e61..42cf4cd60 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -179,23 +179,18 @@ light_theme dark_theme black_theme - device_dark_theme - device_black_theme @string/dark_theme_key @string/light_theme_key @string/dark_theme_key @string/black_theme_key - @string/device_dark_theme_key - @string/device_black_theme_key @string/light_theme_title @string/dark_theme_title @string/black_theme_title - @string/device_dark_theme_title - @string/device_black_theme_title + use_device_theme_key caption_settings_key diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4bb21c0cf..4e45b57f2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -711,4 +711,6 @@ This content is only available to users who have paid, so it cannot be streamed or downloaded by NewPipe. Featured Radio + Follow device theme + The app theme will follow your device theme. It may not work for devices below Android 10. diff --git a/app/src/main/res/xml/appearance_settings.xml b/app/src/main/res/xml/appearance_settings.xml index 7f30d2091..c3363b865 100644 --- a/app/src/main/res/xml/appearance_settings.xml +++ b/app/src/main/res/xml/appearance_settings.xml @@ -12,6 +12,13 @@ android:title="@string/theme_title" app:iconSpaceReserved="false" /> + +