diff --git a/app/src/main/java/io/legado/app/service/help/ReadBook.kt b/app/src/main/java/io/legado/app/service/help/ReadBook.kt index 0ab59ad5e..ba8f05a58 100644 --- a/app/src/main/java/io/legado/app/service/help/ReadBook.kt +++ b/app/src/main/java/io/legado/app/service/help/ReadBook.kt @@ -12,6 +12,7 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import io.legado.app.service.BaseReadAloudService import io.legado.app.ui.book.read.ReadBookViewModel +import io.legado.app.ui.widget.page.ChapterProvider import io.legado.app.ui.widget.page.TextChapter import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -204,6 +205,9 @@ object ReadBook { } } + /** + * 内容加载完成 + */ private fun contentLoadFinish(chapter: BookChapter, content: String) { Coroutine.async { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { @@ -214,7 +218,26 @@ object ReadBook { content, book!!.useReplaceRule ) - callBack?.contentLoadFinish(chapter, c) + when (chapter.index) { + durChapterIndex -> launch { + curTextChapter = ChapterProvider + .getTextChapter(chapter, c, chapterSize) + callBack?.upContent() + callBack?.curChapterChanged() + curPageChanged() + callBack?.contentLoadFinish() + } + durChapterIndex - 1 -> launch { + prevTextChapter = ChapterProvider + .getTextChapter(chapter, c, chapterSize) + callBack?.upContent(-1) + } + durChapterIndex + 1 -> launch { + nextTextChapter = ChapterProvider + .getTextChapter(chapter, c, chapterSize) + callBack?.upContent(1) + } + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 96933b672..5c542a70f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -254,43 +254,24 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } /** - * 加载章节内容, index章节序号 + * 内容加载完成 */ - override fun loadContent(index: Int) { - ReadBook.loadContent(index) + override fun contentLoadFinish() { + if (intent.getBooleanExtra("readAloud", false)) { + intent.removeExtra("readAloud") + ReadBook.readAloud() + } } /** - * 内容加载完成 + * 加载章节内容, index章节序号 */ - override fun contentLoadFinish(bookChapter: BookChapter, content: String) { - when (bookChapter.index) { - ReadBook.durChapterIndex -> launch { - ReadBook.curTextChapter = ChapterProvider - .getTextChapter(bookChapter, content, ReadBook.chapterSize) - page_view.upContent() - curChapterChanged() - ReadBook.curPageChanged() - if (intent.getBooleanExtra("readAloud", false)) { - intent.removeExtra("readAloud") - ReadBook.readAloud() - } - } - ReadBook.durChapterIndex - 1 -> launch { - ReadBook.prevTextChapter = ChapterProvider - .getTextChapter(bookChapter, content, ReadBook.chapterSize) - page_view.upContent(-1) - } - ReadBook.durChapterIndex + 1 -> launch { - ReadBook.nextTextChapter = ChapterProvider - .getTextChapter(bookChapter, content, ReadBook.chapterSize) - page_view.upContent(1) - } - } + override fun loadContent(index: Int) { + ReadBook.loadContent(index) } - override fun upContent() { - page_view.upContent() + override fun upContent(position: Int) { + page_view.upContent(position) } override fun curChapterChanged() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 9fb18014c..01c73dbd5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -202,9 +202,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { interface CallBack { fun loadContent() - fun contentLoadFinish(bookChapter: BookChapter, content: String) - fun upContent() + fun upContent(position: Int = 0) fun curChapterChanged() fun upPageProgress() + fun contentLoadFinish() } } \ No newline at end of file