From 4e33e262ff271b57345f678137332552f7883fd9 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Fri, 20 Aug 2021 17:00:31 -0400 Subject: [PATCH] =?UTF-8?q?snack=20bar=20=E5=8F=96=E6=B6=88=E6=97=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/model/Debug.kt | 8 ++++++++ .../java/io/legado/app/service/CheckSourceService.kt | 5 +++-- .../app/ui/book/source/manage/BookSourceActivity.kt | 5 ++++- .../app/ui/book/source/manage/BookSourceAdapter.kt | 9 +++++++-- 4 files changed, 22 insertions(+), 5 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 36a9ff22d..e30373143 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -87,6 +87,14 @@ object Debug { isChecking = false } + fun updateFinalMessage(sourceUrl: String, state: String) { + if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) { + val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!)) + val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ") + debugMessageMap[sourceUrl] = "$time $originalMessage $state" + } + } + 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 945f0eda3..66fcf24fc 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -65,6 +65,7 @@ class CheckSourceService : BaseService() { override fun onDestroy() { super.onDestroy() + Debug.finishChecking() tasks.clear() searchCoroutine.close() postEvent(EventBus.CHECK_SOURCE_DONE, 0) @@ -141,7 +142,7 @@ class CheckSourceService : BaseService() { ${source.bookSourceComment}" """.trimIndent() if (showCheckSourceMessage) { - Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 失败" + Debug.updateFinalMessage(source.bookSourceUrl, "失败") } appDb.bookSourceDao.update(source) }.onSuccess(searchCoroutine) { @@ -152,7 +153,7 @@ class CheckSourceService : BaseService() { it.startsWith("error:") }?.joinToString("\n") if (showCheckSourceMessage) { - Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 成功" + Debug.updateFinalMessage(source.bookSourceUrl, "成功") } appDb.bookSourceDao.update(source) }.onFinally(searchCoroutine) { 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 108aaa387..b16753e0a 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 @@ -435,11 +435,14 @@ class BookSourceActivity : VMBaseActivity(EventBus.CHECK_SOURCE_DONE) { - Debug.finishChecking() snackBar?.dismiss() snackBar = null groups.map { group -> diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 4a20c7818..6b5b8e845 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -118,11 +118,16 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : "checkSourceMessage" -> { ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" val isEmpty = ivDebugText.text.toString().isEmpty() + var isFinalMessage = ivDebugText.text.toString().contains(Regex("成功|失败")) + if (!isEmpty && !Debug.isChecking && !isFinalMessage){ + Debug.updateFinalMessage(item.bookSourceUrl, "失败") + ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" + isFinalMessage = true + } ivDebugText.visibility = if (!isEmpty) View.VISIBLE else View.GONE ivProgressBar.visibility = - if (ivDebugText.text.toString().contains(Regex("成功|失败")) || isEmpty) View.GONE - else View.VISIBLE + if (isFinalMessage || isEmpty) View.GONE else View.VISIBLE } } }