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 ac969136e..202eb3c69 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 @@ -237,16 +237,23 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea override fun loadContentFinish(bookChapter: BookChapter, content: String) { launch { - if (viewModel.durChapterIndex == bookChapter.index) { - tv_chapter_name.text = bookChapter.title - tv_chapter_name.visible() - if (!viewModel.isLocalBook) { - tv_chapter_url.text = bookChapter.url - tv_chapter_url.visible() + when (bookChapter.index) { + viewModel.durChapterIndex -> { + tv_chapter_name.text = bookChapter.title + tv_chapter_name.visible() + if (!viewModel.isLocalBook) { + tv_chapter_url.text = bookChapter.url + tv_chapter_url.visible() + } + viewModel.curTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) + } + viewModel.durChapterIndex - 1 -> { + viewModel.prevTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) + } + viewModel.durChapterIndex + 1 -> { + viewModel.nextTextChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) } } - val textChapter = ChapterProvider.getTextChapter(content_text_view, bookChapter, content) - content_text_view.text = textChapter.pages[0].stringBuilder } } 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 978a06ab2..4c331cf46 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 @@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource import io.legado.app.help.BookHelp import io.legado.app.model.WebBook +import io.legado.app.ui.widget.page.TextChapter import kotlinx.coroutines.Dispatchers.IO class ReadBookViewModel(application: Application) : BaseViewModel(application) { @@ -24,6 +25,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { var callBack: CallBack? = null var durChapterIndex = 0 var isLocalBook = true + var prevTextChapter: TextChapter? = null + var curTextChapter: TextChapter? = null + var nextTextChapter: TextChapter? = null fun initData(intent: Intent) { val bookUrl = intent.getStringExtra("bookUrl") diff --git a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt index 8083b02ab..e0a675d15 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/ChapterProvider.kt @@ -29,7 +29,7 @@ object ChapterProvider { surplusText = surplusText.substring(textView.getCharNum()) pageIndex++ } - return TextChapter(bookChapter.index, textPages) + return TextChapter(bookChapter.index, bookChapter.title, textPages) } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt index b4414c19b..837f1b2da 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/TextChapter.kt @@ -1,3 +1,3 @@ package io.legado.app.ui.widget.page -data class TextChapter(val position: Int, val pages: List) +data class TextChapter(val position: Int, val title: String, val pages: List)