[新增] 新增了一些 Compose 界面的相关配置,界面模糊配置尚不可用

This commit is contained in:
HapeLee
2026-01-15 01:01:31 +08:00
parent f1c3d4581a
commit 2ef2ab2ec7
17 changed files with 151 additions and 14 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

@@ -172,6 +172,8 @@ object PreferKey {
const val cPrimary = "colorPrimary" const val cPrimary = "colorPrimary"
const val cAccent = "colorAccent" const val cAccent = "colorAccent"
const val customMode = "customMode" const val customMode = "customMode"
const val paletteStyle = "paletteStyle"
const val enableBlur = "enableBlur"
const val cBackground = "colorBackground" const val cBackground = "colorBackground"
const val cBBackground = "colorBottomBackground" const val cBBackground = "colorBottomBackground"
const val bgImage = "backgroundImage" const val bgImage = "backgroundImage"
@@ -902,6 +902,17 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
appCtx.putPrefString(PreferKey.labelVisibilityMode, value) appCtx.putPrefString(PreferKey.labelVisibilityMode, value)
} }
var paletteStyle
get() = appCtx.getPrefString(PreferKey.paletteStyle, "tonalSpot")
set(value) {
appCtx.putPrefString(PreferKey.paletteStyle, value)
}
var enableBlur
get() = appCtx.getPrefBoolean(PreferKey.enableBlur, false)
set(value) {
appCtx.putPrefBoolean(PreferKey.enableBlur, value)
}
var menuAlpha: Int var menuAlpha: Int
get() = appCtx.getPrefInt(PreferKey.menuAlpha, 100) get() = appCtx.getPrefInt(PreferKey.menuAlpha, 100)
set(value) { set(value) {
@@ -961,5 +972,7 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
set(value) { set(value) {
appCtx.putPrefBoolean(PreferKey.sliderVibrator, value) appCtx.putPrefBoolean(PreferKey.sliderVibrator, value)
} }
} }
@@ -139,6 +139,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
true true
} }
// TODO:删掉种子色了喵
val hasColorImage = !getPrefString(PreferKey.colorImage).isNullOrBlank() val hasColorImage = !getPrefString(PreferKey.colorImage).isNullOrBlank()
colorPrimary?.isEnabled = !hasColorImage colorPrimary?.isEnabled = !hasColorImage
if (hasColorImage) if (hasColorImage)
@@ -178,15 +179,16 @@ class ThemeConfigFragment : PreferenceFragmentCompat(),
//recreateActivities() //recreateActivities()
} }
PreferKey.customMode -> handleRestartRequired()
PreferKey.pureBlack -> { PreferKey.paletteStyle, PreferKey.pureBlack, PreferKey.enableBlur -> {
ThemeSyncer.syncAll() ThemeSyncer.syncAll()
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
recreateActivities() recreateActivities()
}, 100) }, 100)
} }
PreferKey.customMode -> handleRestartRequired()
PreferKey.isPredictiveBackEnabled -> { PreferKey.isPredictiveBackEnabled -> {
toastOnUi("重启以应用") toastOnUi("重启以应用")
} }
@@ -19,12 +19,14 @@ fun AppTheme(
val appThemeMode by ThemeState.themeMode.collectAsState() val appThemeMode by ThemeState.themeMode.collectAsState()
val isPureBlack by ThemeState.isPureBlack.collectAsState() val isPureBlack by ThemeState.isPureBlack.collectAsState()
val hasImageBg by ThemeState.hasImageBg.collectAsState() val hasImageBg by ThemeState.hasImageBg.collectAsState()
val paletteStyle by ThemeState.paletteStyle.collectAsState()
val colorScheme = ThemeManager.getColorScheme( val colorScheme = ThemeManager.getColorScheme(
mode = appThemeMode, mode = appThemeMode,
darkTheme = darkTheme, darkTheme = darkTheme,
isAmoled = isPureBlack, isAmoled = isPureBlack,
isImageBg = hasImageBg isImageBg = hasImageBg,
paletteStyle = paletteStyle
) )
MaterialExpressiveTheme( MaterialExpressiveTheme(
@@ -34,4 +36,5 @@ fun AppTheme(
shapes = Shapes(), shapes = Shapes(),
content = content content = content
) )
} }
@@ -8,8 +8,8 @@ import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import com.materialkolor.PaletteStyle
import io.legado.app.lib.theme.primaryColor import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.theme.ThemeResolver.resolvePaletteStyle
import io.legado.app.ui.theme.colorScheme.AugustColorScheme import io.legado.app.ui.theme.colorScheme.AugustColorScheme
import io.legado.app.ui.theme.colorScheme.CarlottaColorScheme import io.legado.app.ui.theme.colorScheme.CarlottaColorScheme
import io.legado.app.ui.theme.colorScheme.ElinkColorScheme import io.legado.app.ui.theme.colorScheme.ElinkColorScheme
@@ -46,10 +46,11 @@ object ThemeManager {
darkTheme: Boolean = isSystemInDarkTheme(), darkTheme: Boolean = isSystemInDarkTheme(),
isAmoled: Boolean, isAmoled: Boolean,
isImageBg: Boolean, isImageBg: Boolean,
paletteStyle: String?,
forceOpaque: Boolean = false forceOpaque: Boolean = false
): ColorScheme { ): ColorScheme {
val context = LocalContext.current val context = LocalContext.current
val style = resolvePaletteStyle(paletteStyle)
val actualMode = if (forceOpaque && mode == AppThemeMode.Transparent) { val actualMode = if (forceOpaque && mode == AppThemeMode.Transparent) {
AppThemeMode.WH AppThemeMode.WH
} else { } else {
@@ -66,7 +67,7 @@ object ThemeManager {
} }
AppThemeMode.CUSTOM -> { AppThemeMode.CUSTOM -> {
CustomColorScheme(context, context.primaryColor, PaletteStyle.Vibrant) CustomColorScheme(context, context.primaryColor, style)
.getColorScheme(darkTheme) .getColorScheme(darkTheme)
} }
@@ -1,5 +1,7 @@
package io.legado.app.ui.theme package io.legado.app.ui.theme
import com.materialkolor.PaletteStyle
object ThemeResolver { object ThemeResolver {
fun resolveThemeMode(value: String): AppThemeMode = when (value) { fun resolveThemeMode(value: String): AppThemeMode = when (value) {
@@ -19,4 +21,20 @@ object ThemeResolver {
"13" -> AppThemeMode.Transparent "13" -> AppThemeMode.Transparent
else -> AppThemeMode.Dynamic else -> AppThemeMode.Dynamic
} }
fun resolvePaletteStyle(value: String?): PaletteStyle {
return when (value) {
"tonalSpot" -> PaletteStyle.TonalSpot
"neutral" -> PaletteStyle.Neutral
"vibrant" -> PaletteStyle.Vibrant
"expressive" -> PaletteStyle.Expressive
"rainbow" -> PaletteStyle.Rainbow
"fruitSalad" -> PaletteStyle.FruitSalad
"monochrome" -> PaletteStyle.Monochrome
"fidelity" -> PaletteStyle.Fidelity
"content" -> PaletteStyle.Content
else -> PaletteStyle.TonalSpot
}
}
} }
@@ -22,6 +22,14 @@ object ThemeState {
MutableStateFlow(AppConfig.hasImageBg) MutableStateFlow(AppConfig.hasImageBg)
val hasImageBg: StateFlow<Boolean> = _hasImageBg.asStateFlow() val hasImageBg: StateFlow<Boolean> = _hasImageBg.asStateFlow()
private val _paletteStyle =
MutableStateFlow(AppConfig.paletteStyle)
val paletteStyle: StateFlow<String?> = _paletteStyle.asStateFlow()
private val _enableBlur =
MutableStateFlow(AppConfig.enableBlur)
val enableBlur: StateFlow<Boolean> = _enableBlur.asStateFlow()
fun updateThemeMode(newMode: AppThemeMode) { fun updateThemeMode(newMode: AppThemeMode) {
if (_themeMode.value != newMode) { if (_themeMode.value != newMode) {
_themeMode.value = newMode _themeMode.value = newMode
@@ -39,4 +47,17 @@ object ThemeState {
_hasImageBg.value = enabled _hasImageBg.value = enabled
} }
} }
fun updatePaletteStyle(style: String?) {
if (_paletteStyle.value != style) {
_paletteStyle.value = style
}
}
fun updateEnableBlur(enabled: Boolean) {
if (_enableBlur.value != enabled) {
_enableBlur.value = enabled
}
}
} }
@@ -11,6 +11,8 @@ object ThemeSyncer {
syncThemeMode() syncThemeMode()
syncPureBlack() syncPureBlack()
syncImageBg() syncImageBg()
syncPaletteStyle()
syncEnableBlur()
} }
fun syncThemeMode() { fun syncThemeMode() {
@@ -26,4 +28,12 @@ object ThemeSyncer {
fun syncImageBg() { fun syncImageBg() {
ThemeState.updateImageBg(AppConfig.hasImageBg) ThemeState.updateImageBg(AppConfig.hasImageBg)
} }
fun syncPaletteStyle() {
ThemeState.updatePaletteStyle(AppConfig.paletteStyle)
}
fun syncEnableBlur() {
ThemeState.updateEnableBlur(AppConfig.enableBlur)
}
} }
@@ -34,12 +34,14 @@ fun GlobalModalBottomSheet(
val themeMode by ThemeState.themeMode.collectAsState() val themeMode by ThemeState.themeMode.collectAsState()
val isPureBlack by ThemeState.isPureBlack.collectAsState() val isPureBlack by ThemeState.isPureBlack.collectAsState()
val hasImageBg by ThemeState.hasImageBg.collectAsState() val hasImageBg by ThemeState.hasImageBg.collectAsState()
val paletteStyle by ThemeState.paletteStyle.collectAsState()
val colorScheme = ThemeManager.getColorScheme( val colorScheme = ThemeManager.getColorScheme(
mode = themeMode, mode = themeMode,
isAmoled = isPureBlack, isAmoled = isPureBlack,
isImageBg = hasImageBg, isImageBg = hasImageBg,
forceOpaque = true forceOpaque = true,
paletteStyle = paletteStyle
) )
ModalBottomSheet( ModalBottomSheet(
+12
View File
@@ -156,6 +156,18 @@
<item>关闭</item> <item>关闭</item>
</string-array> </string-array>
<string-array name="paletteStyle">
<item>柔和</item>
<item>中性</item>
<item>鲜艳</item>
<item>表现力</item>
<item>彩虹</item>
<item>水果拼盘</item>
<item>单色</item>
<item>仿真</item>
<item>内容取色</item>
</string-array>
<string-array name="customMode"> <string-array name="customMode">
<item>全局</item> <item>全局</item>
<item>仅强调色</item> <item>仅强调色</item>
@@ -1367,4 +1367,7 @@
<string name="text_accent_color">强调</string> <string name="text_accent_color">强调</string>
<string name="read_color">颜色样式</string> <string name="read_color">颜色样式</string>
<string name="reverse_volume_key_page">反转音量键翻页方向</string> <string name="reverse_volume_key_page">反转音量键翻页方向</string>
<string name="palette_style">调色板样式</string>
<string name="tip_compose_set">这里的选项仅可以控制使用Compose重写的界面。</string>
<string name="is_blur_enable">启用控件模糊</string>
</resources> </resources>
+12
View File
@@ -78,6 +78,18 @@
<item>off</item> <item>off</item>
</string-array> </string-array>
<string-array name="paletteStyle_value">
<item>tonalSpot</item>
<item>neutral</item>
<item>vibrant</item>
<item>expressive</item>
<item>rainbow</item>
<item>fruitSalad</item>
<item>monochrome</item>
<item>fidelity</item>
<item>content</item>
</string-array>
<string-array name="customMode_value"> <string-array name="customMode_value">
<item>global</item> <item>global</item>
<item>accent</item> <item>accent</item>
+12
View File
@@ -193,6 +193,18 @@
<item>Off</item> <item>Off</item>
</string-array> </string-array>
<string-array name="paletteStyle">
<item>TonalSpot</item>
<item>Neutral</item>
<item>Vibrant</item>
<item>Expressive</item>
<item>Rainbow</item>
<item>FruitSalad</item>
<item>Monochrome</item>
<item>Fidelity</item>
<item>Content</item>
</string-array>
<string-array name="customMode"> <string-array name="customMode">
<item>Global</item> <item>Global</item>
<item>Accent</item> <item>Accent</item>
+3
View File
@@ -1372,4 +1372,7 @@
<string name="text_accent_color">强调</string> <string name="text_accent_color">强调</string>
<string name="read_color">颜色样式</string> <string name="read_color">颜色样式</string>
<string name="reverse_volume_key_page">反转音量键翻页方向</string> <string name="reverse_volume_key_page">反转音量键翻页方向</string>
<string name="palette_style">调色板样式</string>
<string name="tip_compose_set">这里的选项仅可以控制使用Compose重写的界面。</string>
<string name="is_blur_enable">启用控件模糊</string>
</resources> </resources>
+28 -5
View File
@@ -43,11 +43,6 @@
app:cpv_dialogType="preset" app:cpv_dialogType="preset"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.prefs.ImagePreviewPreference
android:key="colorImage"
android:title="种子图片"
android:summary="@string/seed_photo_summary"/>
<io.legado.app.lib.prefs.NameListPreference <io.legado.app.lib.prefs.NameListPreference
android:defaultValue="global" android:defaultValue="global"
android:key="customMode" android:key="customMode"
@@ -81,6 +76,34 @@
</io.legado.app.lib.prefs.PreferenceCategory> </io.legado.app.lib.prefs.PreferenceCategory>
<io.legado.app.lib.prefs.PreferenceCategory
android:title="Compose 相关"
app:allowDividerAbove="false"
app:allowDividerBelow="false"
app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.lib.prefs.TipPreference
android:key="tip"
android:selectable="false"
app:iconSpaceReserved="false"
app:tipText="@string/tip_compose_set" />
<io.legado.app.lib.prefs.NameListPreference
android:defaultValue="tonalSpot"
android:key="paletteStyle"
android:title="@string/palette_style"
app:entries="@array/paletteStyle"
app:entryValues="@array/paletteStyle_value" />
<io.legado.app.lib.prefs.SwitchPreference
android:defaultValue="true"
android:key="enableBlur"
android:title="@string/is_blur_enable"
app:iconSpaceReserved="false" />
</io.legado.app.lib.prefs.PreferenceCategory>
<io.legado.app.lib.prefs.PreferenceCategory <io.legado.app.lib.prefs.PreferenceCategory
android:title="@string/main_activity" android:title="@string/main_activity"
app:allowDividerAbove="false" app:allowDividerAbove="false"
+1 -1
View File
@@ -42,7 +42,7 @@ markwon = "4.6.2"
material = "1.14.0-alpha08" material = "1.14.0-alpha08"
material3 = "1.5.0-alpha11" material3 = "1.5.0-alpha11"
material3IconsExtended = "1.7.8" material3IconsExtended = "1.7.8"
materialKolor = "4.0.5" materialKolor = "4.1.0"
media = "1.7.1" media = "1.7.1"
media3 = "1.8.0" media3 = "1.8.0"
nanoHttpd = "2.3.1" nanoHttpd = "2.3.1"