🛠️ Fix IndexOutOfBounds crash
This commit is contained in:
parent
386ada6d88
commit
71e5e67156
1 changed files with 10 additions and 5 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue