pull/32/head
Administrator 5 years ago
parent 3df45dec46
commit 3accf59299
  1. 4
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  2. 10
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt

@ -27,12 +27,12 @@ class SourceDebugActivity : BaseActivity<SourceDebugModel>() {
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() {

@ -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<EventMessage> = MutableLiveData()
private val logs: MutableLiveData<EventMessage> = 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 {
//优先使用这个,不会抛出异常

Loading…
Cancel
Save