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