pull/32/head
kunfei 5 years ago
parent ce60781a3f
commit 1eab69c288
  1. 12
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt

@ -53,8 +53,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
isLoadingData.postValue(true)
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
WebBook(bookSource).getBookInfo(book, this)
.onSuccess {
it?.let { loadChapter(it) }
.onSuccess(IO) {
it?.let {
if (inBookshelf) {
App.db.bookDao().update(book)
}
loadChapter(it)
}
}.onError {
toast(R.string.error_get_book_info)
}
@ -62,7 +67,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
}
fun loadChapter(book: Book) {
private fun loadChapter(book: Book) {
execute {
isLoadingData.postValue(true)
App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource ->
@ -71,6 +76,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
it?.let {
if (it.isNotEmpty()) {
if (inBookshelf) {
App.db.bookDao().update(book)
App.db.bookChapterDao().insert(*it.toTypedArray())
}
chapterListData.postValue(it)

Loading…
Cancel
Save