From c2f314cf99adab9bde62f8dce4df49f9e567b4de Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 18 Feb 2020 15:24:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/service/DownloadService.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index f8a03d2ea..9d1428317 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -18,6 +18,7 @@ import io.legado.app.model.WebBook import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher +import kotlinx.coroutines.isActive import org.jetbrains.anko.toast import java.util.concurrent.Executors @@ -93,12 +94,14 @@ class DownloadService : BaseService() { private fun download() { val task = Coroutine.async(this, context = searchPool) { downloadMap.forEach { entry -> + if (!isActive) return@async if (!finalMap.containsKey(entry.key)) { val book = App.db.bookDao().getBook(entry.key) ?: return@async val bookSource = App.db.bookSourceDao().getBookSource(book.origin) ?: return@async val webBook = WebBook(bookSource) entry.value.forEach { chapter -> + if (!isActive) return@async if (!BookHelp.hasContent(book, chapter)) { webBook.getContent(book, chapter, scope = this, context = searchPool) .onStart {