From dee96f874f1a51f56c0674cec4ffba3913332fed Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Thu, 19 Aug 2021 01:54:20 -0400 Subject: [PATCH] fix the last source stop checking by itself --- app/src/main/java/io/legado/app/model/Debug.kt | 9 ++++++--- .../java/io/legado/app/service/CheckSourceService.kt | 8 +++----- .../app/ui/book/source/manage/BookSourceActivity.kt | 5 ++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index b696a108f..275f38c67 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -11,11 +11,9 @@ import io.legado.app.utils.HtmlFormatter import io.legado.app.utils.isAbsUrl import io.legado.app.utils.msg import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.flow import java.text.SimpleDateFormat import java.util.* import java.util.concurrent.ConcurrentHashMap -import kotlin.collections.ArrayList object Debug { var callback: Callback? = null @@ -48,10 +46,10 @@ object Debug { printMsg = "$time $printMsg" } it.printLog(state, printMsg) - Log.d(EventBus.CHECK_SOURCE_MESSAGE, "debugMessage to filter $printMsg") if (sourceUrl != null && printMsg.length < 30) { debugMessageMap[sourceUrl] = printMsg callback?.printCheckSourceMessage(sourceUrl, printMsg) + Log.d(EventBus.CHECK_SOURCE_MESSAGE, "debugMessage after filter $printMsg") } } } @@ -76,6 +74,11 @@ object Debug { debugMessageMap[source.bookSourceUrl] = "开始校验" } + fun finishChecking() { + callback = null + isChecking = false + } + fun startDebug(scope: CoroutineScope, rssSource: RssSource) { cancelDebug() debugSource = rssSource.sourceUrl 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 900825709..d9293cfca 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -37,7 +37,7 @@ class CheckSourceService : BaseService() { @Synchronized override fun printCheckSourceMessage(sourceUrl: String, msg: String) { postEvent(EventBus.CHECK_SOURCE_MESSAGE, Pair(sourceUrl, null)) - Log.d(EventBus.CHECK_SOURCE_MESSAGE, "printCheckSourceMessage to post $msg") + Log.d(EventBus.CHECK_SOURCE_MESSAGE, "printCheckSourceMessage to post $sourceUrl $msg") } } private val notificationBuilder by lazy { @@ -77,8 +77,6 @@ class CheckSourceService : BaseService() { super.onDestroy() tasks.clear() searchCoroutine.close() - Debug.callback = null - Debug.isChecking = false postEvent(EventBus.CHECK_SOURCE_DONE, 0) } @@ -112,7 +110,6 @@ class CheckSourceService : BaseService() { if (index < allIds.size) { val sourceUrl = allIds[index] appDb.bookSourceDao.getBookSource(sourceUrl)?.let { source -> - Debug.startChecking(source) check(source) } ?: onNext(sourceUrl, "") } @@ -121,6 +118,7 @@ class CheckSourceService : BaseService() { fun check(source: BookSource) { execute(context = searchCoroutine) { + Debug.startChecking(source) val webBook = WebBook(source) var books = webBook.searchBookAwait(this, CheckSource.keyword) if (books.isEmpty()) { @@ -181,7 +179,7 @@ class CheckSourceService : BaseService() { notificationMsg = getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) upNotification() - if (processIndex >= allIds.size + threadCount - 1) { + if (processIndex > allIds.size + threadCount - 1) { stopSelf() } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 7e3d3bf64..46f76a628 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -440,6 +440,7 @@ class BookSourceActivity : VMBaseActivity(EventBus.CHECK_SOURCE_DONE) { adapter.notifyItemRangeChanged(0, adapter.itemCount, bundleOf(Pair("checkSourceDone", null))) snackBar?.dismiss() + Debug.finishChecking() snackBar = null // groups.map { group -> // if (group.contains("失效")) { @@ -451,12 +452,10 @@ class BookSourceActivity : VMBaseActivity>(EventBus.CHECK_SOURCE_MESSAGE) { messagePair -> sourceFlowJob?.cancel() sourceFlowJob = launch { - var index: Int = -1 appDb.bookSourceDao.flowSearch(messagePair.first) .map { adapter.getItems().indexOf(it[0]) } .collect { - index = it - adapter.notifyItemChanged(index, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, messagePair.second))) } + adapter.notifyItemChanged(it, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, messagePair.second))) } }