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

+ 2 - 2
app/src/main/java/io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt

@@ -215,10 +215,10 @@ fun BgTextConfigSheet(
         }
     }
 
-    if (showColorPicker) {
+    run {
         val initialColor = if (colorPickerIsNight) nightBgColor else dayBgColor
         ColorPickerSheet(
-            show = true,
+            show = showColorPicker,
             initialColor = if (initialColor != 0) initialColor else if (colorPickerIsNight) 0xFF000000.toInt() else 0xFFEEEEEE.toInt(),
             onDismissRequest = { showColorPicker = false },
             onColorSelected = { color ->

+ 16 - 21
app/src/main/java/io/legado/app/ui/book/read/sheet/HighlightRuleConfigSheet.kt

@@ -74,29 +74,24 @@ fun HighlightRuleConfigSheet(
     // Edit existing rule
     val editingRuleValue = state.editingRule
 
-    if (show && editingRuleValue != null) {
-        HighlightRuleEditSheet(
-            show = true,
-            rule = editingRuleValue,
-            onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) },
-            onSave = { updated ->
-                onIntent(ReadBookIntent.SaveHighlightRule(updated))
-            },
-        )
-    }
-
+    HighlightRuleEditSheet(
+        show = show && editingRuleValue != null,
+        rule = editingRuleValue,
+        onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) },
+        onSave = { updated ->
+            onIntent(ReadBookIntent.SaveHighlightRule(updated))
+        },
+    )
 
     // Add new rule
-    if (show && state.showNewRule) {
-        HighlightRuleEditSheet(
-            show = true,
-            rule = null,
-            onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) },
-            onSave = { newRule ->
-                onIntent(ReadBookIntent.SaveHighlightRule(newRule))
-            },
-        )
-    }
+    HighlightRuleEditSheet(
+        show = show && state.showNewRule,
+        rule = null,
+        onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) },
+        onSave = { newRule ->
+            onIntent(ReadBookIntent.SaveHighlightRule(newRule))
+        },
+    )
 
     // Delete confirmation
     val deletingRule = state.deleteRule

+ 10 - 12
app/src/main/java/io/legado/app/ui/book/read/sheet/ShadowSetSheet.kt

@@ -83,16 +83,14 @@ fun ShadowSetSheet(
         }
     }
 
-    if (showColorPicker) {
-        ColorPickerSheet(
-            show = true,
-            initialColor = shadowColor,
-            onDismissRequest = { showColorPicker = false },
-            onColorSelected = { color ->
-                shadowColor = color
-                onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.ShadowColor(color)))
-                showColorPicker = false
-            },
-        )
-    }
+    ColorPickerSheet(
+        show = showColorPicker,
+        initialColor = shadowColor,
+        onDismissRequest = { showColorPicker = false },
+        onColorSelected = { color ->
+            shadowColor = color
+            onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.ShadowColor(color)))
+            showColorPicker = false
+        },
+    )
 }

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

@@ -150,26 +150,24 @@ internal fun SystemMenuPage(
     }
 
     // Floating sheets
-    if (showColorPicker) {
-        ColorPickerSheet(
-            show = true,
-            initialColor = colorPickerInitial,
-            onDismissRequest = { showColorPicker = false },
-            onColorSelected = { color ->
-                when (colorPickerId) {
-                    COLOR_BG -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColor(color)))
-                    COLOR_MENU_ACCENT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColor(color)))
-                    COLOR_MENU_CONTAINER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColor(color)))
-                    COLOR_BG_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColorNight(color)))
-                    COLOR_MENU_ACCENT_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColorNight(color)))
-                    COLOR_MENU_CONTAINER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColorNight(color)))
-                    COLOR_BORDER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColor(color)))
-                    COLOR_BORDER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColorNight(color)))
-                }
-                showColorPicker = false
-            },
-        )
-    }
+    ColorPickerSheet(
+        show = showColorPicker,
+        initialColor = colorPickerInitial,
+        onDismissRequest = { showColorPicker = false },
+        onColorSelected = { color ->
+            when (colorPickerId) {
+                COLOR_BG -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColor(color)))
+                COLOR_MENU_ACCENT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColor(color)))
+                COLOR_MENU_CONTAINER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColor(color)))
+                COLOR_BG_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColorNight(color)))
+                COLOR_MENU_ACCENT_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColorNight(color)))
+                COLOR_MENU_CONTAINER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColorNight(color)))
+                COLOR_BORDER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColor(color)))
+                COLOR_BORDER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColorNight(color)))
+            }
+            showColorPicker = false
+        },
+    )
 
     BottomBarIconSheet(
         show = showIconSheet,

+ 28 - 32
app/src/main/java/io/legado/app/ui/book/read/sheet/TextTitleSheet.kt

@@ -381,25 +381,23 @@ internal fun TextEffectsPage(
     }
 
     // Color picker
-    if (showColorPicker) {
-        ColorPickerSheet(
-            show = true,
-            initialColor = colorPickerInitial,
-            onDismissRequest = { showColorPicker = false },
-            onColorSelected = { color ->
-                when (colorPickerId) {
-                    COLOR_TEXT -> {
-                        onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextColor(color)))
-                    }
-
-                    COLOR_ACCENT -> {
-                        onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextAccentColor(color)))
-                    }
+    ColorPickerSheet(
+        show = showColorPicker,
+        initialColor = colorPickerInitial,
+        onDismissRequest = { showColorPicker = false },
+        onColorSelected = { color ->
+            when (colorPickerId) {
+                COLOR_TEXT -> {
+                    onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextColor(color)))
                 }
-                showColorPicker = false
-            },
-        )
-    }
+
+                COLOR_ACCENT -> {
+                    onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextAccentColor(color)))
+                }
+            }
+            showColorPicker = false
+        },
+    )
 }
 
 // ========== Title Settings (sub-page) ==========
@@ -527,19 +525,17 @@ internal fun TitleSettingsPage(
     }
 
     // Color picker
-    if (showColorPicker) {
-        ColorPickerSheet(
-            show = true,
-            initialColor = colorPickerInitial,
-            onDismissRequest = { showColorPicker = false },
-            onColorSelected = { color ->
-                when (colorPickerId) {
-                    COLOR_TITLE -> {
-                        onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TitleColor(color)))
-                    }
+    ColorPickerSheet(
+        show = showColorPicker,
+        initialColor = colorPickerInitial,
+        onDismissRequest = { showColorPicker = false },
+        onColorSelected = { color ->
+            when (colorPickerId) {
+                COLOR_TITLE -> {
+                    onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TitleColor(color)))
                 }
-                showColorPicker = false
-            },
-        )
-    }
+            }
+            showColorPicker = false
+        },
+    )
 }

+ 10 - 12
app/src/main/java/io/legado/app/ui/book/read/sheet/UnderlineConfigSheet.kt

@@ -146,16 +146,14 @@ fun UnderlineConfigSheet(
     }
 
     // Color picker
-    if (showColorPicker) {
-        ColorPickerSheet(
-            show = true,
-            initialColor = underlineColor,
-            onDismissRequest = { showColorPicker = false },
-            onColorSelected = { color ->
-                underlineColor = color
-                onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.UnderlineColor(color)))
-                showColorPicker = false
-            },
-        )
-    }
+    ColorPickerSheet(
+        show = showColorPicker,
+        initialColor = underlineColor,
+        onDismissRequest = { showColorPicker = false },
+        onColorSelected = { color ->
+            underlineColor = color
+            onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.UnderlineColor(color)))
+            showColorPicker = false
+        },
+    )
 }