pull/32/head
kunfei 5 years ago
parent 5d63e56aa8
commit 488df49270
  1. 2
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 11
      app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt

@ -7,6 +7,7 @@ import android.view.MenuItem
import android.view.animation.Animation import android.view.animation.Animation
import android.view.animation.AnimationUtils import android.view.animation.AnimationUtils
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
@ -39,6 +40,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
initAnimation() initAnimation()
initView() initView()
viewModel.chapterMaxIndex.observe(this, Observer { })
viewModel.initData(intent) viewModel.initData(intent)
savedInstanceState?.let { savedInstanceState?.let {
changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog changeSourceDialog = supportFragmentManager.findFragmentByTag(ChangeSourceDialog.tag) as? ChangeSourceDialog

@ -6,6 +6,7 @@ import androidx.lifecycle.MediatorLiveData
import io.legado.app.App import io.legado.app.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
@ -47,8 +48,15 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
fun download(book: Book, index: Int) { fun getContent(book: Book, index: Int) {
App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter -> App.db.bookChapterDao().getChapter(book.bookUrl, index)?.let { chapter ->
BookHelp.getContent(book, chapter)?.let {
} ?: download(book, chapter)
}
}
private fun download(book: Book, chapter: BookChapter) {
webBook?.getContent(book, chapter) webBook?.getContent(book, chapter)
?.onSuccess(IO) { content -> ?.onSuccess(IO) { content ->
content?.let { content?.let {
@ -56,5 +64,4 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
} }
}
} }
Loading…
Cancel
Save