pull/1738/head
kunfei 3 years ago
parent 694389ca2e
commit 7a03b2f980
  1. 33
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -70,23 +70,13 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
} }
private suspend fun setBook(book: Book) { private fun setBook(book: Book) {
execute {
durChapterIndex = book.durChapterIndex durChapterIndex = book.durChapterIndex
bookData.postValue(book) bookData.postValue(book)
if (book.customCoverUrl.isNullOrBlank()) { upCoverByRule(book)
BookCover.searchCover(book)?.let { coverUrl -> bookSource = if (book.isLocalBook()) null else
book.customCoverUrl = coverUrl
bookData.postValue(book)
if (inBookshelf) {
saveBook(book)
}
}
}
bookSource = if (book.isLocalBook()) {
null
} else {
appDb.bookSourceDao.getBookSource(book.origin) appDb.bookSourceDao.getBookSource(book.origin)
}
if (book.tocUrl.isEmpty()) { if (book.tocUrl.isEmpty()) {
loadBookInfo(book) loadBookInfo(book)
} else { } else {
@ -98,6 +88,21 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
} }
} }
} }
}
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)
}
}
}
}
}
fun loadBookInfo( fun loadBookInfo(
book: Book, book: Book,

Loading…
Cancel
Save