~singpolyma/cheogram-android

581eb5556fc7f7017f841efd253885e0a4b5f2df — Daniel Gultsch 4 years ago e38a9cd
make theme depend on dark/night mode on android 10+

closes #3611
M build.gradle => build.gradle +1 -1
@@ 85,7 85,7 @@ ext {
}

android {
    compileSdkVersion 28
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 16

M src/main/java/eu/siacs/conversations/utils/ThemeHelper.java => src/main/java/eu/siacs/conversations/utils/ThemeHelper.java +14 -3
@@ 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:

A src/main/res/values-v29/theme-settings.xml => src/main/res/values-v29/theme-settings.xml +16 -0
@@ 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>

M src/main/res/values/arrays.xml => src/main/res/values/arrays.xml +0 -8
@@ 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>

M src/main/res/values/defaults.xml => src/main/res/values/defaults.xml +0 -1
@@ 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>

M src/main/res/values/strings.xml => src/main/res/values/strings.xml +1 -0
@@ 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>

A src/main/res/values/theme-settings.xml => src/main/res/values/theme-settings.xml +14 -0
@@ 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>