diff --git a/app/shared/app-data/src/commonMain/kotlin/data/models/preference/ThemeSettings.kt b/app/shared/app-data/src/commonMain/kotlin/data/models/preference/ThemeSettings.kt index 80fdc62ec2..865ea1f39b 100644 --- a/app/shared/app-data/src/commonMain/kotlin/data/models/preference/ThemeSettings.kt +++ b/app/shared/app-data/src/commonMain/kotlin/data/models/preference/ThemeSettings.kt @@ -11,7 +11,6 @@ package me.him188.ani.app.data.models.preference import androidx.compose.runtime.Immutable import androidx.compose.runtime.Stable -import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable import kotlinx.serialization.Transient @@ -28,7 +27,7 @@ data class ThemeSettings( val darkMode: DarkMode = DarkMode.AUTO, val useDynamicTheme: Boolean = false, // default "true" on Android && Build.VERSION.SDK_INT >= 31 val isAmoled: Boolean = false, - @Contextual val seedColor: Int = DEFAULT_SEED_COLOR, + val seedColor: Int = DEFAULT_SEED_COLOR, @Suppress("PropertyName") @Transient val _placeholder: Int = 0, ) { companion object { diff --git a/app/shared/ui-foundation/src/commonMain/kotlin/ui/foundation/layout/CarouselItem.kt b/app/shared/ui-foundation/src/commonMain/kotlin/ui/foundation/layout/CarouselItem.kt index 30a32720a9..039aba6c68 100644 --- a/app/shared/ui-foundation/src/commonMain/kotlin/ui/foundation/layout/CarouselItem.kt +++ b/app/shared/ui-foundation/src/commonMain/kotlin/ui/foundation/layout/CarouselItem.kt @@ -133,7 +133,7 @@ object CarouselItemDefaults { @Composable fun colors(): CarouselItemColors = aniColorTheme(isDark = true).run { - return CarouselItemColors(onSurface, onSurface) + return CarouselItemColors(MaterialTheme.colorScheme.onSurface, MaterialTheme.colorScheme.onSurface) } @Composable diff --git a/app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt b/app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt index 23d51a8514..b8ffd65040 100644 --- a/app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt +++ b/app/shared/ui-settings/src/commonMain/kotlin/ui/settings/tabs/theme/ThemePreferences.kt @@ -59,6 +59,11 @@ import me.him188.ani.utils.platform.isAndroid import me.him188.ani.utils.platform.isDesktop import me.him188.ani.utils.platform.isMobile +private val colorList = + ((4..10) + (1..3)) + .map { it * 35.0 } + .map { Color(Hct.from(it, 40.0, 40.0).toInt()) } + @Composable fun SettingsScope.ThemeGroup( state: SettingsState, @@ -67,7 +72,7 @@ fun SettingsScope.ThemeGroup( Group(title = { Text("主题") }) { // TODO: DarkThemePreference.kt - // Use TextButton with Icon. And only show if build sdk_int >= 29 + // Use TextButton with Icon. And only show if build sdk_int >= 29 AnimatedVisibility( LocalPlatform.current.isDesktop() || LocalPlatform.current.isAndroid(), ) { @@ -105,12 +110,7 @@ fun SettingsScope.ThemeGroup( SwitchItem( checked = themeSettings.useDynamicTheme, onCheckedChange = { checked -> - state.update( - themeSettings.copy( - useDynamicTheme = checked, - // seedColor = if (checked) Color.Black.toArgb() else themeSettings.seedColor - ), - ) + state.update(themeSettings.copy(useDynamicTheme = checked)) }, title = { Text("动态色彩") }, description = { Text("将壁纸主题色应用于应用主题") }, @@ -127,9 +127,6 @@ fun SettingsScope.ThemeGroup( // ) } - val colorList = - ((4..10) + (1..3)).map { it * 35.0 }.map { Color(Hct.from(it, 40.0, 40.0).toInt()) } - Group(title = { Text("调色板") }) { if (LocalPlatform.current.isMobile()) { val colors = colorList.chunked(4) @@ -153,7 +150,7 @@ fun SettingsScope.ThemeGroup( horizontalArrangement = Arrangement.Center, ) { colors[page].forEach { color -> - ColorButtons( + ColorButton( color = color, themeSettings = themeSettings, state = state, @@ -191,7 +188,7 @@ fun SettingsScope.ThemeGroup( // maxItemsInEachRow = 4 ) { colorList.forEach { color -> - ColorButtons( + ColorButton( color = color, themeSettings = themeSettings, state = state, @@ -203,16 +200,14 @@ fun SettingsScope.ThemeGroup( } @Composable -fun ColorButtons( +private fun ColorButton( color: Color, themeSettings: ThemeSettings, state: SettingsState ) { - ColorButtonImpl( + ColorButton( modifier = Modifier, - isSelected = { color.toArgb() == themeSettings.seedColor && !themeSettings.useDynamicTheme }, - cardColor = MaterialTheme.colorScheme.surfaceContainer, - containerColor = MaterialTheme.colorScheme.primaryContainer, + selected = color.toArgb() == themeSettings.seedColor && !themeSettings.useDynamicTheme, onClick = { state.update( themeSettings.copy( @@ -226,16 +221,16 @@ fun ColorButtons( } @Composable -fun ColorButtonImpl( +fun ColorButton( + onClick: () -> Unit, + baseColor: Color, + selected: Boolean, modifier: Modifier = Modifier, - isSelected: () -> Boolean = { false }, - cardColor: Color = MaterialTheme.colorScheme.primaryContainer, + cardColor: Color = MaterialTheme.colorScheme.surfaceContainer, containerColor: Color = MaterialTheme.colorScheme.primaryContainer, - onClick: () -> Unit = {}, - baseColor: Color ) { - val containerSize by animateDpAsState(targetValue = if (isSelected()) 28.dp else 0.dp) - val iconSize by animateDpAsState(targetValue = if (isSelected()) 16.dp else 0.dp) + val containerSize by animateDpAsState(targetValue = if (selected) 28.dp else 0.dp) + val iconSize by animateDpAsState(targetValue = if (selected) 16.dp else 0.dp) Surface( modifier = modifier