Procházet zdrojové kódy

修复可能出现的崩溃问题

HapeLee před 1 rokem
rodič
revize
24714d86fa

+ 8 - 3
app/src/main/java/io/legato/kazusa/ui/book/read/page/entities/TextPage.kt

@@ -291,10 +291,10 @@ data class TextPage(
      * @return
      */
     fun containPos(chapterPos: Int): Boolean {
-        val line = lines.first()
+        val line = lines.firstOrNull() ?: return false // lines 为空时直接返回 false
         val startPos = line.chapterPosition
         val endPos = startPos + charSize
-        return chapterPos in startPos..<endPos
+        return chapterPos in startPos until endPos
     }
 
     fun draw(view: ContentTextView, canvas: Canvas, relativeOffset: Float) {
@@ -364,10 +364,15 @@ data class TextPage(
     }
 
     fun upRenderHeight() {
+        if (lines.isEmpty()) {
+            renderHeight = 0
+            return
+        }
         renderHeight = ceil(lines.last().lineBottom).toInt()
-        if (leftLineSize > 0 && leftLineSize != lines.size) {
+        if (leftLineSize > 0 && leftLineSize <= lines.size) {
             val leftHeight = ceil(lines[leftLineSize - 1].lineBottom).toInt()
             renderHeight = max(renderHeight, leftHeight)
         }
     }
+
 }