pull/32/head
Administrator 5 years ago
parent c662e74a20
commit d6a83ed3e0
  1. 15
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt

@ -28,6 +28,12 @@ class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_s
viewModel.init(intent.getStringExtra("key")) viewModel.init(intent.getStringExtra("key"))
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()
viewModel.observe{state, msg->
adapter.addItem(msg)
if (state == -1 || state == 1000) {
rotate_loading.hide()
}
}
} }
private fun initRecyclerView() { private fun initRecyclerView() {
@ -64,13 +70,4 @@ class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_s
toast("未获取到书源") toast("未获取到书源")
}) })
} }
override fun observeLiveBus() {
observeEvent<EventMessage>(Bus.SOURCE_DEBUG_LOG) {
adapter.addItem(it.obj as String)
if (it.what == -1 || it.what == 1000) {
rotate_loading.hide()
}
}
}
} }

@ -13,6 +13,8 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S
private var webBook: WebBook? = null private var webBook: WebBook? = null
private var callback: ((Int, String)-> Unit)? = null
fun init(sourceUrl: String?) { fun init(sourceUrl: String?) {
sourceUrl?.let { 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) { fun startDebug(key: String, start: (() -> Unit)? = null, error: (() -> Unit)? = null) {
webBook?.let { webBook?.let {
start?.invoke() start?.invoke()
@ -31,7 +37,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S
} }
override fun printLog(state: Int, msg: String) { override fun printLog(state: Int, msg: String) {
postEvent(Bus.SOURCE_DEBUG_LOG, EventMessage.obtain(state, msg)) callback?.invoke(state, msg)
} }
override fun onCleared() { override fun onCleared() {

Loading…
Cancel
Save