style(android): respect system theme and clamp overlays

This commit is contained in:
Peter Steinberger
2025-12-18 01:15:50 +01:00
parent 1673bf2d44
commit 99310a5bbb
4 changed files with 48 additions and 7 deletions

View File

@@ -7,7 +7,6 @@ import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.core.content.ContextCompat
@@ -18,6 +17,7 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.steipete.clawdis.node.ui.RootScreen
import com.steipete.clawdis.node.ui.ClawdisTheme
import kotlinx.coroutines.launch
class MainActivity : ComponentActivity() {
@@ -44,7 +44,7 @@ class MainActivity : ComponentActivity() {
}
setContent {
MaterialTheme {
ClawdisTheme {
Surface(modifier = Modifier) {
RootScreen(viewModel = viewModel)
}

View File

@@ -0,0 +1,41 @@
package com.steipete.clawdis.node.ui
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
@Composable
fun ClawdisTheme(content: @Composable () -> Unit) {
val context = LocalContext.current
val isDark = isSystemInDarkTheme()
val colorScheme =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (isDark) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
} else {
if (isDark) darkColorScheme() else lightColorScheme()
}
MaterialTheme(colorScheme = colorScheme, content = content)
}
@Composable
fun overlayContainerColor(): Color {
val scheme = MaterialTheme.colorScheme
val isDark = isSystemInDarkTheme()
val base = if (isDark) scheme.surfaceContainerLow else scheme.surfaceContainerHigh
// Light mode: background stays dark (canvas), so clamp overlays away from pure-white glare.
return if (isDark) base else base.copy(alpha = 0.88f)
}
@Composable
fun overlayIconColor(): Color {
return MaterialTheme.colorScheme.onSurfaceVariant
}

View File

@@ -131,8 +131,8 @@ private fun OverlayIconButton(
modifier = Modifier.size(44.dp),
colors =
IconButtonDefaults.filledTonalIconButtonColors(
containerColor = MaterialTheme.colorScheme.surfaceContainerHigh,
contentColor = MaterialTheme.colorScheme.onSurface,
containerColor = overlayContainerColor(),
contentColor = overlayIconColor(),
),
) {
icon()

View File

@@ -35,7 +35,7 @@ fun StatusPill(
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(14.dp),
color = MaterialTheme.colorScheme.surfaceContainerHigh,
color = overlayContainerColor(),
tonalElevation = 3.dp,
shadowElevation = 0.dp,
) {
@@ -59,7 +59,7 @@ fun StatusPill(
VerticalDivider(
modifier = Modifier.height(14.dp).alpha(0.35f),
color = MaterialTheme.colorScheme.onSurface,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Icon(
@@ -67,7 +67,7 @@ fun StatusPill(
contentDescription = if (voiceEnabled) "Voice enabled" else "Voice disabled",
tint =
if (voiceEnabled) {
MaterialTheme.colorScheme.onSurface
overlayIconColor()
} else {
MaterialTheme.colorScheme.onSurfaceVariant
},