From 8b6e925b861f95cc77960ce9e3024b01c2260259 Mon Sep 17 00:00:00 2001 From: Jason Yao Date: Mon, 7 Feb 2022 22:54:10 -0500 Subject: [PATCH] debug update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复spinner不正确显示 优化校验逻辑 优化校验修改注释 --- .../java/io/legado/app/model/CheckSource.kt | 12 ++++----- .../main/java/io/legado/app/model/Debug.kt | 27 +++++++++---------- .../legado/app/service/CheckSourceService.kt | 11 +++----- .../book/source/manage/BookSourceActivity.kt | 21 +++++++-------- .../book/source/manage/BookSourceAdapter.kt | 6 ++--- 5 files changed, 35 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/CheckSource.kt b/app/src/main/java/io/legado/app/model/CheckSource.kt index 5f1813402..d8016bf36 100644 --- a/app/src/main/java/io/legado/app/model/CheckSource.kt +++ b/app/src/main/java/io/legado/app/model/CheckSource.kt @@ -46,13 +46,13 @@ object CheckSource { CacheManager.put("checkContent", checkContent) } - fun upSummary(): String { + private fun upSummary(): String { var checkItem = "" - if (checkSearch) checkItem = "${checkItem} ${appCtx.getString(R.string.search)}" - if (checkDiscovery) checkItem = "${checkItem} ${appCtx.getString(R.string.discovery)}" - if (checkInfo) checkItem = "${checkItem} ${appCtx.getString(R.string.source_tab_info)}" - if (checkCategory) checkItem = "${checkItem} ${appCtx.getString(R.string.chapter_list)}" - if (checkContent) checkItem = "${checkItem} ${appCtx.getString(R.string.main_body)}" + if (checkSearch) checkItem = "$checkItem ${appCtx.getString(R.string.search)}" + if (checkDiscovery) checkItem = "$checkItem ${appCtx.getString(R.string.discovery)}" + if (checkInfo) checkItem = "$checkItem ${appCtx.getString(R.string.source_tab_info)}" + if (checkCategory) checkItem = "$checkItem ${appCtx.getString(R.string.chapter_list)}" + if (checkContent) checkItem = "$checkItem ${appCtx.getString(R.string.main_body)}" return appCtx.getString(R.string.check_source_config_summary, (timeout / 1000).toString(), checkItem) } } \ No newline at end of file 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 aad76d367..252620f2b 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -48,18 +48,17 @@ object Debug { } it.printLog(state, printMsg) } - if (isChecking) { - if (sourceUrl != null && (msg ?: "").length < 30) { - var printMsg = msg ?: "" - if (isHtml) { - printMsg = HtmlFormatter.format(msg) - } - if (showTime && debugTimeMap[sourceUrl] != null) { - val time = - debugTimeFormat.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!)) - printMsg = printMsg.replace(AppPattern.debugMessageSymbolRegex,"") - debugMessageMap[sourceUrl] = "$time $printMsg" - } + if (isChecking && sourceUrl != null && (msg ?: "").length < 30) { + var printMsg = msg ?: "" + if (isHtml) { + printMsg = HtmlFormatter.format(msg) + } + if (showTime && debugTimeMap[sourceUrl] != null) { + val time = + debugTimeFormat.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!)) + printMsg = printMsg.replace(AppPattern.debugMessageSymbolRegex,"") + + debugMessageMap[sourceUrl] = "$time $printMsg" } } } @@ -89,13 +88,13 @@ object Debug { } fun getRespondTime(sourceUrl: String): Long { - return debugTimeMap[sourceUrl] ?: 180000L + return debugTimeMap[sourceUrl] ?: CheckSource.timeout } fun updateFinalMessage(sourceUrl: String, state: String) { if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) { val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!! - debugTimeMap[sourceUrl] = if (state == "校验成功") spendingTime else 180000L + debugTimeMap[sourceUrl] = if (state == "校验成功") spendingTime else CheckSource.timeout val printTime = debugTimeFormat.format(Date(spendingTime)) debugMessageMap[sourceUrl] = "$printTime $state" } 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 31ea800b4..758eac57f 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -12,11 +12,7 @@ import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.CompositeCoroutine -import io.legado.app.model.CheckSource -import io.legado.app.model.Debug -import io.legado.app.model.NoStackTraceException -import io.legado.app.model.ContentEmptyException -import io.legado.app.model.TocEmptyException +import io.legado.app.model.* import io.legado.app.model.webBook.WebBook import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.utils.activityPendingIntent @@ -204,8 +200,9 @@ class CheckSourceService : BaseService() { is TocEmptyException -> source.addGroup("目录失效") } source.bookSourceComment = - "Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}" - Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}") + "Error: ${it.localizedMessage}" + if (source.bookSourceComment.isNullOrBlank()) + "" else "\n\n${source.bookSourceComment}" + Debug.updateFinalMessage(source.bookSourceUrl, "校验失败:${it.localizedMessage}") }.onSuccess(searchCoroutine) { Debug.updateFinalMessage(source.bookSourceUrl, "校验成功") }.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 a04b12d92..0f0e8e0e1 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 @@ -360,7 +360,10 @@ class BookSourceActivity : VMBaseActivity= 0 && lastItem >= 0 + checkMessageRefreshJob(firstItem, lastItem).start() } neutralButton(R.string.check_source_config) { checkSource() @@ -478,26 +481,20 @@ class BookSourceActivity : VMBaseActivity= 0 && lastIndex >= 0 + private fun checkMessageRefreshJob(firstItem: Int, lastItem: Int): Job { return async(start = CoroutineStart.LAZY) { flow { while (true) { - refreshCount += 1 - emit(refreshCount) + emit(Debug.isChecking) delay(300L) } }.collect { adapter.notifyItemRangeChanged( - firstIndex, - lastIndex + 1, + firstItem, + lastItem + 1, bundleOf(Pair("checkSourceMessage", null)) ) - if (!Debug.isChecking) { - Debug.finishChecking() + if (!it) { this.cancel() } } 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 9ffeed0d3..48caf74ff 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 @@ -80,7 +80,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : cbBookSource.isChecked = selected.contains(item) ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" ivDebugText.visibility = - if (ivDebugText.text.toString().length > 1) View.VISIBLE else View.GONE + if (ivDebugText.text.toString().isNotBlank()) View.VISIBLE else View.GONE upShowExplore(ivExplore, item) } else { payload.keySet().map { @@ -91,7 +91,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : val isEmpty = ivDebugText.text.toString().isEmpty() var isFinalMessage = ivDebugText.text.toString().contains(Regex("成功|失败")) - if (!isEmpty && !Debug.isChecking && !isFinalMessage) { + if (!Debug.isChecking && !isFinalMessage) { Debug.updateFinalMessage(item.bookSourceUrl, "校验失败") ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" isFinalMessage = true @@ -99,7 +99,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : ivDebugText.visibility = if (!isEmpty) View.VISIBLE else View.GONE ivProgressBar.visibility = - if (isFinalMessage || isEmpty) View.GONE else View.VISIBLE + if (isFinalMessage || isEmpty || !Debug.isChecking) View.GONE else View.VISIBLE } } }