From f9c1183580307f582f3557c874e178cd3971d2da Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 28 Feb 2020 19:24:16 +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 --- .../legado/app/service/CheckSourceService.kt | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 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 67874f9e4..d94b3a6d1 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -21,8 +21,8 @@ class CheckSourceService : BaseService() { private var searchPool = Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null - private var idsCount = 0 - private val unCheckIds = LinkedHashSet() + private val allIds = LinkedHashSet() + private val checkedIds = LinkedHashSet() override fun onCreate() { super.onCreate() @@ -47,12 +47,12 @@ class CheckSourceService : BaseService() { private fun check(ids: List) { task?.cancel() - unCheckIds.clear() - idsCount = ids.size - unCheckIds.addAll(ids) - updateNotification(0, getString(R.string.progress_show, 0, idsCount)) - task = execute { - unCheckIds.forEach { sourceUrl -> + allIds.clear() + checkedIds.clear() + allIds.addAll(ids) + updateNotification(0, getString(R.string.progress_show, 0, allIds.size)) + task = execute(context = searchPool) { + allIds.forEach { sourceUrl -> App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> val webBook = WebBook(source) webBook.searchBook("我的", scope = this, context = searchPool) @@ -60,11 +60,10 @@ class CheckSourceService : BaseService() { source.addGroup("失效") App.db.bookSourceDao().update(source) }.onFinally { - unCheckIds.remove(sourceUrl) - val checkedCount = idsCount - unCheckIds.size + checkedIds.add(sourceUrl) updateNotification( - checkedCount, - getString(R.string.progress_show, checkedCount, idsCount) + checkedIds.size, + getString(R.string.progress_show, checkedIds.size, allIds.size) ) } } @@ -95,7 +94,7 @@ class CheckSourceService : BaseService() { getString(R.string.cancel), IntentHelp.servicePendingIntent(this, IntentAction.stop) ) - builder.setProgress(idsCount, state, false) + builder.setProgress(allIds.size, state, false) builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) val notification = builder.build() startForeground(112202, notification)