Skip to content

Commit

Permalink
🛠️ Fix IndexOutOfBounds crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Acclorite committed Jan 2, 2025
1 parent 386ada6 commit 71e5e67
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/ua/acclorite/book_story/ui/reader/ReaderModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,18 @@ class ReaderModel @Inject constructor(
}

private fun findCurrentChapter(index: Int): Chapter? {
for (textIndex in index downTo 0) {
val readerText = _state.value.text[textIndex]
if (readerText is Chapter) {
return readerText
return try {
for (textIndex in index downTo 0) {
val readerText = _state.value.text.getOrNull(textIndex) ?: break
if (readerText is Chapter) {
return readerText
}
}
null
} catch (e: Exception) {
e.printStackTrace()
null
}
return null
}

private fun calculateProgress(firstVisibleItemIndex: Int? = null): Float {
Expand Down

0 comments on commit 71e5e67

Please sign in to comment.