From 6a65b282f286433b03211c89311682831ee4ec04 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 1 Aug 2019 10:26:00 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/constant/Bus.kt | 1 + .../app/ui/sourcedebug/SourceDebugActivity.kt | 19 ++++++++++++------- .../app/ui/sourcedebug/SourceDebugModel.kt | 15 +++------------ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/Bus.kt b/app/src/main/java/io/legado/app/constant/Bus.kt index 94d41fafb..98acde903 100644 --- a/app/src/main/java/io/legado/app/constant/Bus.kt +++ b/app/src/main/java/io/legado/app/constant/Bus.kt @@ -2,4 +2,5 @@ package io.legado.app.constant object Bus { const val RECREATE = "RECREATE" + const val SOURCE_DEBUG_LOG = "sourceDebugLog" } \ No newline at end of file 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 eda5f392d..81817b616 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 @@ -3,13 +3,15 @@ package io.legado.app.ui.sourcedebug import android.os.Bundle import android.view.View import androidx.appcompat.widget.SearchView -import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseActivity +import io.legado.app.constant.Bus +import io.legado.app.help.EventMessage import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.getViewModel +import io.legado.app.utils.observeEvent import kotlinx.android.synthetic.main.activity_source_debug.* import kotlinx.android.synthetic.main.view_title_bar.* import org.jetbrains.anko.toast @@ -27,12 +29,6 @@ class SourceDebugActivity : BaseActivity() { viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() - viewModel.observeLogs(this){ - adapter.addItem(it.obj as String) - if (it.what == -1 || it.what == 1000) { - rotate_loading.hide() - } - } } private fun initRecyclerView() { @@ -69,4 +65,13 @@ class SourceDebugActivity : BaseActivity() { toast("未获取到书源") }) } + + override fun observeLiveBus() { + observeEvent(Bus.SOURCE_DEBUG_LOG) { + adapter.addItem(it.obj as String) + if (it.what == -1 || it.what == 1000) { + rotate_loading.hide() + } + } + } } \ No newline at end of file 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 5b7716804..df76cda3b 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,27 +1,18 @@ 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.constant.Bus import io.legado.app.help.EventMessage import io.legado.app.model.WebBook import io.legado.app.model.webbook.SourceDebug +import io.legado.app.utils.postEvent class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { - 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 { //优先使用这个,不会抛出异常 @@ -40,7 +31,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S } override fun printLog(state: Int, msg: String) { - logs.postValue(EventMessage.obtain(state, msg)) + postEvent(Bus.SOURCE_DEBUG_LOG, EventMessage.obtain(state, msg)) } override fun onCleared() {