Better handle status bar light/dark icons based on banner background color

(cherry picked from commit 4992f87cb185cfac90aa86f4c4aeb2d0a0385c18)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
This commit is contained in:
arkon 2022-12-14 22:54:34 -05:00 committed by Jobobby04
parent d6a4f1ea14
commit dd367f2f70
2 changed files with 20 additions and 9 deletions

View File

@ -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),

View File

@ -27,6 +27,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.unit.dp
import androidx.core.animation.doOnEnd
@ -49,6 +50,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.more.settings.screen.ConfigureExhDialog
import eu.kanade.presentation.more.settings.screen.WhatsNewDialog
import eu.kanade.presentation.util.AssistContentScreen
@ -184,22 +187,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 },
)
}
@ -255,7 +261,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