pull/1649/head
kunfei 3 years ago
parent d534f67900
commit c094fb991c
  1. 23
      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.data.entities.BookSource
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.NoStackTraceException
import io.legado.app.model.ReadBook import io.legado.app.model.ReadBook
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.model.webBook.WebBook import io.legado.app.model.webBook.WebBook
@ -36,16 +37,24 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
val name = intent.getStringExtra("name") ?: "" val name = intent.getStringExtra("name") ?: ""
val author = intent.getStringExtra("author") ?: "" val author = intent.getStringExtra("author") ?: ""
val bookUrl = intent.getStringExtra("bookUrl") ?: "" val bookUrl = intent.getStringExtra("bookUrl") ?: ""
appDb.bookDao.getBook(name, author)?.let { book -> appDb.bookDao.getBook(name, author)?.let {
inBookshelf = true inBookshelf = true
setBook(book) setBook(it)
} ?: let { return@execute
val searchBook = appDb.searchBookDao.getSearchBook(bookUrl) }
?: appDb.searchBookDao.getFirstByNameAuthor(name, author) if (bookUrl.isNotBlank()) {
searchBook?.toBook()?.let { book -> appDb.searchBookDao.getSearchBook(bookUrl)?.toBook()?.let {
setBook(book) setBook(it)
return@execute
} }
} }
appDb.searchBookDao.getFirstByNameAuthor(name, author)?.toBook()?.let {
setBook(it)
return@execute
}
throw NoStackTraceException("未找到书籍")
}.onError {
context.toastOnUi(it.localizedMessage)
} }
} }

Loading…
Cancel
Save