pull/32/head
Administrator 5 years ago
parent aa1c412a55
commit fa23d1de24
  1. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  2. 2
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  3. 52
      app/src/main/java/io/legado/app/utils/EventBusKt.kt

@ -16,7 +16,10 @@ import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.* import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.dialogs.customView
import io.legado.app.lib.dialogs.noButton
import io.legado.app.lib.dialogs.yesButton
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.ui.bookshelf.BookshelfActivity import io.legado.app.ui.bookshelf.BookshelfActivity

@ -65,7 +65,7 @@ class SourceDebugActivity : VMBaseActivity<SourceDebugModel>(R.layout.activity_s
} }
override fun observeLiveBus() { override fun observeLiveBus() {
observeEvent<EventMessage>(Bus.SOURCE_DEBUG_LOG){ observeEvent<EventMessage>(Bus.SOURCE_DEBUG_LOG) {
adapter.addItem(it.obj as String) adapter.addItem(it.obj as String)
if (it.what == -1 || it.what == 1000) { if (it.what == -1 || it.what == 1000) {
rotate_loading.hide() rotate_loading.hide()

@ -10,29 +10,71 @@ inline fun <reified EVENT> eventObservable(tag: String): LiveEventBus.Observable
} }
inline fun <reified EVENT> postEvent(tag: String, event: EVENT) { inline fun <reified EVENT> postEvent(tag: String, event: EVENT) {
return LiveEventBus.get().with(tag, EVENT::class.java).post(event) LiveEventBus.get().with(tag, EVENT::class.java).post(event)
} }
inline fun <reified EVENT> AppCompatActivity.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) { inline fun <reified EVENT> AppCompatActivity.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observe(this, Observer { eventObservable<EVENT>(tag).observe(this, Observer {
observer(it) observer(it)
}) })
} }
/**
* 只能观察相同类型的事件可用EventMessage
*/
inline fun <reified EVENT> AppCompatActivity.observeEvents(vararg tags: String, crossinline observer: (EVENT) -> Unit) {
val o = Observer<EVENT> {
observer(it)
}
tags.forEach {
eventObservable<EVENT>(it).observe(this, o)
}
}
inline fun <reified EVENT> AppCompatActivity.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) { inline fun <reified EVENT> AppCompatActivity.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observeSticky(this, Observer { eventObservable<EVENT>(tag).observeSticky(this, Observer {
observer(it) observer(it)
}) })
} }
inline fun <reified EVENT> AppCompatActivity.observeEventsSticky(
vararg tags: String,
crossinline observer: (EVENT) -> Unit
) {
val o = Observer<EVENT> {
observer(it)
}
tags.forEach {
eventObservable<EVENT>(it).observeSticky(this, o)
}
}
inline fun <reified EVENT> Fragment.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) { inline fun <reified EVENT> Fragment.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observe(this, Observer { eventObservable<EVENT>(tag).observe(this, Observer {
observer(it) observer(it)
}) })
} }
inline fun <reified EVENT> Fragment.observeEvents(vararg tags: String, crossinline observer: (EVENT) -> Unit) {
val o = Observer<EVENT> {
observer(it)
}
tags.forEach {
eventObservable<EVENT>(it).observe(this, o)
}
}
inline fun <reified EVENT> Fragment.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) { inline fun <reified EVENT> Fragment.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observeSticky(this, Observer { eventObservable<EVENT>(tag).observeSticky(this, Observer {
observer(it) observer(it)
}) })
} }
inline fun <reified EVENT> Fragment.observeEventsSticky(vararg tags: String, crossinline observer: (EVENT) -> Unit) {
val o = Observer<EVENT> {
observer(it)
}
tags.forEach {
eventObservable<EVENT>(it).observeSticky(this, o)
}
}

Loading…
Cancel
Save