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 val initialColor = if (colorPickerIsNight) nightBgColor else dayBgColor
ColorPickerSheet( ColorPickerSheet(
show = true, show = showColorPicker,
initialColor = if (initialColor != 0) initialColor else if (colorPickerIsNight) 0xFF000000.toInt() else 0xFFEEEEEE.toInt(), initialColor = if (initialColor != 0) initialColor else if (colorPickerIsNight) 0xFF000000.toInt() else 0xFFEEEEEE.toInt(),
onDismissRequest = { showColorPicker = false }, onDismissRequest = { showColorPicker = false },
onColorSelected = { color -> onColorSelected = { color ->
@@ -74,29 +74,24 @@ fun HighlightRuleConfigSheet(
// Edit existing rule // Edit existing rule
val editingRuleValue = state.editingRule val editingRuleValue = state.editingRule
if (show && editingRuleValue != null) { HighlightRuleEditSheet(
HighlightRuleEditSheet( show = show && editingRuleValue != null,
show = true, rule = editingRuleValue,
rule = editingRuleValue, onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) },
onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) }, onSave = { updated ->
onSave = { updated -> onIntent(ReadBookIntent.SaveHighlightRule(updated))
onIntent(ReadBookIntent.SaveHighlightRule(updated)) },
}, )
)
}
// Add new rule // Add new rule
if (show && state.showNewRule) { HighlightRuleEditSheet(
HighlightRuleEditSheet( show = show && state.showNewRule,
show = true, rule = null,
rule = null, onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) },
onDismissRequest = { onIntent(ReadBookIntent.DismissHighlightRuleEdit) }, onSave = { newRule ->
onSave = { newRule -> onIntent(ReadBookIntent.SaveHighlightRule(newRule))
onIntent(ReadBookIntent.SaveHighlightRule(newRule)) },
}, )
)
}
// Delete confirmation // Delete confirmation
val deletingRule = state.deleteRule val deletingRule = state.deleteRule
@@ -83,16 +83,14 @@ fun ShadowSetSheet(
} }
} }
if (showColorPicker) { ColorPickerSheet(
ColorPickerSheet( show = showColorPicker,
show = true, initialColor = shadowColor,
initialColor = shadowColor, onDismissRequest = { showColorPicker = false },
onDismissRequest = { showColorPicker = false }, onColorSelected = { color ->
onColorSelected = { color -> shadowColor = color
shadowColor = color onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.ShadowColor(color)))
onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.ShadowColor(color))) showColorPicker = false
showColorPicker = false },
}, )
)
}
} }
@@ -150,26 +150,24 @@ internal fun SystemMenuPage(
} }
// Floating sheets // Floating sheets
if (showColorPicker) { ColorPickerSheet(
ColorPickerSheet( show = showColorPicker,
show = true, initialColor = colorPickerInitial,
initialColor = colorPickerInitial, onDismissRequest = { showColorPicker = false },
onDismissRequest = { showColorPicker = false }, onColorSelected = { color ->
onColorSelected = { color -> when (colorPickerId) {
when (colorPickerId) { COLOR_BG -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColor(color)))
COLOR_BG -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColor(color))) COLOR_MENU_ACCENT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColor(color)))
COLOR_MENU_ACCENT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColor(color))) COLOR_MENU_CONTAINER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColor(color)))
COLOR_MENU_CONTAINER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColor(color))) COLOR_BG_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColorNight(color)))
COLOR_BG_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuBgColorNight(color))) COLOR_MENU_ACCENT_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColorNight(color)))
COLOR_MENU_ACCENT_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuAccentColorNight(color))) COLOR_MENU_CONTAINER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColorNight(color)))
COLOR_MENU_CONTAINER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.MenuContainerColorNight(color))) COLOR_BORDER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColor(color)))
COLOR_BORDER -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColor(color))) COLOR_BORDER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColorNight(color)))
COLOR_BORDER_NIGHT -> onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.BorderColorNight(color))) }
} showColorPicker = false
showColorPicker = false },
}, )
)
}
BottomBarIconSheet( BottomBarIconSheet(
show = showIconSheet, show = showIconSheet,
@@ -381,25 +381,23 @@ internal fun TextEffectsPage(
} }
// Color picker // Color picker
if (showColorPicker) { ColorPickerSheet(
ColorPickerSheet( show = showColorPicker,
show = true, initialColor = colorPickerInitial,
initialColor = colorPickerInitial, onDismissRequest = { showColorPicker = false },
onDismissRequest = { showColorPicker = false }, onColorSelected = { color ->
onColorSelected = { color -> when (colorPickerId) {
when (colorPickerId) { COLOR_TEXT -> {
COLOR_TEXT -> { onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextColor(color)))
onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextColor(color)))
}
COLOR_ACCENT -> {
onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextAccentColor(color)))
}
} }
showColorPicker = false
}, COLOR_ACCENT -> {
) onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TextAccentColor(color)))
} }
}
showColorPicker = false
},
)
} }
// ========== Title Settings (sub-page) ========== // ========== Title Settings (sub-page) ==========
@@ -527,19 +525,17 @@ internal fun TitleSettingsPage(
} }
// Color picker // Color picker
if (showColorPicker) { ColorPickerSheet(
ColorPickerSheet( show = showColorPicker,
show = true, initialColor = colorPickerInitial,
initialColor = colorPickerInitial, onDismissRequest = { showColorPicker = false },
onDismissRequest = { showColorPicker = false }, onColorSelected = { color ->
onColorSelected = { color -> when (colorPickerId) {
when (colorPickerId) { COLOR_TITLE -> {
COLOR_TITLE -> { onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TitleColor(color)))
onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.TitleColor(color)))
}
} }
showColorPicker = false }
}, showColorPicker = false
) },
} )
} }
@@ -146,16 +146,14 @@ fun UnderlineConfigSheet(
} }
// Color picker // Color picker
if (showColorPicker) { ColorPickerSheet(
ColorPickerSheet( show = showColorPicker,
show = true, initialColor = underlineColor,
initialColor = underlineColor, onDismissRequest = { showColorPicker = false },
onDismissRequest = { showColorPicker = false }, onColorSelected = { color ->
onColorSelected = { color -> underlineColor = color
underlineColor = color onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.UnderlineColor(color)))
onIntent(ReadBookIntent.UpdateConfig(ConfigUpdate.UnderlineColor(color))) showColorPicker = false
showColorPicker = false },
}, )
)
}
} }