From 7a03b2f980f261264e7164339a8499a6e92d850e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 20 Mar 2022 12:01:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/info/BookInfoViewModel.kt | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index b257f5dc3..1ed56f4ac 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -70,31 +70,36 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } - private suspend fun setBook(book: Book) { - durChapterIndex = book.durChapterIndex - bookData.postValue(book) - if (book.customCoverUrl.isNullOrBlank()) { - BookCover.searchCover(book)?.let { coverUrl -> - book.customCoverUrl = coverUrl - bookData.postValue(book) - if (inBookshelf) { - saveBook(book) + private fun setBook(book: Book) { + execute { + durChapterIndex = book.durChapterIndex + bookData.postValue(book) + upCoverByRule(book) + bookSource = if (book.isLocalBook()) null else + appDb.bookSourceDao.getBookSource(book.origin) + if (book.tocUrl.isEmpty()) { + loadBookInfo(book) + } else { + val chapterList = appDb.bookChapterDao.getChapterList(book.bookUrl) + if (chapterList.isNotEmpty()) { + chapterListData.postValue(chapterList) + } else { + loadChapter(book) } } } - bookSource = if (book.isLocalBook()) { - null - } else { - appDb.bookSourceDao.getBookSource(book.origin) - } - if (book.tocUrl.isEmpty()) { - loadBookInfo(book) - } else { - val chapterList = appDb.bookChapterDao.getChapterList(book.bookUrl) - if (chapterList.isNotEmpty()) { - chapterListData.postValue(chapterList) - } else { - loadChapter(book) + } + + private fun upCoverByRule(book: Book) { + execute { + if (book.customCoverUrl.isNullOrBlank()) { + BookCover.searchCover(book)?.let { coverUrl -> + book.customCoverUrl = coverUrl + bookData.postValue(book) + if (inBookshelf) { + saveBook(book) + } + } } } }