refactor: 代码优化

This commit is contained in:
HapeLee
2026-06-12 03:22:13 +08:00
parent 81fc3ea7e4
commit d4745b55b4
6 changed files with 84 additions and 99 deletions
@@ -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 ->
@@ -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
@@ -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
},
)
}
@@ -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,
@@ -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
},
)
}
@@ -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
},
)
}