|
|
@ -2,6 +2,7 @@ package io.legado.app.model |
|
|
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint |
|
|
|
import android.annotation.SuppressLint |
|
|
|
import io.legado.app.data.entities.* |
|
|
|
import io.legado.app.data.entities.* |
|
|
|
|
|
|
|
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.rss.Rss |
|
|
|
import io.legado.app.model.rss.Rss |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
|
import io.legado.app.model.webBook.WebBook |
|
|
@ -11,14 +12,15 @@ import io.legado.app.utils.msg |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import java.text.SimpleDateFormat |
|
|
|
import java.text.SimpleDateFormat |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import java.util.concurrent.ConcurrentHashMap |
|
|
|
import kotlin.collections.HashMap |
|
|
|
|
|
|
|
|
|
|
|
object Debug { |
|
|
|
object Debug { |
|
|
|
var callback: Callback? = null |
|
|
|
var callback: Callback? = null |
|
|
|
private var debugSource: String? = null |
|
|
|
private var debugSource: String? = null |
|
|
|
private val tasks: CompositeCoroutine = CompositeCoroutine() |
|
|
|
private val tasks: CompositeCoroutine = CompositeCoroutine() |
|
|
|
val debugMessageMap = ConcurrentHashMap<String, String>() |
|
|
|
val debugMessageMap = HashMap<String, String>() |
|
|
|
private var isChecking: Boolean = false |
|
|
|
private val debugTimeMap = HashMap<String, Long>() |
|
|
|
|
|
|
|
var isChecking: Boolean = false |
|
|
|
|
|
|
|
|
|
|
|
@SuppressLint("ConstantLocale") |
|
|
|
@SuppressLint("ConstantLocale") |
|
|
|
private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) |
|
|
|
private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) |
|
|
@ -33,20 +35,30 @@ object Debug { |
|
|
|
showTime: Boolean = true, |
|
|
|
showTime: Boolean = true, |
|
|
|
state: Int = 1 |
|
|
|
state: Int = 1 |
|
|
|
) { |
|
|
|
) { |
|
|
|
callback?.let { |
|
|
|
if (AppConfig.checkSourceMessage) { |
|
|
|
if ((debugSource != sourceUrl || !print) && !isChecking) return |
|
|
|
if (isChecking && 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) { |
|
|
|
if (showTime && debugTimeMap[sourceUrl] != null) { |
|
|
|
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)) |
|
|
|
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!)) |
|
|
|
printMsg = "$time $printMsg" |
|
|
|
printMsg = "$time $printMsg" |
|
|
|
} |
|
|
|
debugMessageMap[sourceUrl] = printMsg |
|
|
|
it.printLog(state, printMsg) |
|
|
|
} |
|
|
|
if (sourceUrl != null && printMsg.length < 30) { |
|
|
|
} else { |
|
|
|
debugMessageMap[sourceUrl] = printMsg |
|
|
|
callback?.let { |
|
|
|
callback?.postCheckMessageEvent(sourceUrl) |
|
|
|
if ((debugSource != sourceUrl || !print)) return |
|
|
|
|
|
|
|
var printMsg = msg ?: "" |
|
|
|
|
|
|
|
if (isHtml) { |
|
|
|
|
|
|
|
printMsg = HtmlFormatter.format(msg) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (showTime) { |
|
|
|
|
|
|
|
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)) |
|
|
|
|
|
|
|
printMsg = "$time $printMsg" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
it.printLog(state, printMsg) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -66,13 +78,12 @@ object Debug { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun startChecking(source: BookSource) { |
|
|
|
fun startChecking(source: BookSource) { |
|
|
|
startTime = System.currentTimeMillis() |
|
|
|
|
|
|
|
isChecking = true |
|
|
|
isChecking = true |
|
|
|
debugMessageMap[source.bookSourceUrl] = "开始校验" |
|
|
|
debugTimeMap[source.bookSourceUrl] = System.currentTimeMillis() |
|
|
|
|
|
|
|
debugMessageMap[source.bookSourceUrl] = "${DEBUG_TIME_FORMAT.format(Date(0))} 开始校验" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun finishChecking() { |
|
|
|
fun finishChecking() { |
|
|
|
callback = null |
|
|
|
|
|
|
|
isChecking = false |
|
|
|
isChecking = false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -261,7 +272,5 @@ object Debug { |
|
|
|
|
|
|
|
|
|
|
|
interface Callback { |
|
|
|
interface Callback { |
|
|
|
fun printLog(state: Int, msg: String) |
|
|
|
fun printLog(state: Int, msg: String) |
|
|
|
fun postCheckMessageEvent(sourceUrl: String) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |