Add option to follow system theme

This commit is contained in:
ByteHamster 2019-09-10 23:36:43 +02:00
parent 037c4d3922
commit c4c1780da4
5 changed files with 22 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import de.danoeh.antennapod.BuildConfig; import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
import de.danoeh.antennapod.core.util.gui.NotificationUtils; import de.danoeh.antennapod.core.util.gui.NotificationUtils;
@ -64,5 +65,11 @@ public class PreferenceUpgrader {
break; break;
} }
} }
if (oldVersion < 1070400) {
int theme = UserPreferences.getTheme();
if (theme == R.style.Theme_AntennaPod_Light) {
prefs.edit().putString(UserPreferences.PREF_THEME, "system").apply();
}
}
} }
} }

View File

@ -10,7 +10,7 @@
android:title="@string/pref_set_theme_title" android:title="@string/pref_set_theme_title"
android:key="prefTheme" android:key="prefTheme"
android:summary="@string/pref_set_theme_sum" android:summary="@string/pref_set_theme_sum"
android:defaultValue="0" android:defaultValue="system"
app:useStockLayout="true"/> app:useStockLayout="true"/>
<Preference <Preference
android:key="prefHiddenDrawerItems" android:key="prefHiddenDrawerItems"

View File

@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.preferences;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.annotation.IntRange; import android.support.annotation.IntRange;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -164,7 +165,7 @@ public class UserPreferences {
* @return R.style.Theme_AntennaPod_Light or R.style.Theme_AntennaPod_Dark * @return R.style.Theme_AntennaPod_Light or R.style.Theme_AntennaPod_Dark
*/ */
public static int getTheme() { public static int getTheme() {
return readThemeValue(prefs.getString(PREF_THEME, "0")); return readThemeValue(prefs.getString(PREF_THEME, "system"));
} }
public static int getNoTitleTheme() { public static int getNoTitleTheme() {
@ -672,14 +673,18 @@ public class UserPreferences {
} }
private static int readThemeValue(String valueFromPrefs) { private static int readThemeValue(String valueFromPrefs) {
switch (Integer.parseInt(valueFromPrefs)) { switch (valueFromPrefs) {
case 0: case "0":
return R.style.Theme_AntennaPod_Light; return R.style.Theme_AntennaPod_Light;
case 1: case "1":
return R.style.Theme_AntennaPod_Dark; return R.style.Theme_AntennaPod_Dark;
case 2: case "2":
return R.style.Theme_AntennaPod_TrueBlack; return R.style.Theme_AntennaPod_TrueBlack;
default: default:
int nightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
if (nightMode == Configuration.UI_MODE_NIGHT_YES) {
return R.style.Theme_AntennaPod_Dark;
}
return R.style.Theme_AntennaPod_Light; return R.style.Theme_AntennaPod_Light;
} }
} }

View File

@ -164,11 +164,14 @@
</string-array> </string-array>
<string-array name="theme_options"> <string-array name="theme_options">
<item>@string/pref_theme_title_use_system</item>
<item>@string/pref_theme_title_light</item> <item>@string/pref_theme_title_light</item>
<item>@string/pref_theme_title_dark</item> <item>@string/pref_theme_title_dark</item>
<item>@string/pref_theme_title_trueblack</item> <item>@string/pref_theme_title_trueblack</item>
</string-array> </string-array>
<string-array name="theme_values"> <string-array name="theme_values">
<item>system</item>
<item>0</item> <item>0</item>
<item>1</item> <item>1</item>
<item>2</item> <item>2</item>

View File

@ -424,6 +424,7 @@
<string name="pref_parallel_downloads_title">Parallel Downloads</string> <string name="pref_parallel_downloads_title">Parallel Downloads</string>
<string name="pref_episode_cache_title">Episode Cache</string> <string name="pref_episode_cache_title">Episode Cache</string>
<string name="pref_episode_cache_summary">Total number of downloaded episodes cached on the device. Automatic download will be suspended if this number is reached.</string> <string name="pref_episode_cache_summary">Total number of downloaded episodes cached on the device. Automatic download will be suspended if this number is reached.</string>
<string name="pref_theme_title_use_system">Use system theme</string>
<string name="pref_theme_title_light">Light</string> <string name="pref_theme_title_light">Light</string>
<string name="pref_theme_title_dark">Dark</string> <string name="pref_theme_title_dark">Dark</string>
<string name="pref_theme_title_trueblack">Black (AMOLED ready)</string> <string name="pref_theme_title_trueblack">Black (AMOLED ready)</string>