Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WoLeo-Z committed Jan 10, 2025
1 parent fa89dd6 commit 1012ab3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ThemeSettings>,
Expand All @@ -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(),
) {
Expand Down Expand Up @@ -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("将壁纸主题色应用于应用主题") },
Expand All @@ -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)
Expand All @@ -153,7 +150,7 @@ fun SettingsScope.ThemeGroup(
horizontalArrangement = Arrangement.Center,
) {
colors[page].forEach { color ->
ColorButtons(
ColorButton(
color = color,
themeSettings = themeSettings,
state = state,
Expand Down Expand Up @@ -191,7 +188,7 @@ fun SettingsScope.ThemeGroup(
// maxItemsInEachRow = 4
) {
colorList.forEach { color ->
ColorButtons(
ColorButton(
color = color,
themeSettings = themeSettings,
state = state,
Expand All @@ -203,16 +200,14 @@ fun SettingsScope.ThemeGroup(
}

@Composable
fun ColorButtons(
private fun ColorButton(
color: Color,
themeSettings: ThemeSettings,
state: SettingsState<ThemeSettings>
) {
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(
Expand All @@ -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
Expand Down

0 comments on commit 1012ab3

Please sign in to comment.