parent
e38a9cd729
commit
581eb5556f
|
@ -85,7 +85,7 @@ ext {
|
|||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
compileSdkVersion 29
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 16
|
||||
|
|
|
@ -31,8 +31,10 @@ package eu.siacs.conversations.utils;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.StyleRes;
|
||||
import android.support.design.widget.Snackbar;
|
||||
|
@ -45,10 +47,10 @@ import eu.siacs.conversations.ui.SettingsActivity;
|
|||
|
||||
public class ThemeHelper {
|
||||
|
||||
public static int find(Context context) {
|
||||
public static int find(final Context context) {
|
||||
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final Resources resources = context.getResources();
|
||||
final boolean dark = sharedPreferences.getString(SettingsActivity.THEME, resources.getString(R.string.theme)).equals("dark");
|
||||
final boolean dark = isDark(sharedPreferences, resources);
|
||||
final String fontSize = sharedPreferences.getString("font_size", resources.getString(R.string.default_font_size));
|
||||
switch (fontSize) {
|
||||
case "medium":
|
||||
|
@ -63,7 +65,7 @@ public class ThemeHelper {
|
|||
public static int findDialog(Context context) {
|
||||
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
final Resources resources = context.getResources();
|
||||
final boolean dark = sharedPreferences.getString(SettingsActivity.THEME, resources.getString(R.string.theme)).equals("dark");
|
||||
final boolean dark = isDark(sharedPreferences, resources);
|
||||
final String fontSize = sharedPreferences.getString("font_size", resources.getString(R.string.default_font_size));
|
||||
switch (fontSize) {
|
||||
case "medium":
|
||||
|
@ -75,6 +77,15 @@ public class ThemeHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean isDark(final SharedPreferences sharedPreferences, final Resources resources) {
|
||||
final String setting = sharedPreferences.getString(SettingsActivity.THEME, resources.getString(R.string.theme));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && "automatic".equals(setting)) {
|
||||
return (resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
} else {
|
||||
return "dark".equals(setting);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDark(@StyleRes int id) {
|
||||
switch (id) {
|
||||
case R.style.ConversationsTheme_Dark:
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<string name="theme">automatic</string>
|
||||
<string-array name="themes" tools:ignore="InconsistentArrays">
|
||||
<item>@string/pref_theme_automatic</item>
|
||||
<item>@string/pref_theme_light</item>
|
||||
<item>@string/pref_theme_dark</item>
|
||||
</string-array>
|
||||
<string-array name="themes_values" tools:ignore="InconsistentArrays">
|
||||
<item>automatic</item>
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -1,14 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string-array name="themes">
|
||||
<item>@string/pref_theme_light</item>
|
||||
<item>@string/pref_theme_dark</item>
|
||||
</string-array>
|
||||
<string-array name="themes_values">
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
</string-array>
|
||||
<string-array name="filesizes">
|
||||
<item>@string/never</item>
|
||||
<item>256 KiB</item>
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
<integer name="grace_period">144</integer>
|
||||
<integer name="auto_accept_filesize">524288</integer>
|
||||
<string name="picture_compression">auto</string>
|
||||
<string name="theme">light</string>
|
||||
<bool name="use_green_background">true</bool>
|
||||
<string name="quick_action">recent</string>
|
||||
<bool name="show_dynamic_tags">false</bool>
|
||||
|
|
|
@ -559,6 +559,7 @@
|
|||
<string name="pref_privacy">Privacy</string>
|
||||
<string name="pref_theme_options">Theme</string>
|
||||
<string name="pref_theme_options_summary">Select the color palette</string>
|
||||
<string name="pref_theme_automatic">Automatic</string>
|
||||
<string name="pref_theme_light">Light theme</string>
|
||||
<string name="pref_theme_dark">Dark theme</string>
|
||||
<string name="pref_use_green_background">Green Background</string>
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="theme">light</string>
|
||||
<string-array name="themes">
|
||||
<item>@string/pref_theme_light</item>
|
||||
<item>@string/pref_theme_dark</item>
|
||||
</string-array>
|
||||
<string-array name="themes_values">
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue