Product Promotion
0x5a.live
for different kinds of informations and explorations.
GitHub - adrielcafe/KBus: Dead simple EventBus for Android made with Kotlin and RxJava 2
Dead simple EventBus for Android made with Kotlin and RxJava 2 - adrielcafe/KBus
Visit SiteGitHub - adrielcafe/KBus: Dead simple EventBus for Android made with Kotlin and RxJava 2
Dead simple EventBus for Android made with Kotlin and RxJava 2 - adrielcafe/KBus
Powered by 0x5a.live ๐
KBus
Super lightweight (13 LOC) and minimalistic (post()
, subscribe()
, unsubscribe()
) EventBus written with idiomatic Kotlin and RxJava 2
KBus in 3 steps
1. Define your events
// With data
data class ShowMessageEvent(val message: String)
// Without data
class OtherEvent
2. Add subscribers
override fun onStart() {
super.onStart()
KBus.subscribe<ShowMessageEvent>(this) {
showMessage(it.message)
}
KBus.subscribe<OtherEvent>(this) {
doSomething()
}
}
override fun onStop() {
super.onStop()
KBus.unsubscribe(this)
}
Where:
- ShowMessageEvent - the event you're subscribing
- this - the subscriber (by default the current Activity/Fragment)
- { showMessage() } - the subscription observer
- it - the event instance
Sticky events
If you want to post events between Activities/Fragments just subscribe in onCreate()
(or onPostCreate()
) and unsubscribe in onDestroy()
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
KBus.subscribe<ShowMessageEvent>(this) {
showMessage(it.message)
}
}
override fun onDestroy() {
super.onDestroy()
KBus.unsubscribe(this)
}
3. Post events
KBus.post(ShowMessageEvent("Hello KBus!"))
Add KBus to your project
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'io.reactivex.rxjava2:rxjava:2.2.10'
implementation 'com.github.adrielcafe:KBus:1.1'
}
Kotlin Resources
are all listed below.
GitHub - BenWoodworth/knbt: Kotlin NBT library for kotlinx.serialization
resource
~/github.com
resource
GitHub - brianmadden/krawler: A web crawling framework written in Kotlin
resource
~/github.com
resource
GitHub - OxygenCobalt/Auxio: A simple, rational music player for android
resource
~/github.com
resource
GitHub - eriksencosta/math-percentage: Percentage calculations made easy
resource
~/github.com
resource
GitHub - ctripcorp/mmkv-kotlin: A Kotlin Multiplatform porting for MMKV.
resource
~/github.com
resource
GitHub - Litote/kmongo: [deprecated] KMongo - a Kotlin toolkit for Mongo
resource
~/github.com
resource
Test-Driven Development Tutorial for Android: Getting Started
resource
~/www.raywenderlich.com
resource
GitHub - jacinpoz/rxaerospike: RxJava2 wrapper for aerospike-client-java
resource
~/github.com
resource
GitHub - pedrovgs/KotlinSnapshot: Snapshot Testing framework for Kotlin.
resource
~/github.com
resource
GitHub - hankdavidson/ktime: kotlin extensions to the java8 time library
resource
~/github.com
resource
GitHub - ziggy42/Blum: A simple android Twitter client written in Kotlin
resource
~/github.com
resource
Made with โค๏ธ
to provide different kinds of informations and resources.