mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-31 04:06:26 +00:00
Follow system theme on Android 10+.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user