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

Loading…
Cancel
Save