Skip to content

Commit

Permalink
Update theme in case system dark mode was changed on another activity
Browse files Browse the repository at this point in the history
onConfigurationChanged is only called on the current activity, so opened activities on the backstack wouldn't get updated
  • Loading branch information
BrayanDSO authored and mikehardy committed Jun 29, 2022
1 parent 63eccac commit 0d686e4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {

Expand All @@ -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;

Expand All @@ -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()) {
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0d686e4

Please sign in to comment.