From ef52d442096d89266243f71a970f0f7d6888b2f4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 22 Aug 2019 20:15:08 +0800 Subject: [PATCH] up --- .../java/io/legado/app/ui/readbook/ReadBookActivity.kt | 3 ++- .../java/io/legado/app/ui/readbook/ReadBookViewModel.kt | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) 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 760b285c4..5b33ef5b6 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 @@ -55,6 +55,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea initView() viewModel.callBack = this viewModel.bookData.observe(this, Observer { title_bar.title = it.name }) + viewModel.chapterListFinish.observe(this, Observer { bookLoadFinish() }) viewModel.initData(intent) savedInstanceState?.let { changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog @@ -235,7 +236,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea } } - override fun bookLoadFinish() { + fun bookLoadFinish() { viewModel.bookData.value?.let { viewModel.loadContent(it, viewModel.durChapterIndex) viewModel.loadContent(it, viewModel.durChapterIndex + 1) 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 8c0c0c3cc..b3105599f 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 @@ -19,6 +19,7 @@ import kotlinx.coroutines.Dispatchers.IO class ReadBookViewModel(application: Application) : BaseViewModel(application) { var inBookshelf = false var bookData = MutableLiveData() + val chapterListFinish = MutableLiveData() var chapterSize = 0 var bookSource: BookSource? = null var webBook: WebBook? = null @@ -58,7 +59,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { durChapterIndex = count - 1 } chapterSize = count - callBack?.bookLoadFinish() + chapterListFinish.postValue(true) } } @@ -82,7 +83,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { if (!cList.isNullOrEmpty()) { App.db.bookChapterDao().insert(*cList.toTypedArray()) chapterSize = cList.size - callBack?.bookLoadFinish() + chapterListFinish.postValue(true) } else { toast(R.string.error_load_toc) } @@ -175,7 +176,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { durPageIndex = 0 } saveRead() - callBack?.bookLoadFinish() + chapterListFinish.postValue(true) } fun saveRead() { @@ -194,7 +195,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } interface CallBack { - fun bookLoadFinish() fun contentLoadFinish(bookChapter: BookChapter, content: String) } } \ No newline at end of file