From 502f7fbe123350f2bb3ee3bf5cf2298794955e1e Mon Sep 17 00:00:00 2001 From: HapeLee <63206378+HapeLee@users.noreply.github.com> Date: Wed, 17 Jun 2026 23:27:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=9C=E8=89=B2?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E9=9D=9E=E6=B3=95=E6=97=B6=20Color.?= =?UTF-8?q?parseColor=20=E5=B4=A9=E6=BA=83=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ensureColorInts 和 ensureAccentColorInts 中对 toColorInt() 加 try-catch 保护, 解析失败时回退到字段默认值,避免数据库中存储损坏颜色字符串导致崩溃 --- .../legado/app/help/config/ReadBookConfig.kt | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index 7307d22a8..86e3f97b7 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt @@ -1141,21 +1141,25 @@ object ReadBookConfig { } } + private fun String.toColorIntSafe(fallback: Int): Int { + return runCatching { toColorInt() }.getOrDefault(fallback) + } + private fun ensureColorInts() { if (initColorInt) { return } - textColorIntEInk = textColorEInk.toColorInt() - textColorIntNight = textColorNight.toColorInt() - textColorInt = textColor.toColorInt() - shadowColorNightInt = shadowColorN.toColorInt() - shadowColorInt = shadowColor.toColorInt() - menuBgColorInt = menuBgColor.toColorInt() - menuBgColorNightInt = menuBgColorNight.toColorInt() - menuAcColorInt = menuAcColor.toColorInt() - menuAcColorNightInt = menuAcColorNight.toColorInt() - underlineColorInt = underlineColor.toColorInt() - underlineColorNightInt = underlineColorNight.toColorInt() + textColorIntEInk = textColorEInk.toColorIntSafe(0xFF000000.toInt()) + textColorIntNight = textColorNight.toColorIntSafe(0xFFADADAD.toInt()) + textColorInt = textColor.toColorIntSafe(0xFF3E3D3B.toInt()) + shadowColorNightInt = shadowColorN.toColorIntSafe(0xFF3E3D3B.toInt()) + shadowColorInt = shadowColor.toColorIntSafe(0xFF3E3D3B.toInt()) + menuBgColorInt = menuBgColor.toColorIntSafe(-1) + menuBgColorNightInt = menuBgColorNight.toColorIntSafe(-1) + menuAcColorInt = menuAcColor.toColorIntSafe(-1) + menuAcColorNightInt = menuAcColorNight.toColorIntSafe(-1) + underlineColorInt = underlineColor.toColorIntSafe(0xFF3E3D3B.toInt()) + underlineColorNightInt = underlineColorNight.toColorIntSafe(0xFFADADAD.toInt()) initColorInt = true } @@ -1163,9 +1167,9 @@ object ReadBookConfig { if (initAccentColorInt) { return } - textAccentColorIntEInk = textAccentColorEInk.toColorInt() - textAccentColorIntNight = textAccentColorNight.toColorInt() - textAccentColorInt = textAccentColor.toColorInt() + textAccentColorIntEInk = textAccentColorEInk.toColorIntSafe(0xFF000000.toInt()) + textAccentColorIntNight = textAccentColorNight.toColorIntSafe(0xFFFE4D55.toInt()) + textAccentColorInt = textAccentColor.toColorIntSafe(0xFF834E00.toInt()) initAccentColorInt = true }