pull/32/head
kunfei 5 years ago
parent 50e4f72b8e
commit 6a65b282f2
  1. 1
      app/src/main/java/io/legado/app/constant/Bus.kt
  2. 19
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  3. 15
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugModel.kt

@ -2,4 +2,5 @@ package io.legado.app.constant
object Bus { object Bus {
const val RECREATE = "RECREATE" const val RECREATE = "RECREATE"
const val SOURCE_DEBUG_LOG = "sourceDebugLog"
} }

@ -3,13 +3,15 @@ package io.legado.app.ui.sourcedebug
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseActivity 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.ATH
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.utils.getViewModel 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.activity_source_debug.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
@ -27,12 +29,6 @@ class SourceDebugActivity : BaseActivity<SourceDebugModel>() {
viewModel.init(intent.getStringExtra("key")) viewModel.init(intent.getStringExtra("key"))
initRecyclerView() initRecyclerView()
initSearchView() initSearchView()
viewModel.observeLogs(this){
adapter.addItem(it.obj as String)
if (it.what == -1 || it.what == 1000) {
rotate_loading.hide()
}
}
} }
private fun initRecyclerView() { private fun initRecyclerView() {
@ -69,4 +65,13 @@ class SourceDebugActivity : BaseActivity<SourceDebugModel>() {
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()
}
}
}
} }

@ -1,27 +1,18 @@
package io.legado.app.ui.sourcedebug package io.legado.app.ui.sourcedebug
import android.app.Application 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.App
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.constant.Bus
import io.legado.app.help.EventMessage import io.legado.app.help.EventMessage
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import io.legado.app.model.webbook.SourceDebug import io.legado.app.model.webbook.SourceDebug
import io.legado.app.utils.postEvent
class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback { class SourceDebugModel(application: Application) : BaseViewModel(application), SourceDebug.Callback {
private val logs: MutableLiveData<EventMessage> = MutableLiveData()
private var webBook: WebBook? = null private var webBook: WebBook? = null
fun observeLogs(owner: LifecycleOwner, observer: (EventMessage) -> Unit) {
logs.observe(owner, Observer {
observer(it)
})
}
fun init(sourceUrl: String?) { fun init(sourceUrl: String?) {
sourceUrl?.let { sourceUrl?.let {
//优先使用这个,不会抛出异常 //优先使用这个,不会抛出异常
@ -40,7 +31,7 @@ class SourceDebugModel(application: Application) : BaseViewModel(application), S
} }
override fun printLog(state: Int, msg: String) { 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() { override fun onCleared() {

Loading…
Cancel
Save