Merge pull request #3403 from ByteHamster/follow-system-theme

Add option to follow system theme
This commit is contained in:
H. Lehmann 2019-09-20 23:47:31 +02:00 committed by GitHub
commit c5dba814d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -157,11 +157,14 @@
</string-array>
<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_dark</item>
<item>@string/pref_theme_title_trueblack</item>
</string-array>
<string-array name="theme_values">
<item>system</item>
<item>0</item>
<item>1</item>
<item>2</item>

View File

@ -398,6 +398,7 @@
<string name="pref_parallel_downloads_title">Parallel Downloads</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_theme_title_use_system">Use system theme</string>
<string name="pref_theme_title_light">Light</string>
<string name="pref_theme_title_dark">Dark</string>
<string name="pref_theme_title_trueblack">Black (AMOLED ready)</string>