Commit dbce9b8c authored by Pavel Shmakov's avatar Pavel Shmakov Committed by Commit Bot

Fix CCT night mode initial state

This fixes an error due to which AppCompatDelegate.setLocalNightMode
wasn't always triggered on CCT startup

Bug: 1012755
Change-Id: I5dce526db679ba36b667f6330bd94c577aef02a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857318
Commit-Queue: Pavel Shmakov <pshmakov@chromium.org>
Commit-Queue: Theresa  <twellington@chromium.org>
Auto-Submit: Pavel Shmakov <pshmakov@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705289}
parent bcfeb5b2
......@@ -8,6 +8,7 @@ import android.content.Intent;
import android.support.v7.app.AppCompatDelegate;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.browser.customtabs.CustomTabsIntent;
import org.chromium.base.ObserverList;
......@@ -38,7 +39,8 @@ public class CustomTabNightModeStateController implements Destroyable, NightMode
private int mRequestedColorScheme;
private AppCompatDelegate mAppCompatDelegate;
private boolean mIsInNightMode;
@Nullable // Null initially, so that the first update is always applied (see updateNightMode()).
private Boolean mIsInNightMode;
CustomTabNightModeStateController(ActivityLifecycleDispatcher lifecycleDispatcher,
SystemNightModeMonitor systemNightModeMonitor,
......@@ -85,8 +87,7 @@ public class CustomTabNightModeStateController implements Destroyable, NightMode
// NightModeStateProvider implementation.
@Override
public boolean isInNightMode() {
return mIsInNightMode;
return mIsInNightMode != null && mIsInNightMode;
}
@Override
......@@ -108,7 +109,7 @@ public class CustomTabNightModeStateController implements Destroyable, NightMode
private void updateNightMode() {
boolean shouldBeInNightMode = shouldBeInNightMode();
if (mIsInNightMode == shouldBeInNightMode) return;
if (mIsInNightMode != null && mIsInNightMode == shouldBeInNightMode) return;
mIsInNightMode = shouldBeInNightMode;
mAppCompatDelegate.setLocalNightMode(mIsInNightMode ? AppCompatDelegate.MODE_NIGHT_YES
......
......@@ -76,6 +76,20 @@ public class CustomTabNightModeStateControllerTest {
FeatureUtilities.setNightModeForCustomTabsAvailableForTesting(false);
}
@Test
public void triggersAppCompatDelegate_WhenInitialSchemeIsLight() {
setSystemNightMode(false);
initializeWithColorScheme(COLOR_SCHEME_SYSTEM);
verify(mAppCompatDelegate).setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
@Test
public void triggersAppCompatDelegate_WhenInitialSchemeIsDark() {
setSystemNightMode(true);
initializeWithColorScheme(COLOR_SCHEME_SYSTEM);
verify(mAppCompatDelegate).setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
@Test
public void nightModeIfOff_WhenSchemeForced() {
initializeWithColorScheme(COLOR_SCHEME_LIGHT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment