Better handle status bar light/dark icons based on banner background color
This commit is contained in:
parent
7608cb0da3
commit
4992f87cb1
@ -19,6 +19,11 @@ import androidx.compose.ui.text.style.TextAlign
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
|
||||||
|
val DownloadedOnlyBannerBackgroundColor
|
||||||
|
@Composable get() = MaterialTheme.colorScheme.tertiary
|
||||||
|
val IncognitoModeBannerBackgroundColor
|
||||||
|
@Composable get() = MaterialTheme.colorScheme.primary
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun WarningBanner(
|
fun WarningBanner(
|
||||||
@StringRes textRes: Int,
|
@StringRes textRes: Int,
|
||||||
@ -66,7 +71,7 @@ private fun DownloadedOnlyModeBanner(modifier: Modifier = Modifier) {
|
|||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.label_downloaded_only),
|
text = stringResource(R.string.label_downloaded_only),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(color = MaterialTheme.colorScheme.tertiary)
|
.background(DownloadedOnlyBannerBackgroundColor)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.then(modifier),
|
.then(modifier),
|
||||||
@ -81,7 +86,7 @@ private fun IncognitoModeBanner(modifier: Modifier = Modifier) {
|
|||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.pref_incognito_mode),
|
text = stringResource(R.string.pref_incognito_mode),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(color = MaterialTheme.colorScheme.primary)
|
.background(IncognitoModeBannerBackgroundColor)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(4.dp)
|
.padding(4.dp)
|
||||||
.then(modifier),
|
.then(modifier),
|
||||||
|
@ -29,6 +29,7 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.luminance
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
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.source.service.SourcePreferences
|
||||||
import eu.kanade.domain.ui.UiPreferences
|
import eu.kanade.domain.ui.UiPreferences
|
||||||
import eu.kanade.presentation.components.AppStateBanners
|
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.AssistContentScreen
|
||||||
import eu.kanade.presentation.util.DefaultNavigatorScreenTransition
|
import eu.kanade.presentation.util.DefaultNavigatorScreenTransition
|
||||||
import eu.kanade.presentation.util.collectAsState
|
import eu.kanade.presentation.util.collectAsState
|
||||||
@ -149,22 +152,25 @@ class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
setComposeContent {
|
setComposeContent {
|
||||||
val incognito by preferences.incognitoMode().collectAsState()
|
val incognito by preferences.incognitoMode().collectAsState()
|
||||||
val download by preferences.downloadedOnly().collectAsState()
|
val downloadOnly by preferences.downloadedOnly().collectAsState()
|
||||||
Column {
|
Column {
|
||||||
AppStateBanners(
|
AppStateBanners(
|
||||||
downloadedOnlyMode = download,
|
downloadedOnlyMode = downloadOnly,
|
||||||
incognitoMode = incognito,
|
incognitoMode = incognito,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Set statusbar color
|
// Set statusbar color
|
||||||
val systemUiController = rememberSystemUiController()
|
val systemUiController = rememberSystemUiController()
|
||||||
val isSystemInDarkTheme = isSystemInDarkTheme()
|
val isSystemInDarkTheme = isSystemInDarkTheme()
|
||||||
val active = incognito || download
|
val statusBarBackgroundColor = when {
|
||||||
val useDarkStatusBarIcons = if (isSystemInDarkTheme) active else !active
|
downloadOnly -> DownloadedOnlyBannerBackgroundColor
|
||||||
LaunchedEffect(systemUiController, useDarkStatusBarIcons) {
|
incognito -> IncognitoModeBannerBackgroundColor
|
||||||
|
else -> MaterialTheme.colorScheme.background
|
||||||
|
}
|
||||||
|
LaunchedEffect(systemUiController, statusBarBackgroundColor) {
|
||||||
systemUiController.setStatusBarColor(
|
systemUiController.setStatusBarColor(
|
||||||
color = ComposeColor.Transparent,
|
color = ComposeColor.Transparent,
|
||||||
darkIcons = useDarkStatusBarIcons,
|
darkIcons = statusBarBackgroundColor.luminance() > 0.5,
|
||||||
transformColorForLightContent = { ComposeColor.Black },
|
transformColorForLightContent = { ComposeColor.Black },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -206,7 +212,7 @@ class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Consume insets already used by app state banners
|
// Consume insets already used by app state banners
|
||||||
val boxModifier = if (incognito || download) {
|
val boxModifier = if (incognito || downloadOnly) {
|
||||||
Modifier.consumeWindowInsets(WindowInsets.statusBars)
|
Modifier.consumeWindowInsets(WindowInsets.statusBars)
|
||||||
} else {
|
} else {
|
||||||
Modifier
|
Modifier
|
||||||
|
Loading…
Reference in New Issue
Block a user