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()
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<ReadBookViewModel>(R.layout.activity_rea
}
}
override fun bookLoadFinish() {
fun bookLoadFinish() {
viewModel.bookData.value?.let {
viewModel.loadContent(it, viewModel.durChapterIndex)
viewModel.loadContent(it, viewModel.durChapterIndex + 1)

@ -19,6 +19,7 @@ import kotlinx.coroutines.Dispatchers.IO
class ReadBookViewModel(application: Application) : BaseViewModel(application) {
var inBookshelf = false
var bookData = MutableLiveData<Book>()
val chapterListFinish = MutableLiveData<Boolean>()
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)
}
}
Loading…
Cancel
Save