Merge remote-tracking branch 'origin/master'

pull/32/head
kunfei 5 years ago
commit 275adb2720
  1. 5
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  2. 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.data.entities.Book
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.ThemeStore
import io.legado.app.ui.bookshelf.BookshelfActivity

@ -10,29 +10,71 @@ inline fun <reified EVENT> eventObservable(tag: String): LiveEventBus.Observable
}
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) {
return eventObservable<EVENT>(tag).observe(this, Observer {
eventObservable<EVENT>(tag).observe(this, Observer {
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) {
return eventObservable<EVENT>(tag).observeSticky(this, Observer {
eventObservable<EVENT>(tag).observeSticky(this, Observer {
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) {
return eventObservable<EVENT>(tag).observe(this, Observer {
eventObservable<EVENT>(tag).observe(this, Observer {
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) {
return eventObservable<EVENT>(tag).observeSticky(this, Observer {
eventObservable<EVENT>(tag).observeSticky(this, Observer {
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