Просмотр исходного кода

fix: 优化阅读菜单文字颜色

HapeLee 3 месяцев назад
Родитель
Сommit
b3f78ed0b0

+ 2 - 0
app/src/main/java/io/legado/app/constant/PreferKey.kt

@@ -305,6 +305,8 @@ object PreferKey {
     const val readMenuBgColorNight = "readMenuBgColorNight"
     const val readMenuAccentColorNight = "readMenuAccentColorNight"
     const val readMenuContainerColorNight = "readMenuContainerColorNight"
+    const val readMenuTextColor = "readMenuTextColor"
+    const val readMenuTextColorNight = "readMenuTextColorNight"
     const val readMenuColorMode = "readMenuColorMode"
     const val readMenuIconShowText = "readMenuIconShowText"
     const val readMenuIconStyle = "readMenuIconStyle"

+ 12 - 0
app/src/main/java/io/legado/app/data/repository/ReadSettingsRepository.kt

@@ -80,6 +80,8 @@ data class ReadPreferences(
     val readMenuBgColorNight: Int = 0,
     val readMenuAccentColorNight: Int = 0,
     val readMenuContainerColorNight: Int = 0,
+    val readMenuTextColor: Int = 0,
+    val readMenuTextColorNight: Int = 0,
     val readMenuColorMode: Int = 1,
     val readMenuIconShowText: Boolean = true,
     val readMenuIconStyle: Int = 0,
@@ -299,6 +301,12 @@ class ReadSettingsRepository(
     suspend fun setReadMenuContainerColorNight(value: Int) =
         settingsRepository.putInt(PreferKey.readMenuContainerColorNight, value)
 
+    suspend fun setReadMenuTextColor(value: Int) =
+        settingsRepository.putInt(PreferKey.readMenuTextColor, value)
+
+    suspend fun setReadMenuTextColorNight(value: Int) =
+        settingsRepository.putInt(PreferKey.readMenuTextColorNight, value)
+
     suspend fun setReadMenuColorMode(value: Int) =
         settingsRepository.putInt(PreferKey.readMenuColorMode, value.coerceIn(0, 1))
 
@@ -461,6 +469,8 @@ class ReadSettingsRepository(
             readMenuBgColorNight = this[Keys.ReadMenuBgColorNight] ?: 0,
             readMenuAccentColorNight = this[Keys.ReadMenuAccentColorNight] ?: 0,
             readMenuContainerColorNight = this[Keys.ReadMenuContainerColorNight] ?: 0,
+            readMenuTextColor = this[Keys.ReadMenuTextColor] ?: 0,
+            readMenuTextColorNight = this[Keys.ReadMenuTextColorNight] ?: 0,
             readMenuColorMode = this[Keys.ReadMenuColorMode] ?: 1,
             readMenuIconShowText = this[Keys.ReadMenuIconShowText] ?: true,
             readMenuIconStyle = this[Keys.ReadMenuIconStyle] ?: 0,
@@ -562,6 +572,8 @@ class ReadSettingsRepository(
         val ReadMenuBgColorNight = intPreferencesKey(PreferKey.readMenuBgColorNight)
         val ReadMenuAccentColorNight = intPreferencesKey(PreferKey.readMenuAccentColorNight)
         val ReadMenuContainerColorNight = intPreferencesKey(PreferKey.readMenuContainerColorNight)
+        val ReadMenuTextColor = intPreferencesKey(PreferKey.readMenuTextColor)
+        val ReadMenuTextColorNight = intPreferencesKey(PreferKey.readMenuTextColorNight)
         val ReadMenuColorMode = intPreferencesKey(PreferKey.readMenuColorMode)
         val ReadMenuIconShowText = booleanPreferencesKey(PreferKey.readMenuIconShowText)
         val ReadMenuIconStyle = intPreferencesKey(PreferKey.readMenuIconStyle)

+ 5 - 0
app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt

@@ -217,6 +217,8 @@ object ReadBookConfig {
     var readMenuBottomBarLiquidGlassButtons by prefDelegate(PreferKey.readMenuBottomBarLiquidGlassButtons, false)
     var readMenuBorderColor by prefDelegate(PreferKey.readMenuBorderColor, 0)
     var readMenuBorderColorNight by prefDelegate(PreferKey.readMenuBorderColorNight, 0)
+    var readMenuTextColor by prefDelegate(PreferKey.readMenuTextColor, 0)
+    var readMenuTextColorNight by prefDelegate(PreferKey.readMenuTextColorNight, 0)
     var showTitleBarIcons by prefDelegate(PreferKey.showTitleBarIcons, true)
     var readSliderMode by prefDelegate(PreferKey.readSliderMode, "0")
     var showBrightnessView by prefDelegate(PreferKey.showBrightnessView, "1")
@@ -350,6 +352,9 @@ object ReadBookConfig {
     val resolvedMenuBorderColor: Int
         get() = if (ReadStyleResolver.isNightTheme()) readMenuBorderColorNight else readMenuBorderColor
 
+    val resolvedMenuTextColor: Int
+        get() = if (ReadStyleResolver.isNightTheme()) readMenuTextColorNight else readMenuTextColor
+
     val resolvedMenuBlurColor: Int
         get() = if (ReadStyleResolver.isNightTheme()) readMenuBlurColorNight else readMenuBlurColor
 

+ 8 - 0
app/src/main/java/io/legado/app/ui/book/read/ReadBookContract.kt

@@ -300,6 +300,8 @@ data class ReadMenuConfig(
     val readMenuBorderWidth: Int = 0,
     val readMenuBorderColor: Int = 0,
     val readMenuBorderColorNight: Int = 0,
+    val readMenuTextColor: Int = 0,
+    val readMenuTextColorNight: Int = 0,
     val readMenuBlurAlpha: Int = 60,
     val readMenuBlurColor: Int = 0,
     val readMenuBlurColorNight: Int = 0,
@@ -1084,6 +1086,12 @@ sealed interface ConfigUpdate {
     data class MenuContainerColorNight(val color: Int) : ConfigUpdate {
         override val actions = setOf(ConfigUpdateAction.UpdateBackground, ConfigUpdateAction.UpdateStyle, ConfigUpdateAction.ReloadContent)
     }
+    data class MenuTextColor(val color: Int) : ConfigUpdate {
+        override val actions = emptySet<ConfigUpdateAction>()
+    }
+    data class MenuTextColorNight(val color: Int) : ConfigUpdate {
+        override val actions = emptySet<ConfigUpdateAction>()
+    }
     data class MenuColorMode(val value: Int) : ConfigUpdate {
         override val actions = setOf(ConfigUpdateAction.UpdateSystemUi)
     }

+ 22 - 20
app/src/main/java/io/legado/app/ui/book/read/ReadBookMenuBar.kt

@@ -534,11 +534,14 @@ private fun ReadBookMenuSurface(
     } else {
         bottomBarSurfaceAlpha
     }
-    val bottomBarTextColor = if (bottomBarVisualState.useContrastContent) {
-        Color.White.copy(alpha = 0.87f).compositeOver(colors.background)
-    } else {
-        LegadoTheme.colorScheme.onSurface
-    }
+    val bottomBarTextColor = Color(
+        if (ReadStyleResolver.isNightTheme()) {
+            state.menuConfig.readMenuTextColorNight
+        } else {
+            state.menuConfig.readMenuTextColor
+        }
+    ).takeUnless { it == Color.Unspecified || it.alpha == 0f }
+        ?: LegadoTheme.colorScheme.onSurface
     val surfaceWindowInsetSides = when {
         isFloating || extendSurfaceToNavigationBar -> WindowInsetsSides.Horizontal
         else -> WindowInsetsSides.Bottom + WindowInsetsSides.Horizontal
@@ -925,22 +928,21 @@ private fun MenuTitleBar(
     val topBarTintColor = readMenuTintColor(state.menuConfig)
         .takeIf { topBarVisualState.useTint }
         ?: colors.background
-    val titleTextColor = if (topBarVisualState.useContrastContent) {
-        Color.White.copy(alpha = 0.72f).compositeOver(colors.background)
-    } else {
-        LegadoTheme.colorScheme.onSurface
-    }
-    val labelStyle = if (topBarVisualState.useContrastContent) {
-        LegadoTheme.typography.labelSmallEmphasized.copy(
-            shadow = androidx.compose.ui.graphics.Shadow(
-                color = Color.Black.copy(alpha = 0.12f),
-                offset = Offset.Zero,
-                blurRadius = 12f,
-            )
+    val titleTextColor = Color(
+        if (ReadStyleResolver.isNightTheme()) {
+            state.menuConfig.readMenuTextColorNight
+        } else {
+            state.menuConfig.readMenuTextColor
+        }
+    ).takeUnless { it == Color.Unspecified || it.alpha == 0f }
+        ?: LegadoTheme.colorScheme.onSurface
+    val labelStyle = LegadoTheme.typography.labelSmallEmphasized.copy(
+        shadow = androidx.compose.ui.graphics.Shadow(
+            color = Color.Black.copy(alpha = 0.12f),
+            offset = Offset.Zero,
+            blurRadius = 12f,
         )
-    } else {
-        LegadoTheme.typography.labelSmallEmphasized
-    }
+    )
 
     Column(
         modifier = Modifier

+ 20 - 0
app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@@ -2051,6 +2051,8 @@ class ReadBookViewModel(
                 readMenuBorderWidth = ReadBookConfig.readMenuBorderWidth,
                 readMenuBorderColor = ReadBookConfig.readMenuBorderColor,
                 readMenuBorderColorNight = ReadBookConfig.readMenuBorderColorNight,
+                readMenuTextColor = ReadBookConfig.readMenuTextColor,
+                readMenuTextColorNight = ReadBookConfig.readMenuTextColorNight,
                 readMenuBlurAlpha = ReadBookConfig.readMenuBlurAlpha,
                 readMenuBlurColor = ReadBookConfig.readMenuBlurColor,
                 readMenuBlurColorNight = ReadBookConfig.readMenuBlurColorNight,
@@ -4534,6 +4536,24 @@ class ReadBookViewModel(
                 }
                 postEvent(EventBus.UPDATE_READ_ACTION_BAR, true)
             }
+            is ConfigUpdate.MenuTextColor -> {
+                ReadBookConfig.readMenuTextColor = update.color
+                viewModelScope.launch {
+                    readSettingsRepository.setReadMenuTextColor(update.color)
+                }
+                _uiState.update {
+                    it.copy(menuConfig = it.menuConfig.copy(readMenuTextColor = update.color))
+                }
+            }
+            is ConfigUpdate.MenuTextColorNight -> {
+                ReadBookConfig.readMenuTextColorNight = update.color
+                viewModelScope.launch {
+                    readSettingsRepository.setReadMenuTextColorNight(update.color)
+                }
+                _uiState.update {
+                    it.copy(menuConfig = it.menuConfig.copy(readMenuTextColorNight = update.color))
+                }
+            }
             is ConfigUpdate.MenuColorMode -> {
                 val value = update.value.coerceIn(0, 1)
                 ReadBookConfig.readMenuColorMode = value

+ 25 - 0
app/src/main/java/io/legado/app/ui/book/read/sheet/SystemMenuPage.kt

@@ -90,6 +90,8 @@ private const val COLOR_BORDER = 11
 private const val COLOR_BORDER_NIGHT = 12
 private const val COLOR_BLUR_TINT = 13
 private const val COLOR_BLUR_TINT_NIGHT = 14
+private const val COLOR_MENU_TEXT = 15
+private const val COLOR_MENU_TEXT_NIGHT = 16
 
 @Composable
 internal fun SystemMenuPage(
@@ -216,6 +218,8 @@ internal fun SystemMenuPage(
                 COLOR_BORDER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColorNight(color)))
                 COLOR_BLUR_TINT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBlurColor(color)))
                 COLOR_BLUR_TINT_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBlurColorNight(color)))
+                COLOR_MENU_TEXT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuTextColor(color)))
+                COLOR_MENU_TEXT_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuTextColorNight(color)))
             }
             showColorPicker = false
         },
@@ -485,6 +489,27 @@ private fun GlobalMenuTab(
                 onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBlurAlpha(it.toInt())))
             },
         )
+        TinyClearColorModeSettingItem(
+            title = stringResource(R.string.read_menu_text_color),
+            description = stringResource(R.string.read_menu_text_color_summary),
+            dayColor = preferences.readMenuTextColor,
+            nightColor = preferences.readMenuTextColorNight,
+            onClearColor = { isNight ->
+                onIntent(
+                    ReadBookIntent.UpdateConfig(
+                        if (isNight) ConfigUpdate.MenuTextColorNight(0)
+                        else ConfigUpdate.MenuTextColor(0)
+                    )
+                )
+            },
+            onClickColor = { isNight ->
+                if (isNight) {
+                    onShowColorPicker(COLOR_MENU_TEXT_NIGHT, preferences.readMenuTextColorNight)
+                } else {
+                    onShowColorPicker(COLOR_MENU_TEXT, preferences.readMenuTextColor)
+                }
+            },
+        )
         TinyColorModeSettingItem(
             title = stringResource(R.string.read_menu_blur_color),
             dayColor = preferences.readMenuBlurColor,

+ 4 - 3
app/src/main/java/io/legado/app/ui/widget/components/settingItem/TinySettingItems.kt

@@ -521,9 +521,10 @@ private fun ColorModePill(
                 .offset { IntOffset(x = knobOffset.roundToPx(), y = 0) }
                 .size(knobSize)
                 .clip(CircleShape)
-                .background(
-                    if (currentColor != 0) Color(currentColor)
-                    else LegadoTheme.colorScheme.surfaceContainerLow
+                .background(LegadoTheme.colorScheme.surfaceContainerLow)
+                .then(
+                    if (currentColor != 0) Modifier.background(Color(currentColor))
+                    else Modifier
                 )
                 .clickable(
                     enabled = enabled,

+ 2 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -2090,6 +2090,8 @@
     <string name="ai_test_failed">AI 连接测试失败</string>
     <string name="ai_profile_counts">供应商:%1$d,模型:%2$d,预设:%3$d</string>
     <string name="read_menu_bg_color_summary">阅读顶栏和底栏背景色</string>
+    <string name="read_menu_text_color">菜单文字颜色</string>
+    <string name="read_menu_text_color_summary">默认时使用主题色</string>
     <string name="read_menu_color_source">色板来源</string>
     <string name="container_background_color">容器背景色</string>
     <string name="read_menu_container_color_summary">用于生成阅读菜单色板的基础表面色</string>

+ 2 - 0
app/src/main/res/values-zh-rHK/strings.xml

@@ -1902,6 +1902,8 @@
     <string name="read_menu_bar_liquid_glass_buttons">液態玻璃底部按鈕</string>
     <string name="read_menu_bar_liquid_glass_summary">為懸浮底部導航欄使用液態玻璃。需要 Android 13+</string>
     <string name="read_menu_bg_color_summary">頂部和底部閱讀列的背景</string>
+    <string name="read_menu_text_color">選單文字顏色</string>
+    <string name="read_menu_text_color_summary">預設時使用主題色</string>
     <string name="read_menu_blur_alpha">選單不透明度</string>
     <string name="read_menu_blur_color">選單著色</string>
     <string name="read_menu_blur_mode">選單模糊模式</string>

+ 2 - 0
app/src/main/res/values-zh-rTW/strings.xml

@@ -2034,6 +2034,8 @@
     <string name="homepage_select_one_kind">選擇一個分類</string>
     <string name="or">或</string>
     <string name="read_menu_bg_color_summary">閱讀器頂部和底部工具列的背景色</string>
+    <string name="read_menu_text_color">選單文字顏色</string>
+    <string name="read_menu_text_color_summary">預設時使用主題色</string>
     <string name="read_menu_color_source">調色板來源</string>
     <string name="container_background_color">容器背景色</string>
     <string name="read_menu_container_color_summary">閱讀器選單調色板的基礎表面色</string>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -2099,6 +2099,8 @@
     <string name="homepage_status_blocked"> · Blocked</string>
     <string name="homepage_status_joined"> · Already joined</string>
     <string name="read_menu_bg_color_summary">Background for the top and bottom reader bars</string>
+    <string name="read_menu_text_color">Menu Text Color</string>
+    <string name="read_menu_text_color_summary">Uses the theme color by default</string>
     <string name="read_menu_color_source">Palette Source</string>
     <string name="container_background_color">Container Background Color</string>
     <string name="read_menu_container_color_summary">Base surface color for the generated reader menu palette</string>