From c094fb991c61bc0687b35e7c3603424a432c2b40 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 25 Feb 2022 15:12:21 +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 | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 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 c7e820518..781e554a9 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 @@ -14,6 +14,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource import io.legado.app.help.BookHelp import io.legado.app.help.coroutine.Coroutine +import io.legado.app.model.NoStackTraceException import io.legado.app.model.ReadBook import io.legado.app.model.localBook.LocalBook import io.legado.app.model.webBook.WebBook @@ -36,16 +37,24 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { val name = intent.getStringExtra("name") ?: "" val author = intent.getStringExtra("author") ?: "" val bookUrl = intent.getStringExtra("bookUrl") ?: "" - appDb.bookDao.getBook(name, author)?.let { book -> + appDb.bookDao.getBook(name, author)?.let { inBookshelf = true - setBook(book) - } ?: let { - val searchBook = appDb.searchBookDao.getSearchBook(bookUrl) - ?: appDb.searchBookDao.getFirstByNameAuthor(name, author) - searchBook?.toBook()?.let { book -> - setBook(book) + setBook(it) + return@execute + } + if (bookUrl.isNotBlank()) { + appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()?.let { + setBook(it) + return@execute } } + appDb.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let { + setBook(it) + return@execute + } + throw NoStackTraceException("未找到书籍") + }.onError { + context.toastOnUi(it.localizedMessage) } }