diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 681829fc9..d6e91e91f 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -249,28 +249,20 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea * 内容加载完成 */ override fun contentLoadFinish(bookChapter: BookChapter, content: String) { - launch { - when (bookChapter.index) { - viewModel.durChapterIndex -> { - viewModel.curTextChapter = - ChapterProvider.getTextChapter(content_text_view, bookChapter, content) - page_view.upContent() - curChapterChanged() - } - viewModel.durChapterIndex - 1 -> { - viewModel.prevTextChapter = - ChapterProvider.getTextChapter(content_text_view, bookChapter, content) - } - viewModel.durChapterIndex + 1 -> { - viewModel.nextTextChapter = - ChapterProvider.getTextChapter(content_text_view, bookChapter, content) - viewModel.bookData.value?.let { - for (i in viewModel.durChapterIndex.plus(2) - ..viewModel.durChapterIndex.plus(8)) { - viewModel.download(it, i) - } - } - } + when (bookChapter.index) { + viewModel.durChapterIndex -> launch { + viewModel.curTextChapter = + ChapterProvider.getTextChapter(content_text_view, bookChapter, content) + page_view.upContent() + curChapterChanged() + } + viewModel.durChapterIndex - 1 -> launch { + viewModel.prevTextChapter = + ChapterProvider.getTextChapter(content_text_view, bookChapter, content) + } + viewModel.durChapterIndex + 1 -> launch { + viewModel.nextTextChapter = + ChapterProvider.getTextChapter(content_text_view, bookChapter, content) } } } 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 48bb7b1fe..bcb17f50c 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 @@ -101,7 +101,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { execute { App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> BookHelp.getContent(book, chapter)?.let { - callBack?.contentLoadFinish(chapter, it) + contentLoadFinish(chapter, it) synchronized(loadingLock) { loadingChapters.remove(index) } @@ -138,25 +138,31 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { webBook?.getContent(book, chapter, scope = this) ?.onSuccess(IO) { content -> if (content.isNullOrEmpty()) { - callBack?.contentLoadFinish(chapter, context.getString(R.string.content_empty)) + contentLoadFinish(chapter, context.getString(R.string.content_empty)) synchronized(loadingLock) { loadingChapters.remove(chapter.index) } } else { BookHelp.saveContent(book, chapter, content) - callBack?.contentLoadFinish(chapter, content) + contentLoadFinish(chapter, content) synchronized(loadingLock) { loadingChapters.remove(chapter.index) } } }?.onError { - callBack?.contentLoadFinish(chapter, it.localizedMessage) + contentLoadFinish(chapter, it.localizedMessage) synchronized(loadingLock) { loadingChapters.remove(chapter.index) } } } + private fun contentLoadFinish(chapter: BookChapter, content: String) { + if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { + callBack?.contentLoadFinish(chapter, content) + } + } + fun changeTo(book: Book) { execute { bookData.value?.let {