自定义主题添加选择对比度的选项 #762
Merge pull request #762 * 手动选择对比度 * 样式优化&操作逻辑优化 * [优化] 优化代码,使用kolor自带的枚举值
This commit is contained in:
@@ -178,6 +178,7 @@ object PreferKey {
|
||||
const val disableMangaScale = "disableMangaScale"
|
||||
const val firebaseEnable = "firebaseEnable"
|
||||
const val cPrimary = "colorPrimary"
|
||||
const val customContrast = "customContrast"
|
||||
const val cAccent = "colorAccent"
|
||||
const val customMode = "customMode"
|
||||
const val paletteStyle = "paletteStyle"
|
||||
|
||||
@@ -47,6 +47,10 @@ object ThemeConfig {
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
}
|
||||
|
||||
var customContrast by prefDelegate(PreferKey.customContrast, "Default") {
|
||||
postEvent(EventBus.RECREATE, "")
|
||||
}
|
||||
|
||||
var launcherIcon by prefDelegate(PreferKey.launcherIcon, "ic_launcher")
|
||||
|
||||
var showDiscovery by prefDelegate(PreferKey.showDiscovery, true)
|
||||
@@ -68,4 +72,4 @@ object ThemeConfig {
|
||||
fun hasImageBg(isDark: Boolean): Boolean =
|
||||
!(if (isDark) bgImageDark else bgImageLight).isNullOrBlank()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,12 +213,12 @@ fun ThemeConfigScreen(
|
||||
onClick = { showLauncherIconPicker = true }
|
||||
)
|
||||
SwitchSettingItem(
|
||||
title = "预见性返回手势",
|
||||
description = "启用系统预见性返回手势",
|
||||
title = stringResource(R.string.predictive_back),
|
||||
description = stringResource(R.string.predictive_back_summary),
|
||||
checked = ThemeConfig.isPredictiveBackEnabled,
|
||||
onCheckedChange = {
|
||||
ThemeConfig.isPredictiveBackEnabled = it
|
||||
context.toastOnUi("重启以应用")
|
||||
context.toastOnUi(R.string.restart_to_apply)
|
||||
}
|
||||
)
|
||||
SliderSettingItem(
|
||||
@@ -239,14 +239,14 @@ fun ThemeConfigScreen(
|
||||
}
|
||||
|
||||
if (selectedTheme == "12") {
|
||||
SplicedColumnGroup(title = "自定义主题") {
|
||||
SplicedColumnGroup(title = stringResource(R.string.custom_theme)) {
|
||||
ClickableSettingItem(
|
||||
title = stringResource(R.string.seed_color),
|
||||
option = if (primaryColorValue.intValue != 0) "#${
|
||||
Integer.toHexString(
|
||||
primaryColorValue.intValue
|
||||
).uppercase()
|
||||
}" else "点击选择",
|
||||
}" else stringResource(R.string.click_to_select),
|
||||
onClick = { showColorPicker = true },
|
||||
trailingContent = {
|
||||
if (primaryColorValue.intValue != 0) {
|
||||
@@ -271,6 +271,13 @@ fun ThemeConfigScreen(
|
||||
entryValues = stringArrayResource(R.array.paletteStyle_value),
|
||||
onValueChange = { ThemeConfig.paletteStyle = it }
|
||||
)
|
||||
DropdownListSettingItem(
|
||||
title = stringResource(R.string.preferred_contrast),
|
||||
selectedValue = ThemeConfig.customContrast,
|
||||
displayEntries = stringArrayResource(R.array.customContrast),
|
||||
entryValues = stringArrayResource(R.array.customContrast_value),
|
||||
onValueChange = { ThemeConfig.customContrast = it }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -325,9 +332,9 @@ fun ThemeConfigScreen(
|
||||
)
|
||||
}
|
||||
|
||||
SplicedColumnGroup(title = "Compose 相关") {
|
||||
SplicedColumnGroup(title = stringResource(R.string.compose_related)) {
|
||||
SwitchSettingItem(
|
||||
title = "使用折叠应用栏",
|
||||
title = stringResource(R.string.use_flexible_top_bar),
|
||||
checked = ThemeConfig.useFlexibleTopAppBar,
|
||||
onCheckedChange = { ThemeConfig.useFlexibleTopAppBar = it }
|
||||
)
|
||||
@@ -469,6 +476,7 @@ fun ThemeConfigScreen(
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
|
||||
|
||||
@@ -1,30 +1,16 @@
|
||||
package io.legado.app.ui.theme
|
||||
|
||||
import android.app.UiModeManager
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import androidx.compose.material3.ColorScheme
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.core.content.getSystemService
|
||||
import com.materialkolor.Contrast
|
||||
import com.materialkolor.PaletteStyle
|
||||
import com.materialkolor.dynamicColorScheme
|
||||
|
||||
class CustomColorScheme(
|
||||
context: Context,
|
||||
seed: Int,
|
||||
style: PaletteStyle,
|
||||
) : BaseColorScheme() {
|
||||
|
||||
private val contrastLevel: Double =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||
context.getSystemService<UiModeManager>()
|
||||
?.contrast
|
||||
?.toDouble()
|
||||
?: Contrast.Default.value
|
||||
} else {
|
||||
Contrast.Default.value
|
||||
}
|
||||
private val contrastLevel: Double = ThemeResolver.resolveContrastLevel()
|
||||
|
||||
override val lightScheme: ColorScheme = dynamicColorScheme(
|
||||
seedColor = Color(seed),
|
||||
|
||||
@@ -65,7 +65,7 @@ object ThemeManager {
|
||||
}
|
||||
|
||||
AppThemeMode.CUSTOM -> {
|
||||
CustomColorScheme(context, context.primaryColor, style)
|
||||
CustomColorScheme(context.primaryColor, style)
|
||||
.getColorScheme(darkTheme)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.legado.app.ui.theme
|
||||
|
||||
import com.materialkolor.Contrast
|
||||
import com.materialkolor.PaletteStyle
|
||||
import io.legado.app.ui.config.themeConfig.ThemeConfig
|
||||
|
||||
object ThemeResolver {
|
||||
|
||||
@@ -37,4 +39,12 @@ object ThemeResolver {
|
||||
}
|
||||
}
|
||||
|
||||
fun resolveContrastLevel(): Double {
|
||||
return try {
|
||||
Contrast.valueOf(ThemeConfig.customContrast).value
|
||||
} catch (e: Exception) {
|
||||
Contrast.Default.value
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user