pull/32/head
Administrator 5 years ago
parent 846c01a416
commit e3c7e8d0c4
  1. 2
      app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt
  2. 11
      app/src/main/java/io/legado/app/model/webbook/SourceDebug.kt
  3. 2
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt

@ -7,7 +7,7 @@ import android.content.Context
* *
* item代理 * item代理
*/ */
abstract class ItemViewDelegate<in ITEM>(protected val context: Context, val layoutId: Int) { abstract class ItemViewDelegate<ITEM>(protected val context: Context, val layoutId: Int) {
abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>) abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>)

@ -23,8 +23,7 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
private val startTime: Long = System.currentTimeMillis() private val startTime: Long = System.currentTimeMillis()
fun printLog(sourceUrl: String?, state: Int, msg: String, print: Boolean = true, isHtml: Boolean = false) { fun printLog(sourceUrl: String?, state: Int, msg: String, print: Boolean = true, isHtml: Boolean = false) {
if (debugSource != sourceUrl) return if (debugSource != sourceUrl || callback == null || !print) return
if (!print) return
var printMsg = msg var printMsg = msg
if (isHtml) { if (isHtml) {
printMsg = printMsg.htmlFormat() printMsg = printMsg.htmlFormat()
@ -34,22 +33,22 @@ class SourceDebug(private val webBook: WebBook, callback: Callback) {
callback?.printLog(state, printMsg) callback?.printLog(state, printMsg)
} }
fun cancelDebug() { fun cancelDebug(destroy: Boolean = false) {
tasks.forEach { tasks.forEach {
if (!it.isCancelled) { if (!it.isCancelled) {
it.cancel() it.cancel()
} }
} }
tasks.clear() tasks.clear()
}
fun stopDebug(){ if (destroy) {
cancelDebug()
debugSource = null debugSource = null
callback = null callback = null
} }
} }
}
init { init {
debugSource = webBook.sourceUrl debugSource = webBook.sourceUrl
SourceDebug.callback = callback SourceDebug.callback = callback

@ -37,6 +37,6 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
SourceDebug.stopDebug() SourceDebug.cancelDebug(true)
} }
} }

Loading…
Cancel
Save