From 4992f87cb185cfac90aa86f4c4aeb2d0a0385c18 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 14 Dec 2022 22:54:34 -0500 Subject: [PATCH] Better handle status bar light/dark icons based on banner background color --- .../kanade/presentation/components/Banners.kt | 9 +++++++-- .../kanade/tachiyomi/ui/main/MainActivity.kt | 20 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/components/Banners.kt b/app/src/main/java/eu/kanade/presentation/components/Banners.kt index d455b943d5..465e3ad5a4 100644 --- a/app/src/main/java/eu/kanade/presentation/components/Banners.kt +++ b/app/src/main/java/eu/kanade/presentation/components/Banners.kt @@ -19,6 +19,11 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import eu.kanade.tachiyomi.R +val DownloadedOnlyBannerBackgroundColor + @Composable get() = MaterialTheme.colorScheme.tertiary +val IncognitoModeBannerBackgroundColor + @Composable get() = MaterialTheme.colorScheme.primary + @Composable fun WarningBanner( @StringRes textRes: Int, @@ -66,7 +71,7 @@ private fun DownloadedOnlyModeBanner(modifier: Modifier = Modifier) { Text( text = stringResource(R.string.label_downloaded_only), modifier = Modifier - .background(color = MaterialTheme.colorScheme.tertiary) + .background(DownloadedOnlyBannerBackgroundColor) .fillMaxWidth() .padding(4.dp) .then(modifier), @@ -81,7 +86,7 @@ private fun IncognitoModeBanner(modifier: Modifier = Modifier) { Text( text = stringResource(R.string.pref_incognito_mode), modifier = Modifier - .background(color = MaterialTheme.colorScheme.primary) + .background(IncognitoModeBannerBackgroundColor) .fillMaxWidth() .padding(4.dp) .then(modifier), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index b17297d086..3323ce4e8b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -29,6 +29,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.luminance import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -51,6 +52,8 @@ import eu.kanade.domain.library.service.LibraryPreferences import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.ui.UiPreferences import eu.kanade.presentation.components.AppStateBanners +import eu.kanade.presentation.components.DownloadedOnlyBannerBackgroundColor +import eu.kanade.presentation.components.IncognitoModeBannerBackgroundColor import eu.kanade.presentation.util.AssistContentScreen import eu.kanade.presentation.util.DefaultNavigatorScreenTransition import eu.kanade.presentation.util.collectAsState @@ -149,22 +152,25 @@ class MainActivity : BaseActivity() { setComposeContent { val incognito by preferences.incognitoMode().collectAsState() - val download by preferences.downloadedOnly().collectAsState() + val downloadOnly by preferences.downloadedOnly().collectAsState() Column { AppStateBanners( - downloadedOnlyMode = download, + downloadedOnlyMode = downloadOnly, incognitoMode = incognito, ) // Set statusbar color val systemUiController = rememberSystemUiController() val isSystemInDarkTheme = isSystemInDarkTheme() - val active = incognito || download - val useDarkStatusBarIcons = if (isSystemInDarkTheme) active else !active - LaunchedEffect(systemUiController, useDarkStatusBarIcons) { + val statusBarBackgroundColor = when { + downloadOnly -> DownloadedOnlyBannerBackgroundColor + incognito -> IncognitoModeBannerBackgroundColor + else -> MaterialTheme.colorScheme.background + } + LaunchedEffect(systemUiController, statusBarBackgroundColor) { systemUiController.setStatusBarColor( color = ComposeColor.Transparent, - darkIcons = useDarkStatusBarIcons, + darkIcons = statusBarBackgroundColor.luminance() > 0.5, transformColorForLightContent = { ComposeColor.Black }, ) } @@ -206,7 +212,7 @@ class MainActivity : BaseActivity() { } // Consume insets already used by app state banners - val boxModifier = if (incognito || download) { + val boxModifier = if (incognito || downloadOnly) { Modifier.consumeWindowInsets(WindowInsets.statusBars) } else { Modifier