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)