Преглед на файлове

fix: 修复 BgTextConfigSheet 中 Color.parseColor 崩溃问题

当 bgStr/bgStrNight 为空字符串或非法颜色值时,toColorInt() 会抛出
IllegalArgumentException: Unknown color。使用 runCatching 包裹并提供
合理的默认值(日间 #EEEEEE,夜间 #000000)。
HapeLee преди 5 месеца
родител
ревизия
40cb04dfab
променени са 1 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 6 2
      app/src/main/java/io/legado/app/ui/book/read/sheet/BgTextConfigSheet.kt

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

@@ -62,8 +62,12 @@ fun BgTextConfigSheet(
     val styleName = styleConfig.styleName
     val darkStatusIcon = styleConfig.darkStatusIcon
     val bgAlpha = styleConfig.bgAlpha
-    val dayBgColor = if (styleConfig.bgType == 0) styleConfig.bgStr.toColorInt() else 0
-    val nightBgColor = if (styleConfig.bgTypeNight == 0) styleConfig.bgStrNight.toColorInt() else 0
+    val dayBgColor = if (styleConfig.bgType == 0) {
+        runCatching { styleConfig.bgStr.toColorInt() }.getOrDefault(0xFFEEEEEE.toInt())
+    } else 0
+    val nightBgColor = if (styleConfig.bgTypeNight == 0) {
+        runCatching { styleConfig.bgStrNight.toColorInt() }.getOrDefault(0xFF000000.toInt())
+    } else 0
     val dayBgImage = if (styleConfig.bgType != 0) styleConfig.bgStr else null
     val nightBgImage = if (styleConfig.bgTypeNight != 0) styleConfig.bgStrNight else null