Merge pull request #1596 from h11128/debug-update-cherry

校验优化
pull/1603/head
kunfei 3 years ago committed by GitHub
commit cd3bb7be86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/src/main/java/io/legado/app/model/CheckSource.kt
  2. 27
      app/src/main/java/io/legado/app/model/Debug.kt
  3. 11
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  4. 21
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  5. 6
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt

@ -46,13 +46,13 @@ object CheckSource {
CacheManager.put("checkContent", checkContent) CacheManager.put("checkContent", checkContent)
} }
fun upSummary(): String { private fun upSummary(): String {
var checkItem = "" var checkItem = ""
if (checkSearch) checkItem = "${checkItem} ${appCtx.getString(R.string.search)}" if (checkSearch) checkItem = "$checkItem ${appCtx.getString(R.string.search)}"
if (checkDiscovery) checkItem = "${checkItem} ${appCtx.getString(R.string.discovery)}" if (checkDiscovery) checkItem = "$checkItem ${appCtx.getString(R.string.discovery)}"
if (checkInfo) checkItem = "${checkItem} ${appCtx.getString(R.string.source_tab_info)}" if (checkInfo) checkItem = "$checkItem ${appCtx.getString(R.string.source_tab_info)}"
if (checkCategory) checkItem = "${checkItem} ${appCtx.getString(R.string.chapter_list)}" if (checkCategory) checkItem = "$checkItem ${appCtx.getString(R.string.chapter_list)}"
if (checkContent) checkItem = "${checkItem} ${appCtx.getString(R.string.main_body)}" if (checkContent) checkItem = "$checkItem ${appCtx.getString(R.string.main_body)}"
return appCtx.getString(R.string.check_source_config_summary, (timeout / 1000).toString(), checkItem) return appCtx.getString(R.string.check_source_config_summary, (timeout / 1000).toString(), checkItem)
} }
} }

@ -48,18 +48,17 @@ object Debug {
} }
it.printLog(state, printMsg) it.printLog(state, printMsg)
} }
if (isChecking) { if (isChecking && sourceUrl != null && (msg ?: "").length < 30) {
if (sourceUrl != null && (msg ?: "").length < 30) { var printMsg = msg ?: ""
var printMsg = msg ?: "" if (isHtml) {
if (isHtml) { printMsg = HtmlFormatter.format(msg)
printMsg = HtmlFormatter.format(msg) }
} if (showTime && debugTimeMap[sourceUrl] != null) {
if (showTime && debugTimeMap[sourceUrl] != null) { val time =
val time = debugTimeFormat.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!))
debugTimeFormat.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!)) printMsg = printMsg.replace(AppPattern.debugMessageSymbolRegex,"")
printMsg = printMsg.replace(AppPattern.debugMessageSymbolRegex,"")
debugMessageMap[sourceUrl] = "$time $printMsg" debugMessageMap[sourceUrl] = "$time $printMsg"
}
} }
} }
} }
@ -89,13 +88,13 @@ object Debug {
} }
fun getRespondTime(sourceUrl: String): Long { fun getRespondTime(sourceUrl: String): Long {
return debugTimeMap[sourceUrl] ?: 180000L return debugTimeMap[sourceUrl] ?: CheckSource.timeout
} }
fun updateFinalMessage(sourceUrl: String, state: String) { fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) { if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!! val spendingTime = System.currentTimeMillis() - debugTimeMap[sourceUrl]!!
debugTimeMap[sourceUrl] = if (state == "校验成功") spendingTime else 180000L debugTimeMap[sourceUrl] = if (state == "校验成功") spendingTime else CheckSource.timeout + spendingTime
val printTime = debugTimeFormat.format(Date(spendingTime)) val printTime = debugTimeFormat.format(Date(spendingTime))
debugMessageMap[sourceUrl] = "$printTime $state" 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.data.entities.SearchBook
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.model.CheckSource import io.legado.app.model.*
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.webBook.WebBook import io.legado.app.model.webBook.WebBook
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.utils.activityPendingIntent import io.legado.app.utils.activityPendingIntent
@ -204,8 +200,9 @@ class CheckSourceService : BaseService() {
is TocEmptyException -> source.addGroup("目录失效") is TocEmptyException -> source.addGroup("目录失效")
} }
source.bookSourceComment = source.bookSourceComment =
"Error: ${it.localizedMessage} \n\n" + "${source.bookSourceComment}" "Error: ${it.localizedMessage}" + if (source.bookSourceComment.isNullOrBlank())
Debug.updateFinalMessage(source.bookSourceUrl, "失败:${it.localizedMessage}") "" else "\n\n${source.bookSourceComment}"
Debug.updateFinalMessage(source.bookSourceUrl, "校验失败:${it.localizedMessage}")
}.onSuccess(searchCoroutine) { }.onSuccess(searchCoroutine) {
Debug.updateFinalMessage(source.bookSourceUrl, "校验成功") Debug.updateFinalMessage(source.bookSourceUrl, "校验成功")
}.onFinally(searchCoroutine) { }.onFinally(searchCoroutine) {

@ -360,7 +360,10 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
} }
CheckSource.start(this@BookSourceActivity, adapter.selection) 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) { neutralButton(R.string.check_source_config) {
checkSource() checkSource()
@ -478,26 +481,20 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
} }
} }
private fun checkMessageRefreshJob(): Job { private fun checkMessageRefreshJob(firstItem: Int, lastItem: Int): 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
return async(start = CoroutineStart.LAZY) { return async(start = CoroutineStart.LAZY) {
flow { flow {
while (true) { while (true) {
refreshCount += 1 emit(Debug.isChecking)
emit(refreshCount)
delay(300L) delay(300L)
} }
}.collect { }.collect {
adapter.notifyItemRangeChanged( adapter.notifyItemRangeChanged(
firstIndex, firstItem,
lastIndex + 1, lastItem + 1,
bundleOf(Pair("checkSourceMessage", null)) bundleOf(Pair("checkSourceMessage", null))
) )
if (!Debug.isChecking) { if (!it) {
Debug.finishChecking()
this.cancel() this.cancel()
} }
} }

@ -80,7 +80,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
cbBookSource.isChecked = selected.contains(item) cbBookSource.isChecked = selected.contains(item)
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
ivDebugText.visibility = 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) upShowExplore(ivExplore, item)
} else { } else {
payload.keySet().map { payload.keySet().map {
@ -91,7 +91,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
val isEmpty = ivDebugText.text.toString().isEmpty() val isEmpty = ivDebugText.text.toString().isEmpty()
var isFinalMessage = var isFinalMessage =
ivDebugText.text.toString().contains(Regex("成功|失败")) ivDebugText.text.toString().contains(Regex("成功|失败"))
if (!isEmpty && !Debug.isChecking && !isFinalMessage) { if (!Debug.isChecking && !isFinalMessage) {
Debug.updateFinalMessage(item.bookSourceUrl, "校验失败") Debug.updateFinalMessage(item.bookSourceUrl, "校验失败")
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
isFinalMessage = true isFinalMessage = true
@ -99,7 +99,7 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
ivDebugText.visibility = ivDebugText.visibility =
if (!isEmpty) View.VISIBLE else View.GONE if (!isEmpty) View.VISIBLE else View.GONE
ivProgressBar.visibility = ivProgressBar.visibility =
if (isFinalMessage || isEmpty) View.GONE else View.VISIBLE if (isFinalMessage || isEmpty || !Debug.isChecking) View.GONE else View.VISIBLE
} }
} }
} }

Loading…
Cancel
Save