From d09a530c0d1d5c1c68ebb8799331d0de9f2fdcee Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 2 May 2020 19:53:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/CheckSourceService.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index 8cbd80afd..896e7bb75 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -20,7 +20,7 @@ import java.util.concurrent.Executors import kotlin.math.min class CheckSourceService : BaseService() { - private val threadCount = AppConfig.threadCount + private var threadCount = AppConfig.threadCount private var searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher() private var tasks = CompositeCoroutine() private val allIds = ArrayList() @@ -58,20 +58,24 @@ class CheckSourceService : BaseService() { checkedIds.clear() allIds.addAll(ids) processIndex = 0 + threadCount = min(allIds.size, threadCount) updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) - for (i in 0 until min(threadCount, allIds.size)) { + for (i in 0 until threadCount) { check() } } - + /** + * 检测 + */ private fun check() { + val index = processIndex synchronized(this) { processIndex++ } execute { - if (processIndex < allIds.size) { - val sourceUrl = allIds[processIndex] + if (index < allIds.size) { + val sourceUrl = allIds[index] App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> if (source.searchUrl.isNullOrEmpty()) { onNext(sourceUrl) @@ -102,7 +106,7 @@ class CheckSourceService : BaseService() { checkedIds.size, getString(R.string.progress_show, checkedIds.size, allIds.size) ) - if (processIndex >= allIds.size + min(threadCount, allIds.size) - 1) { + if (processIndex >= allIds.size + threadCount - 1) { stopSelf() } }