mirror of
https://github.com/gedoor/legado.git
synced 2024-07-17 00:58:29 +08:00
debug update
修复spinner不正确显示 优化校验逻辑 优化校验修改注释
This commit is contained in:
parent
4a73754942
commit
8b6e925b86
@ -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)
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -360,7 +360,10 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
}
|
||||
CheckSource.start(this@BookSourceActivity, adapter.selection)
|
||||
checkMessageRefreshJob().start()
|
||||
val firstItem = adapter.getItems().indexOf(adapter.selection.firstOrNull())
|
||||
val lastItem = adapter.getItems().indexOf(adapter.selection.lastOrNull())
|
||||
Debug.isChecking = firstItem >= 0 && lastItem >= 0
|
||||
checkMessageRefreshJob(firstItem, lastItem).start()
|
||||
}
|
||||
neutralButton(R.string.check_source_config) {
|
||||
checkSource()
|
||||
@ -478,26 +481,20 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkMessageRefreshJob(): Job {
|
||||
val firstIndex = adapter.getItems().indexOf(adapter.selection.firstOrNull())
|
||||
val lastIndex = adapter.getItems().indexOf(adapter.selection.lastOrNull())
|
||||
var refreshCount = 0
|
||||
Debug.isChecking = firstIndex >= 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()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user