This commit is contained in:
Horis 2024-02-26 18:12:23 +08:00
parent 64cc37bdb5
commit f632d3f936

View File

@ -288,21 +288,26 @@ object ReadBook : CoroutineScope by MainScope() {
}
fun setPageIndex(index: Int) {
val textChapter = curTextChapter
if (textChapter != null) {
val pageIndex = durPageIndex
if (index > pageIndex) {
textChapter.getPage(index - 2)?.recycleRecorders()
}
if (index < pageIndex) {
textChapter.getPage(index + 3)?.recycleRecorders()
}
}
recycleRecorders(durPageIndex, index)
durChapterPos = curTextChapter?.getReadLength(index) ?: index
saveRead(true)
curPageChanged(true)
}
fun recycleRecorders(beforeIndex: Int, afterIndex: Int) {
executor.execute {
val textChapter = curTextChapter
if (textChapter != null) {
if (afterIndex > beforeIndex) {
textChapter.getPage(afterIndex - 2)?.recycleRecorders()
}
if (afterIndex < beforeIndex) {
textChapter.getPage(afterIndex + 3)?.recycleRecorders()
}
}
}
}
fun openChapter(index: Int, durChapterPos: Int = 0, success: (() -> Unit)? = null) {
if (index < chapterSize) {
clearTextChapter()