diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt index 400328f1f..eda5f392d 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt @@ -27,12 +27,12 @@ class SourceDebugActivity : BaseActivity() { viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() - viewModel.logs.observe(this, Observer { + viewModel.observeLogs(this){ adapter.addItem(it.obj as String) if (it.what == -1 || it.what == 1000) { rotate_loading.hide() } - }) + } } private fun initRecyclerView() { diff --git a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt index 0a9732ad5..5b7716804 100644 --- a/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt @@ -1,7 +1,9 @@ package io.legado.app.ui.sourcedebug import android.app.Application +import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Observer import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.help.EventMessage @@ -10,10 +12,16 @@ import io.legado.app.model.webbook.SourceDebug class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { - val logs: MutableLiveData = MutableLiveData() + private val logs: MutableLiveData = MutableLiveData() private var webBook: WebBook? = null + fun observeLogs(owner: LifecycleOwner, observer: (EventMessage) -> Unit) { + logs.observe(owner, Observer { + observer(it) + }) + } + fun init(sourceUrl: String?) { sourceUrl?.let { //优先使用这个,不会抛出异常