mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-03 09:49:21 +02:00
Dark theme / DayNight: Add option to follow system
fix maybe #1748. Maybe not, because actually I don't understand why issue #1748 even happened because we don't use the system background for the bubble but an own one (see conversation_item_sent.xml:50). Probably the system is somehow trying to forcefully create a dark mode. So, let's see whether this PR fixes the issue, if not, I'll try again.
This commit is contained in:
parent
cfea049418
commit
1ff6a3a18d
7 changed files with 115 additions and 19 deletions
16
res/values-v29/arrays.xml
Normal file
16
res/values-v29/arrays.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<string-array name="pref_theme_entries" tools:ignore="InconsistentArrays">
|
||||
<item>@string/pref_system_default</item>
|
||||
<item>@string/pref_light_theme</item>
|
||||
<item>@string/pref_dark_theme</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_theme_values" translatable="false" tools:ignore="InconsistentArrays">
|
||||
<item>system</item>
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<!-- take care, language_entries and languages_values are in sync ...
|
||||
... some one has to clean up this mess some day ... -->
|
||||
|
@ -84,12 +84,12 @@
|
|||
<item>te</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_theme_entries">
|
||||
<string-array name="pref_theme_entries" tools:ignore="InconsistentArrays">
|
||||
<item>@string/pref_light_theme</item>
|
||||
<item>@string/pref_dark_theme</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_theme_values" translatable="false">
|
||||
<string-array name="pref_theme_values" translatable="false" tools:ignore="InconsistentArrays">
|
||||
<item>light</item>
|
||||
<item>dark</item>
|
||||
</string-array>
|
||||
|
|
|
@ -457,6 +457,7 @@
|
|||
<string name="pref_silent">Silent</string>
|
||||
<string name="pref_privacy">Privacy</string>
|
||||
<string name="pref_chats_and_media">Chats and media</string>
|
||||
<string name="pref_system_default">System default</string>
|
||||
<!-- Translators: "light" in the meaning "opposite of dark" -->
|
||||
<string name="pref_light_theme">Light</string>
|
||||
<string name="pref_dark_theme">Dark</string>
|
||||
|
|
36
res/xml-v29/preferences_appearance.xml
Normal file
36
res/xml-v29/preferences_appearance.xml
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<ListPreference
|
||||
android:key="pref_theme"
|
||||
android:title="@string/pref_theme"
|
||||
android:entries="@array/pref_theme_entries"
|
||||
android:entryValues="@array/pref_theme_values"
|
||||
android:defaultValue="system"/>
|
||||
|
||||
<Preference
|
||||
android:key="pref_chat_background"
|
||||
android:title="@string/pref_background"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="pref_message_body_text_size"
|
||||
android:title="@string/pref_message_text_size"
|
||||
android:entries="@array/pref_message_font_size_entries"
|
||||
android:entryValues="@array/pref_message_font_size_values"
|
||||
android:defaultValue="16"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
|
||||
android:defaultValue="false"
|
||||
android:key="pref_system_emoji"
|
||||
android:title="@string/pref_use_system_emoji"
|
||||
android:summary="@string/pref_use_system_emoji_explain" />
|
||||
|
||||
<ListPreference
|
||||
android:key="pref_language"
|
||||
android:title="@string/pref_language"
|
||||
android:entries="@array/language_entries"
|
||||
android:entryValues="@array/language_values"
|
||||
android:defaultValue="zz"/>
|
||||
|
||||
</PreferenceScreen>
|
|
@ -1,16 +1,15 @@
|
|||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
public class DynamicNoActionBarTheme extends DynamicTheme {
|
||||
@Override
|
||||
protected int getSelectedTheme(Activity activity) {
|
||||
String theme = Prefs.getTheme(activity);
|
||||
|
||||
if (theme.equals("dark")) return R.style.TextSecure_DarkNoActionBar;
|
||||
|
||||
protected @StyleRes int getLightThemeStyle() {
|
||||
return R.style.TextSecure_LightNoActionBar;
|
||||
}
|
||||
|
||||
protected @StyleRes int getDarkThemeStyle() {
|
||||
return R.style.TextSecure_DarkNoActionBar;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,11 @@ package org.thoughtcrime.securesms.util;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
|
@ -10,12 +15,25 @@ public class DynamicTheme {
|
|||
|
||||
public static final String DARK = "dark";
|
||||
public static final String LIGHT = "light";
|
||||
public static final String SYSTEM = "system";
|
||||
|
||||
//private static boolean isDarkTheme;
|
||||
|
||||
private int currentTheme;
|
||||
|
||||
public void onCreate(Activity activity) {
|
||||
//boolean wasDarkTheme = isDarkTheme;
|
||||
|
||||
currentTheme = getSelectedTheme(activity);
|
||||
//isDarkTheme = isDarkTheme(activity);
|
||||
|
||||
activity.setTheme(currentTheme);
|
||||
|
||||
// In case you introduce a CachedInflater and there are problems with the dark mode, uncomment
|
||||
// this line and the line in onResume():
|
||||
//if (isDarkTheme != wasDarkTheme) {
|
||||
//CachedInflater.from(activity).clear();
|
||||
//}
|
||||
}
|
||||
|
||||
public void onResume(Activity activity) {
|
||||
|
@ -25,19 +43,45 @@ public class DynamicTheme {
|
|||
OverridePendingTransition.invoke(activity);
|
||||
activity.startActivity(intent);
|
||||
OverridePendingTransition.invoke(activity);
|
||||
//CachedInflater.from(activity).clear();
|
||||
}
|
||||
}
|
||||
|
||||
protected int getSelectedTheme(Activity activity) {
|
||||
String theme = Prefs.getTheme(activity);
|
||||
|
||||
if (theme.equals(DARK)) return R.style.TextSecure_DarkTheme;
|
||||
private @StyleRes int getSelectedTheme(Activity activity) {
|
||||
if (isDarkTheme(activity)) {
|
||||
return getDarkThemeStyle();
|
||||
} else {
|
||||
return getLightThemeStyle();
|
||||
}
|
||||
}
|
||||
|
||||
protected @StyleRes int getLightThemeStyle() {
|
||||
return R.style.TextSecure_LightTheme;
|
||||
}
|
||||
|
||||
public static boolean isDarkTheme(Context context) {
|
||||
return Prefs.getTheme(context).equals(DARK);
|
||||
protected @StyleRes int getDarkThemeStyle() {
|
||||
return R.style.TextSecure_DarkTheme;
|
||||
}
|
||||
|
||||
static boolean systemThemeAvailable() {
|
||||
return Build.VERSION.SDK_INT >= 29;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the system theme into account.
|
||||
*/
|
||||
public static boolean isDarkTheme(@NonNull Context context) {
|
||||
String theme = Prefs.getTheme(context);
|
||||
|
||||
if (theme.equals(SYSTEM) && systemThemeAvailable()) {
|
||||
return isSystemInDarkTheme(context);
|
||||
} else {
|
||||
return theme.equals(DARK);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isSystemInDarkTheme(@NonNull Context context) {
|
||||
return (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
|
||||
}
|
||||
|
||||
private static final class OverridePendingTransition {
|
||||
|
|
|
@ -138,7 +138,7 @@ public class Prefs {
|
|||
}
|
||||
|
||||
public static String getTheme(Context context) {
|
||||
return getStringPreference(context, THEME_PREF, "light");
|
||||
return getStringPreference(context, THEME_PREF, DynamicTheme.systemThemeAvailable() ? DynamicTheme.SYSTEM : DynamicTheme.LIGHT);
|
||||
}
|
||||
|
||||
public static boolean isScreenLockTimeoutEnabled(Context context) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue