diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e4bc75603..994e103c1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -133,7 +133,9 @@ android:name=".ui.about.DonateActivity" android:launchMode="singleTask" /> - + @@ -144,7 +146,9 @@ - + @@ -159,7 +163,7 @@ + android:launchMode="singleTop"> @@ -171,16 +175,36 @@ android:scheme="yuedu" /> - - - - - - - - - - + + + + + + + + + + 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 d94b3a6d1..a19604ede 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -18,11 +18,12 @@ import org.jetbrains.anko.toast import java.util.concurrent.Executors class CheckSourceService : BaseService() { - private var searchPool = - Executors.newFixedThreadPool(AppConfig.threadCount).asCoroutineDispatcher() + private val threadCount = AppConfig.threadCount + private var searchPool = Executors.newFixedThreadPool(threadCount).asCoroutineDispatcher() private var task: Coroutine<*>? = null - private val allIds = LinkedHashSet() - private val checkedIds = LinkedHashSet() + private val allIds = ArrayList() + private val checkedIds = ArrayList() + private var processIndex = 0 override fun onCreate() { super.onCreate() @@ -50,30 +51,40 @@ class CheckSourceService : BaseService() { allIds.clear() checkedIds.clear() allIds.addAll(ids) + processIndex = 0 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) - .onError(IO) { - source.addGroup("失效") - App.db.bookSourceDao().update(source) - }.onFinally { - checkedIds.add(sourceUrl) - updateNotification( - checkedIds.size, - getString(R.string.progress_show, checkedIds.size, allIds.size) - ) - } - } + task = execute { + for (i in 0 until threadCount) { + check() } }.onError { toast("校验书源出错:${it.localizedMessage}") } + } + - task?.invokeOnCompletion { - stopSelf() + private fun check() { + processIndex++ + if (processIndex < allIds.size) { + val sourceUrl = allIds[processIndex] + + App.db.bookSourceDao().getBookSource(sourceUrl)?.let { source -> + val webBook = WebBook(source) + webBook.searchBook("我的", scope = this, context = searchPool) + .onError(IO) { + source.addGroup("失效") + App.db.bookSourceDao().update(source) + }.onFinally { + checkedIds.add(sourceUrl) + updateNotification( + checkedIds.size, + getString(R.string.progress_show, checkedIds.size, allIds.size) + ) + if (processIndex >= allIds.size + threadCount - 1) { + stopSelf() + } + } + } } }