From 0d686e49883f42f3239b914c17d95c3c39dcf617 Mon Sep 17 00:00:00 2001 From: Brayan Oliveira <69634269+BrayanDSO@users.noreply.github.com> Date: Tue, 28 Jun 2022 17:52:11 -0300 Subject: [PATCH] Update theme in case system dark mode was changed on another activity onConfigurationChanged is only called on the current activity, so opened activities on the backstack wouldn't get updated --- .../src/main/java/com/ichi2/anki/AnkiActivity.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.java b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.java index d6238aa0fdf1..dad60d47d6e3 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.java +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.java @@ -52,6 +52,7 @@ import com.ichi2.compat.customtabs.CustomTabsHelper; import com.ichi2.libanki.Collection; import com.ichi2.libanki.CollectionGetter; +import com.ichi2.themes.Theme; import com.ichi2.themes.Themes; import com.ichi2.utils.AdaptionUtil; import com.ichi2.utils.AndroidUiUtils; @@ -66,7 +67,6 @@ import static com.ichi2.anim.ActivityTransitionAnimation.Direction.*; import static com.ichi2.anim.ActivityTransitionAnimation.Direction; import static com.ichi2.anki.Preferences.MINIMUM_CARDS_DUE_FOR_NOTIFICATION; -import static com.ichi2.themes.Themes.currentTheme; public class AnkiActivity extends AppCompatActivity implements SimpleMessageDialog.SimpleMessageDialogListener, CollectionGetter { @@ -81,6 +81,8 @@ public class AnkiActivity extends AppCompatActivity implements SimpleMessageDial private final DialogHandler mHandler = new DialogHandler(this); + private Theme mPreviousTheme = null; + // custom tabs private CustomTabActivityHelper mCustomTabActivityHelper; @@ -103,6 +105,7 @@ protected void onCreate(Bundle savedInstanceState) { // Set the theme Themes.setTheme(this); Themes.disableXiaomiForceDarkMode(this); + mPreviousTheme = Themes.currentTheme; super.onCreate(savedInstanceState); // Disable the notifications bar if running under the test monkey. if (AdaptionUtil.isUserATestClient()) { @@ -121,6 +124,10 @@ protected void onStart() { Timber.i("AnkiActivity::onStart - %s", mActivityName); super.onStart(); mCustomTabActivityHelper.bindCustomTabsService(this); + // Reload theme in case it was changed on another activity + if (mPreviousTheme != Themes.currentTheme) { + recreate(); + } } @Override @@ -486,7 +493,7 @@ public void openUrl(@NonNull Uri url) { private int getColorScheme() { if (AppCompatDelegate.getDefaultNightMode() == AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) { return COLOR_SCHEME_SYSTEM; - } else if (currentTheme.isNightMode()) { + } else if (Themes.currentTheme.isNightMode()) { return COLOR_SCHEME_DARK; } else { return COLOR_SCHEME_LIGHT;