pull/783/head
gedoor 4 years ago
parent c6e65c5c29
commit 41148e3924
  1. 3
      app/src/main/java/io/legado/app/model/webBook/PreciseSearch.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@ -3,6 +3,7 @@ package io.legado.app.model.webBook
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.isActive
/**
* 精准搜索
@ -18,10 +19,12 @@ object PreciseSearch {
bookSources.forEach { bookSource ->
val webBook = WebBook(bookSource)
kotlin.runCatching {
if (!scope.isActive) return null
webBook.searchBookAwait(scope, name).firstOrNull {
it.name == name && it.author == author
}?.let {
return if (it.tocUrl.isBlank()) {
if (!scope.isActive) return null
webBook.getBookInfoAwait(scope, it.toBook())
} else {
it.toBook()

@ -11,6 +11,7 @@ import io.legado.app.model.webBook.PreciseSearch
import io.legado.app.model.webBook.WebBook
import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.isActive
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toText
@ -105,6 +106,7 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application)
execute {
val bookSources = App.db.bookSourceDao.allEnabled
GSON.fromJsonArray<Map<String, String?>>(json)?.forEach {
if (!isActive) return@execute
val name = it["name"] ?: ""
val author = it["author"] ?: ""
if (name.isNotEmpty() && App.db.bookDao.getBook(name, author) == null) {

Loading…
Cancel
Save