From e86283634924f66e97596a690266476d021b237b Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 27 Jul 2019 14:20:17 +0800 Subject: [PATCH] up --- .../java/io/legado/app/model/webbook/Debug.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/src/main/java/io/legado/app/model/webbook/Debug.kt diff --git a/app/src/main/java/io/legado/app/model/webbook/Debug.kt b/app/src/main/java/io/legado/app/model/webbook/Debug.kt new file mode 100644 index 000000000..82047ddd0 --- /dev/null +++ b/app/src/main/java/io/legado/app/model/webbook/Debug.kt @@ -0,0 +1,32 @@ +package io.legado.app.model.webbook + +import android.annotation.SuppressLint +import io.legado.app.utils.htmlFormat +import java.text.SimpleDateFormat +import java.util.* + +object Debug { + + var debugSource: String? = null + var callback: Callback? = null + @SuppressLint("ConstantLocale") + private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) + private val startTime: Long = System.currentTimeMillis() + + interface Callback { + fun printLog(state: Int, msg: String) + } + + fun printLog(source: String, state: Int, msg: String, print: Boolean = true, isHtml: Boolean = false) { + if (debugSource != source) return + if (!print) return + var printMsg = msg + if (isHtml) { + printMsg = printMsg.htmlFormat() + } + printMsg = + String.format("%s %s", DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - startTime)), printMsg) + callback?.printLog(state, printMsg) + } + +} \ No newline at end of file