File tree Expand file tree Collapse file tree
sheaf/app/src/main/java/systems/lupine/sheaf/ui Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import androidx.compose.material.icons.Icons
1818import androidx.compose.material.icons.filled.Warning
1919import androidx.compose.material3.*
2020import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
21+ import androidx.compose.foundation.isSystemInDarkTheme
2122import androidx.compose.runtime.*
2223import androidx.compose.ui.Alignment
2324import androidx.compose.ui.Modifier
@@ -116,6 +117,17 @@ fun parseColor(hex: String): Color? = runCatching {
116117 Color (android.graphics.Color .parseColor(hex))
117118}.getOrNull()
118119
120+ // Adjusts a color's HSV brightness so it stays legible on the current theme background:
121+ // darkened to ≤0.55 in light theme, brightened to ≥0.75 in dark theme.
122+ @Composable
123+ fun Color.toThemeAdapted (): Color {
124+ val dark = isSystemInDarkTheme()
125+ val hsv = FloatArray (3 )
126+ android.graphics.Color .colorToHSV(this .toArgb(), hsv)
127+ hsv[2 ] = if (dark) hsv[2 ].coerceAtLeast(0.75f ) else hsv[2 ].coerceAtMost(0.55f )
128+ return Color (android.graphics.Color .HSVToColor (hsv))
129+ }
130+
119131// ── Member card ───────────────────────────────────────────────────────────────
120132
121133@OptIn(ExperimentalFoundationApi ::class )
Original file line number Diff line number Diff line change @@ -15,7 +15,10 @@ import androidx.compose.material3.pulltorefresh.PullToRefreshBox
1515import androidx.compose.runtime.*
1616import androidx.compose.ui.Alignment
1717import androidx.compose.ui.Modifier
18+ import androidx.compose.ui.text.SpanStyle
19+ import androidx.compose.ui.text.buildAnnotatedString
1820import androidx.compose.ui.text.style.TextOverflow
21+ import androidx.compose.ui.text.withStyle
1922import androidx.compose.ui.unit.dp
2023import androidx.hilt.navigation.compose.hiltViewModel
2124import androidx.lifecycle.Lifecycle
@@ -55,7 +58,20 @@ fun HomeScreen(
5558 contentWindowInsets = WindowInsets (0 ),
5659 topBar = {
5760 SheafCenterAlignedTopAppBar (
58- title = { Text (state.system?.name?.let { " Welcome, $it " } ? : " Welcome" ) },
61+ title = {
62+ val systemColor = state.system?.color?.let { parseColor(it)?.toThemeAdapted() }
63+ Text (
64+ text = buildAnnotatedString {
65+ append(" Welcome" )
66+ state.system?.name?.let { name ->
67+ append(" , " )
68+ withStyle(SpanStyle (color = systemColor ? : LocalContentColor .current)) {
69+ append(name)
70+ }
71+ }
72+ },
73+ )
74+ },
5975 )
6076 },
6177 floatingActionButton = {
You can’t perform that action at this time.
0 commit comments