pull/32/head
kunfei 5 years ago
parent 1887ce05cb
commit ef52d44209
  1. 3
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -55,6 +55,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
initView() initView()
viewModel.callBack = this viewModel.callBack = this
viewModel.bookData.observe(this, Observer { title_bar.title = it.name }) viewModel.bookData.observe(this, Observer { title_bar.title = it.name })
viewModel.chapterListFinish.observe(this, Observer { bookLoadFinish() })
viewModel.initData(intent) viewModel.initData(intent)
savedInstanceState?.let { savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog
@ -235,7 +236,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
override fun bookLoadFinish() { fun bookLoadFinish() {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex) viewModel.loadContent(it, viewModel.durChapterIndex)
viewModel.loadContent(it, viewModel.durChapterIndex + 1) viewModel.loadContent(it, viewModel.durChapterIndex + 1)

@ -19,6 +19,7 @@ import kotlinx.coroutines.Dispatchers.IO
class ReadBookViewModel(application: Application) : BaseViewModel(application) { class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var inBookshelf = false var inBookshelf = false
var bookData = MutableLiveData<Book>() var bookData = MutableLiveData<Book>()
val chapterListFinish = MutableLiveData<Boolean>()
var chapterSize = 0 var chapterSize = 0
var bookSource: BookSource? = null var bookSource: BookSource? = null
var webBook: WebBook? = null var webBook: WebBook? = null
@ -58,7 +59,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
durChapterIndex = count - 1 durChapterIndex = count - 1
} }
chapterSize = count chapterSize = count
callBack?.bookLoadFinish() chapterListFinish.postValue(true)
} }
} }
@ -82,7 +83,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
if (!cList.isNullOrEmpty()) { if (!cList.isNullOrEmpty()) {
App.db.bookChapterDao().insert(*cList.toTypedArray()) App.db.bookChapterDao().insert(*cList.toTypedArray())
chapterSize = cList.size chapterSize = cList.size
callBack?.bookLoadFinish() chapterListFinish.postValue(true)
} else { } else {
toast(R.string.error_load_toc) toast(R.string.error_load_toc)
} }
@ -175,7 +176,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
durPageIndex = 0 durPageIndex = 0
} }
saveRead() saveRead()
callBack?.bookLoadFinish() chapterListFinish.postValue(true)
} }
fun saveRead() { fun saveRead() {
@ -194,7 +195,6 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
interface CallBack { interface CallBack {
fun bookLoadFinish()
fun contentLoadFinish(bookChapter: BookChapter, content: String) fun contentLoadFinish(bookChapter: BookChapter, content: String)
} }
} }
Loading…
Cancel
Save