From 41148e39245d3702f41a0baf7245b082df50fb64 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 1 Jan 2021 17:17:58 +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/src/main/java/io/legado/app/model/webBook/PreciseSearch.kt | 3 +++ .../java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app/src/main/java/io/legado/app/model/webBook/PreciseSearch.kt b/app/src/main/java/io/legado/app/model/webBook/PreciseSearch.kt index 1615d57cc..31d08314c 100644 --- a/app/src/main/java/io/legado/app/model/webBook/PreciseSearch.kt +++ b/app/src/main/java/io/legado/app/model/webBook/PreciseSearch.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() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index 6c2d29c23..e2e1b50e3 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -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>(json)?.forEach { + if (!isActive) return@execute val name = it["name"] ?: "" val author = it["author"] ?: "" if (name.isNotEmpty() && App.db.bookDao.getBook(name, author) == null) {