🛠️ Fix IndexOutOfBounds crash

This commit is contained in:
Acclorite 2025-01-02 17:21:17 +02:00
parent 386ada6d88
commit 71e5e67156

View file

@ -560,13 +560,18 @@ class ReaderModel @Inject constructor(
}
private fun findCurrentChapter(index: Int): Chapter? {
return try {
for (textIndex in index downTo 0) {
val readerText = _state.value.text[textIndex]
val readerText = _state.value.text.getOrNull(textIndex) ?: break
if (readerText is Chapter) {
return readerText
}
}
return null
null
} catch (e: Exception) {
e.printStackTrace()
null
}
}
private fun calculateProgress(firstVisibleItemIndex: Int? = null): Float {