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)