🛠️ 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? { private fun findCurrentChapter(index: Int): Chapter? {
for (textIndex in index downTo 0) { return try {
val readerText = _state.value.text[textIndex] for (textIndex in index downTo 0) {
if (readerText is Chapter) { val readerText = _state.value.text.getOrNull(textIndex) ?: break
return readerText if (readerText is Chapter) {
return readerText
}
} }
null
} catch (e: Exception) {
e.printStackTrace()
null
} }
return null
} }
private fun calculateProgress(firstVisibleItemIndex: Int? = null): Float { private fun calculateProgress(firstVisibleItemIndex: Int? = null): Float {