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

fix: 阅读搜素和菜单部分问题,长按替换净化按钮打开列表

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

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

@@ -1781,6 +1781,7 @@ private fun FloatingIconRow(
         state.isReadAloudRunning,
         state.isReadAloudRunning,
         state.isAutoPage,
         state.isAutoPage,
         state.translationMode,
         state.translationMode,
+        state.useReplaceRule,
     ) {
     ) {
         loadFloatingIcons(context, state, onIntent)
         loadFloatingIcons(context, state, onIntent)
     }
     }
@@ -2359,7 +2360,8 @@ private fun MenuBottomBar(
             state.menuConfig.readMenuCustomIcons,
             state.menuConfig.readMenuCustomIcons,
             state.isReadAloudRunning,
             state.isReadAloudRunning,
             state.isAutoPage,
             state.isAutoPage,
-            state.translationMode
+            state.translationMode,
+            state.useReplaceRule,
         ) {
         ) {
             loadToolButtons(context, state, onIntent)
             loadToolButtons(context, state, onIntent)
         }
         }
@@ -2890,8 +2892,11 @@ private fun loadToolButtons(
         infoMap.getValue("next_chapter").toButton {
         infoMap.getValue("next_chapter").toButton {
             onIntent(ReadBookIntent.NextChapter)
             onIntent(ReadBookIntent.NextChapter)
         },
         },
-        infoMap.getValue("replace").toButton {
-            onIntent(ReadBookIntent.MenuSettingReplace)
+        infoMap.getValue("replace").toButton(
+            isActive = state.useReplaceRule,
+            onLongClick = { onIntent(ReadBookIntent.MenuSettingReplace) },
+        ) {
+            onIntent(ReadBookIntent.MenuEnableReplace)
         },
         },
         infoMap.getValue("replace_badge").toButton {
         infoMap.getValue("replace_badge").toButton {
             onIntent(ReadBookIntent.MenuSettingReplace)
             onIntent(ReadBookIntent.MenuSettingReplace)
@@ -3256,7 +3261,7 @@ private fun loadFloatingIcons(
         "theme" to { onIntent(ReadBookIntent.ToggleDayNight) },
         "theme" to { onIntent(ReadBookIntent.ToggleDayNight) },
         "prev_chapter" to { onIntent(ReadBookIntent.PrevChapter) },
         "prev_chapter" to { onIntent(ReadBookIntent.PrevChapter) },
         "next_chapter" to { onIntent(ReadBookIntent.NextChapter) },
         "next_chapter" to { onIntent(ReadBookIntent.NextChapter) },
-        "replace" to { onIntent(ReadBookIntent.MenuSettingReplace) },
+        "replace" to { onIntent(ReadBookIntent.MenuEnableReplace) },
         "replace_badge" to { onIntent(ReadBookIntent.MenuSettingReplace) },
         "replace_badge" to { onIntent(ReadBookIntent.MenuSettingReplace) },
         "auto_page" to {
         "auto_page" to {
             if (state.isAutoPage) {
             if (state.isAutoPage) {
@@ -3275,6 +3280,7 @@ private fun loadFloatingIcons(
         if (state.isReadAloudRunning) add("read_aloud")
         if (state.isReadAloudRunning) add("read_aloud")
         if (state.isAutoPage) add("auto_page")
         if (state.isAutoPage) add("auto_page")
         if (state.translationMode) add("translate")
         if (state.translationMode) add("translate")
+        if (state.useReplaceRule) add("replace")
     }
     }
 
 
     return state.menuConfig.titleBarButtons
     return state.menuConfig.titleBarButtons
@@ -3289,10 +3295,16 @@ private fun loadFloatingIcons(
                 label = info.label,
                 label = info.label,
                 isActive = id in activeIds,
                 isActive = id in activeIds,
                 onClick = actionMap[id] ?: {},
                 onClick = actionMap[id] ?: {},
-                onLongClick = if (id == "read_aloud") {
-                    { onIntent(ReadBookIntent.OpenReadMenuRoute(ReadBookMenuRoute.ReadAloud)) }
-                } else {
-                    null
+                onLongClick = when (id) {
+                    "read_aloud" -> {
+                        { onIntent(ReadBookIntent.OpenReadMenuRoute(ReadBookMenuRoute.ReadAloud)) }
+                    }
+
+                    "replace" -> {
+                        { onIntent(ReadBookIntent.MenuSettingReplace) }
+                    }
+
+                    else -> null
                 },
                 },
             )
             )
         }
         }

+ 8 - 1
app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@@ -707,8 +707,12 @@ class ReadBookViewModel(
 
 
             is ReadBookIntent.MenuEnableReplace -> {
             is ReadBookIntent.MenuEnableReplace -> {
                 ReadBook.book?.let {
                 ReadBook.book?.let {
-                    it.setUseReplaceRule(!it.getUseReplaceRule())
+                    val enabled = !it.getUseReplaceRule()
+                    it.setUseReplaceRule(enabled)
                     ReadBook.saveRead()
                     ReadBook.saveRead()
+                    _uiState.update { state ->
+                        state.copy(useReplaceRule = enabled, replaceRuleEnabled = enabled)
+                    }
                     replaceRuleChanged()
                     replaceRuleChanged()
                 }
                 }
             }
             }
@@ -4374,6 +4378,9 @@ class ReadBookViewModel(
         ReadBook.book?.let {
         ReadBook.book?.let {
             it.setUseReplaceRule(enabled)
             it.setUseReplaceRule(enabled)
             ReadBook.saveRead()
             ReadBook.saveRead()
+            _uiState.update { state ->
+                state.copy(useReplaceRule = enabled, replaceRuleEnabled = enabled)
+            }
             replaceRuleChanged()
             replaceRuleChanged()
         }
         }
     }
     }

+ 1 - 6
app/src/main/java/io/legado/app/ui/widget/components/button/series/SeriesIconButton.kt

@@ -17,7 +17,6 @@ import androidx.compose.foundation.layout.Row
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.layout.size
 import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
 import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
-import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButtonDefaults
 import androidx.compose.material3.IconButtonDefaults
 import androidx.compose.material3.ripple
 import androidx.compose.material3.ripple
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.Composable
@@ -39,12 +38,8 @@ import androidx.compose.ui.unit.Dp
 import androidx.compose.ui.unit.DpSize
 import androidx.compose.ui.unit.DpSize
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.dp
 import io.legado.app.ui.theme.LegadoTheme
 import io.legado.app.ui.theme.LegadoTheme
-import io.legado.app.ui.theme.LegadoTheme.composeEngine
-import io.legado.app.ui.theme.ThemeResolver
 import io.legado.app.ui.widget.components.icon.AppIcon
 import io.legado.app.ui.widget.components.icon.AppIcon
 import io.legado.app.ui.widget.components.text.AppText
 import io.legado.app.ui.widget.components.text.AppText
-import top.yukonga.miuix.kmp.basic.Icon as MiuixIcon
-import top.yukonga.miuix.kmp.basic.Text as MiuixText
 
 
 @OptIn(ExperimentalMaterial3ExpressiveApi::class)
 @OptIn(ExperimentalMaterial3ExpressiveApi::class)
 internal val SeriesIconSize: Dp
 internal val SeriesIconSize: Dp
@@ -256,7 +251,7 @@ internal fun squareSize(size: Dp) = DpSize(size, size)
 private fun containerColor(style: SeriesIconButtonStyle): Color {
 private fun containerColor(style: SeriesIconButtonStyle): Color {
     return when (style) {
     return when (style) {
         SeriesIconButtonStyle.Plain -> Color.Transparent
         SeriesIconButtonStyle.Plain -> Color.Transparent
-        SeriesIconButtonStyle.Tonal,
+        SeriesIconButtonStyle.Tonal -> LegadoTheme.colorScheme.surface
         SeriesIconButtonStyle.Outlined -> LegadoTheme.colorScheme.surface.copy(alpha = 0f)
         SeriesIconButtonStyle.Outlined -> LegadoTheme.colorScheme.surface.copy(alpha = 0f)
     }
     }
 }
 }