LiveDataBus is an event bus based on LiveData. It has lifecycle perceive ability and supports Sticky messages
Gradle:
root build.gradle
repositories {
maven { url 'https://jitpack.io' }
}
module build.gradle
dependencies {
implementation 'com.github.Hejx0808:LiveDataBus:v1.0'
}
create Message.class:
class Message {...}
class Event {...}
...
get channel by message.class:
val channelMsg = LiveDataBus.getChannel(Message::class.java)
val channelEvent = LiveDataBus.getChannel(Event::class.java)
...
observe:
val observer = Observer<Message> {}
channelMsg.observe(observer)
// channelMsg.observeSticky(observer)
// channelMsg.observeLifecycle(lifecycleOwner, observer)
// channelMsg.observeLifecycleSticky(lifecycleOwner, observer)
post messages:
val message = Message()
...
channelMsg.postEvent(message)
channelMsg.postEventDelay(Message(), 1000)
remove observer:
channelMsg.removeObserve(observer)
-dontwarn com.hjx.livedatabus.**
-keep class com.hjx.livedatabus.** { *; }
-keep class androidx.lifecycle.** { *; }
-keep class androidx.arch.core.** { *; }
Version | Features |
---|---|
v1.0 | base version |