Add system theme option

This commit is contained in:
Shinokuni 2021-10-12 22:49:50 +02:00
parent 6f7e2b7cef
commit 2f56f388e1
6 changed files with 23 additions and 13 deletions

View File

@ -31,10 +31,13 @@ open class ReadropsApp : Application() {
modules(apiModule, dbModule, appModule) modules(apiModule, dbModule, appModule)
} }
if (SharedPreferencesManager.readString(SharedPreferencesManager.SharedPrefKey.DARK_THEME).toBoolean()) val theme = when (SharedPreferencesManager.readString(SharedPreferencesManager.SharedPrefKey.DARK_THEME)) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) getString(R.string.theme_value_light) -> AppCompatDelegate.MODE_NIGHT_NO
else getString(R.string.theme_value_dark) -> AppCompatDelegate.MODE_NIGHT_YES
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO) else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
AppCompatDelegate.setDefaultNightMode(theme)
} }
private fun createNotificationChannels() { private fun createNotificationChannels() {

View File

@ -1,5 +1,7 @@
package com.readrops.app.settings; package com.readrops.app.settings;
import static com.readrops.app.utils.ReadropsKeys.FEEDS;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Pair; import android.util.Pair;
@ -25,8 +27,6 @@ import java.util.ArrayList;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static com.readrops.app.utils.ReadropsKeys.FEEDS;
public class SettingsFragment extends PreferenceFragmentCompat { public class SettingsFragment extends PreferenceFragmentCompat {
@Override @Override
@ -56,12 +56,12 @@ public class SettingsFragment extends PreferenceFragmentCompat {
}); });
themePreference.setOnPreferenceChangeListener((preference, newValue) -> { themePreference.setOnPreferenceChangeListener((preference, newValue) -> {
boolean darkTheme = Boolean.parseBoolean(newValue.toString()); if (newValue.equals(getString(R.string.theme_value_light))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
if (darkTheme) { } else if (newValue.equals(getString(R.string.theme_value_dark))) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else { } else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} }
return true; return true;

View File

@ -137,5 +137,6 @@
<string name="source_code">Code source</string> <string name="source_code">Code source</string>
<string name="changelog">Journal des modifications</string> <string name="changelog">Journal des modifications</string>
<string name="app_description">App distribuée sous la licence GPLv3</string> <string name="app_description">App distribuée sous la licence GPLv3</string>
<string name="system">Thème du système</string>
</resources> </resources>

View File

@ -45,11 +45,13 @@
<string-array name="themes"> <string-array name="themes">
<item>@string/light</item> <item>@string/light</item>
<item>@string/dark</item> <item>@string/dark</item>
<item>@string/system</item>
</string-array> </string-array>
<string-array name="themes_values"> <string-array name="themes_values">
<item>false</item> <item>@string/theme_value_light</item>
<item>true</item> <item>@string/theme_value_dark</item>
<item>@string/theme_value_system</item>
</string-array> </string-array>
<string-array name="synchro"> <string-array name="synchro">

View File

@ -140,4 +140,8 @@
<string name="source_code">Source code</string> <string name="source_code">Source code</string>
<string name="changelog">Changelog</string> <string name="changelog">Changelog</string>
<string name="changelog_url" translatable="false">https://github.com/readrops/Readrops/blob/develop/CHANGELOG.md</string> <string name="changelog_url" translatable="false">https://github.com/readrops/Readrops/blob/develop/CHANGELOG.md</string>
<string name="system">System theme</string>
<string name="theme_value_light" translatable="false">light</string>
<string name="theme_value_dark" translatable="false">dark</string>
<string name="theme_value_system" translatable="false">system</string>
</resources> </resources>

View File

@ -23,7 +23,7 @@
android:title="@string/open_items_in" /> android:title="@string/open_items_in" />
<ListPreference <ListPreference
android:defaultValue="false" android:defaultValue="system"
android:entries="@array/themes" android:entries="@array/themes"
android:entryValues="@array/themes_values" android:entryValues="@array/themes_values"
android:key="dark_theme" android:key="dark_theme"