From 1eab69c288ea85d7bca5a6b539818f49c82d7518 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 30 Aug 2019 12:21:49 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/bookinfo/BookInfoViewModel.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index 7b6c093bd..01308e15f 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/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)