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 c0f1e9411..b5a851298 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 @@ -328,6 +328,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea observeEvent(Bus.TTS_RANGE_START) {} observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } + observeEvent(Bus.OPEN_CHAPTER) { viewModel.openChapter(it) } observeEventSticky(Bus.READ_ALOUD) { onClickReadAloud() } observeEventSticky(Bus.UP_CONFIG) { when (it) { 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 c1c6dc7a5..818f50810 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 @@ -169,6 +169,23 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } + fun openChapter(chapter: BookChapter) { + if (chapter.index != durChapterIndex) { + durChapterIndex = chapter.index + durPageIndex = 0 + } + callBack?.bookLoadFinish() + } + + fun saveRead() { + execute { + bookData.value?.let { book -> + book.durChapterIndex = durChapterIndex + book.durChapterPos = durPageIndex + } + } + } + override fun onCleared() { super.onCleared() ReadAloudService.stop(context)