From 3accf592995c02cd02447192d87d7ea3fedf5379 Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Wed, 31 Jul 2019 15:21:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/ui/sourcedebug/SourceDebugActivity.kt | 4 ++-- .../io/legado/app/ui/sourcedebug/SourceDebugModel.kt | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) 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 { //优先使用这个,不会抛出异常