Follow system theme on Android 10+.

This commit is contained in:
Greyson Parrelli
2020-02-13 13:09:54 -05:00
parent 2e19d0459b
commit 4e7a92637c
13 changed files with 107 additions and 50 deletions

View File

@@ -7,6 +7,7 @@ import androidx.preference.ListPreference;
import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.DynamicTheme;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import java.util.Arrays;

View File

@@ -1,18 +1,16 @@
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import androidx.annotation.StyleRes;
import org.thoughtcrime.securesms.R;
public class DynamicDarkActionBarTheme extends DynamicTheme {
@Override
protected int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("dark")) {
return R.style.TextSecure_DarkTheme_Conversation;
}
protected @StyleRes int getLightThemeStyle() {
return R.style.TextSecure_LightTheme_Conversation;
}
protected @StyleRes int getDarkThemeStyle() {
return R.style.TextSecure_DarkTheme_Conversation;
}
}

View File

@@ -1,18 +1,16 @@
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import androidx.annotation.StyleRes;
import org.thoughtcrime.securesms.R;
public class DynamicDarkToolbarTheme extends DynamicTheme {
@Override
protected int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("dark")) {
return R.style.TextSecure_DarkNoActionBar_DarkToolbar;
}
protected @StyleRes int getLightThemeStyle() {
return R.style.TextSecure_LightNoActionBar_DarkToolbar;
}
protected @StyleRes int getDarkThemeStyle() {
return R.style.TextSecure_DarkNoActionBar_DarkToolbar;
}
}

View File

@@ -1,16 +1,16 @@
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import androidx.annotation.StyleRes;
import org.thoughtcrime.securesms.R;
public class DynamicIntroTheme extends DynamicTheme {
@Override
protected int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("dark")) return R.style.TextSecure_DarkIntroTheme;
protected @StyleRes int getLightThemeStyle() {
return R.style.TextSecure_LightIntroTheme;
}
protected @StyleRes int getDarkThemeStyle() {
return R.style.TextSecure_DarkIntroTheme;
}
}

View File

@@ -1,16 +1,16 @@
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import androidx.annotation.StyleRes;
import org.thoughtcrime.securesms.R;
public class DynamicNoActionBarInviteTheme extends DynamicTheme {
@Override
protected int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("dark")) return R.style.Signal_NoActionBar_Invite;
protected @StyleRes int getLightThemeStyle() {
return R.style.Signal_Light_NoActionBar_Invite;
}
protected @StyleRes int getDarkThemeStyle() {
return R.style.Signal_NoActionBar_Invite;
}
}

View File

@@ -1,16 +1,16 @@
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 = TextSecurePreferences.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;
}
}

View File

@@ -1,16 +1,16 @@
package org.thoughtcrime.securesms.util;
import android.app.Activity;
import androidx.annotation.StyleRes;
import org.thoughtcrime.securesms.R;
public class DynamicRegistrationTheme extends DynamicTheme {
@Override
protected int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals("dark")) return R.style.TextSecure_DarkRegistrationTheme;
protected @StyleRes int getLightThemeStyle() {
return R.style.TextSecure_LightRegistrationTheme;
}
protected @StyleRes int getDarkThemeStyle() {
return R.style.TextSecure_DarkRegistrationTheme;
}
}

View File

@@ -3,15 +3,19 @@ package org.thoughtcrime.securesms.util;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.StyleRes;
import androidx.appcompat.app.AppCompatDelegate;
import org.thoughtcrime.securesms.R;
public class DynamicTheme {
public static final String DARK = "dark";
public static final String LIGHT = "light";
public static final String DARK = "dark";
public static final String LIGHT = "light";
public static final String SYSTEM = "system";
private int currentTheme;
@@ -30,16 +34,38 @@ public class DynamicTheme {
}
}
protected int getSelectedTheme(Activity activity) {
private @StyleRes int getSelectedTheme(Activity activity) {
String theme = TextSecurePreferences.getTheme(activity);
if (theme.equals(DARK)) {
return R.style.TextSecure_DarkTheme;
if (theme.equals(SYSTEM) && systemThemeAvailable()) {
if (isSystemInDarkTheme(activity)) {
return getDarkThemeStyle();
} else {
return getLightThemeStyle();
}
} else if (theme.equals(DARK)) {
return getDarkThemeStyle();
} else {
return getLightThemeStyle();
}
}
protected @StyleRes int getLightThemeStyle() {
return R.style.TextSecure_LightTheme;
}
protected @StyleRes int getDarkThemeStyle() {
return R.style.TextSecure_DarkTheme;
}
public static boolean systemThemeAvailable() {
return Build.VERSION.SDK_INT >= 29;
}
private static boolean isSystemInDarkTheme(@NonNull Activity activity) {
return (activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
}
private static final class OverridePendingTransition {
static void invoke(Activity activity) {
activity.overridePendingTransition(0, 0);

View File

@@ -886,7 +886,7 @@ public class TextSecurePreferences {
}
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 isVerifying(Context context) {