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 609689873..a70924bed 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 @@ -28,6 +28,12 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s viewModel.init(intent.getStringExtra("key")) initRecyclerView() initSearchView() + viewModel.observe{state, msg-> + adapter.addItem(msg) + if (state == -1 || state == 1000) { + rotate_loading.hide() + } + } } private fun initRecyclerView() { @@ -64,13 +70,4 @@ class SourceDebugActivity : VMBaseActivity(R.layout.activity_s 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 df76cda3b..e5c800b20 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 @@ -13,6 +13,8 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S private var webBook: WebBook? = null + private var callback: ((Int, String)-> Unit)? = null + fun init(sourceUrl: String?) { sourceUrl?.let { //优先使用这个,不会抛出异常 @@ -23,6 +25,10 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S } } + fun observe(callback: (Int, String)-> Unit){ + this.callback = callback + } + fun startDebug(key: String, start: (() -> Unit)? = null, error: (() -> Unit)? = null) { webBook?.let { start?.invoke() @@ -31,7 +37,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S } override fun printLog(state: Int, msg: String) { - postEvent(Bus.SOURCE_DEBUG_LOG, EventMessage.obtain(state, msg)) + callback?.invoke(state, msg) } override fun onCleared() {