From 61cfd284b76bd4380fcf59cc05e1c6d8c8f4e89c Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 27 Aug 2019 17:44:13 +0800 Subject: [PATCH] up --- .../app/ui/readbook/ReadBookViewModel.kt | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) 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 ->