diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index f1805c6bd..85de3fc04 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -97,6 +97,44 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } + fun moveToNextChapter() { + durChapterIndex++ + prevTextChapter = curTextChapter + curTextChapter = nextTextChapter + nextTextChapter = null + bookData.value?.let { + loadContent(it, durChapterIndex) + loadContent(it, durChapterIndex.plus(1)) + launch(IO) { + for (i in 2..10) { + delay(100) + bookData.value?.let { book -> + download(book, durChapterIndex + i) + } + } + } + } + } + + fun moveToPrevChapter() { + durChapterIndex-- + nextTextChapter = curTextChapter + curTextChapter = prevTextChapter + prevTextChapter = null + bookData.value?.let { + loadContent(it, durChapterIndex) + loadContent(it, durChapterIndex.minus(1)) + launch(IO) { + for (i in -5..-2) { + delay(100) + bookData.value?.let { book -> + download(book, durChapterIndex + i) + } + } + } + } + } + fun loadContent(book: Book, index: Int) { synchronized(loadingLock) { if (loadingChapters.contains(index)) return @@ -230,42 +268,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - fun moveToNextChapter() { - durChapterIndex++ - prevTextChapter = curTextChapter - curTextChapter = nextTextChapter - nextTextChapter = null - bookData.value?.let { - loadContent(it, durChapterIndex.plus(1)) - launch(IO) { - for (i in 2..10) { - delay(100) - bookData.value?.let { book -> - download(book, durChapterIndex + i) - } - } - } - } - } - - fun moveToPrevChapter() { - durChapterIndex-- - nextTextChapter = curTextChapter - curTextChapter = prevTextChapter - prevTextChapter = null - bookData.value?.let { - loadContent(it, durChapterIndex.minus(1)) - launch(IO) { - for (i in -5..-2) { - delay(100) - bookData.value?.let { book -> - download(book, durChapterIndex + i) - } - } - } - } - } - fun refreshContent(book: Book) { execute { App.db.bookChapterDao().getChapter(book.bookUrl, durChapterIndex)?.let { chapter ->