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. 21
      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,14 +48,20 @@ 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 ->
webBook?.getContent(book, chapter) BookHelp.getContent(book, chapter)?.let {
?.onSuccess(IO) { content ->
content?.let { } ?: download(book, chapter)
BookHelp.saveContent(book, chapter, it)
}
}
} }
} }
private fun download(book: Book, chapter: BookChapter) {
webBook?.getContent(book, chapter)
?.onSuccess(IO) { content ->
content?.let {
BookHelp.saveContent(book, chapter, it)
}
}
}
} }
Loading…
Cancel
Save