From 86b954ea947f6ba9ae7e931e8c82b32f6b7f0178 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 22 Aug 2019 15:05:08 +0800 Subject: [PATCH] up --- .../legado/app/ui/readbook/ReadBookActivity.kt | 1 + .../legado/app/ui/readbook/ReadBookViewModel.kt | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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)