Event Bus powered by Kotlin Coroutines Flow

Overview

FlowBus

FlowBus is a kotlin event bus implementation.

  • Powered by Kotlin Coroutines and Flows
  • Android MainThread-aware
  • Fully operable from Java code

Example

Subscribing

Most common Android use case will consist of subscribing in your Activity/Fragment onStart method and unsubscribing in onStop. You can also use bindLifecycle extension to automatically unsubscribe when lifecycle reaches STOPPED state.

class SomeActivity : AppCompatActivity() {

    private val receiver = EventsReceiver()

    override fun onStart() {
        super.onStart()
        receiver
            .bindLifecycle(this)
            .subscribe { event: MyEvent ->
                // handle new event
            }
    }

Posting

Instance of any class can posted as an event.

GlobalBus.post(MyEvent())

For more examples see example app
For detailed documentation check the wiki.

Include in your project

FlowBus is available on Jitpack.
Add jitpack repo in your project root build.gradle:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

In your module's build.gradle:

dependencies {
    // core package:
    implementation 'com.github.Kosert.FlowBus:FlowBus:1.1'
    
    // android extensions:
    implementation 'com.github.Kosert.FlowBus:FlowBus-android:1.1'
}

License

Copyright 2021 Robert Kosakowski

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
An app to detect color palettes in the real world - powered by VisionCamera
An app to detect color palettes in the real world - powered by VisionCamera

Colorwaver An app to detect colorwaves (swatches/palettes) in the real world - powered by VisionCamera and Reanimated. I wrote this app in less than a

LedBuzz is a NodeMCU-powered see-through propeller display
LedBuzz is a NodeMCU-powered see-through propeller display

LedBuzz What it does LedBuzz is a NodeMCU-powered see-through propeller display. By simply staring at your ceiling fan, you receive notification alert

Picker-kt - Media picker library powered by Jetpack Compose
Picker-kt - Media picker library powered by Jetpack Compose

ANDROID LIBRARY PickerKT A media picker library for Android apps powered by Jetp

Get a libGDX-powered Android live wallpaper up and running quickly with this project template

This project is a libGDX Android live wallpaper template. It's the demo application created by the libGDX code generator, remade as a live wallpaper.

ICSx⁵ is an Android app to subscribe to remote or local iCalendar files (like time tables of your school/university or event files of your sports team).

ICSx⁵ ICSx⁵ is an Android app to subscribe to remote Webcal feeds / iCalendar files (like time tables of your school/university or event files of your

Solving all 25 days of the AOC 2021 event here: https://adventofcode.com

advent-of-code-2021-kotlin Welcome to the Advent of Code1 Kotlin project using the Advent of Code Kotlin Template delivered by JetBrains. In this repo

Juara Android - Repository Google Code Lab, JuaraAndroid Event
Juara Android - Repository Google Code Lab, JuaraAndroid Event

Juara Android - Repository Google Code Lab, JuaraAndroid Event

The JeTrivia is built on a modern Android Development tech stack with MVVM architecture. Kotlin, Coroutine, Flow, StateFlow, Jetpack Compose, Navigation, Room, Hilt, Retrofit2, OkHttp3, kotlinx.serialization, MockK, Truth
The JeTrivia is built on a modern Android Development tech stack with MVVM architecture. Kotlin, Coroutine, Flow, StateFlow, Jetpack Compose, Navigation, Room, Hilt, Retrofit2, OkHttp3, kotlinx.serialization, MockK, Truth

JeTrivia 🚧 In Progress 🚧 The JeTrivia application is sample based on MVVM architecture. Fetching data from the network via repository pattern and sa

A Android app Permissions with Kotlin Flow APIs

Know about real-time state of a Android app Permissions with Kotlin Flow APIs. Made with ❤️ for Android Developers.

Comments
  • I have to call GlobalBus.dropAll() to keep receiving events after the first one.

    I have to call GlobalBus.dropAll() to keep receiving events after the first one.

    My event subscribers will not continue to work after the same event once it is repeated. I've tried using skipRetained and retained. Event drop event but the only thing that seems to work is the dropAll() command.

    Here is a portion of my code.

    Poster

    GlobalBus.post(FriendUpdatePayload(userSession.user.toPublic(), userSession.user.identifier, "state", UserState.ONLINE.ordinal))
    GlobalBus.post(SelfUpdatePayload(userSession.user.toPublic(), "state", UserState.ONLINE.ordinal))
    

    Subscriber

      events.subscribe<FriendUpdatePayload> { payload ->
                logger.info("Update Payload -> ${payload.id} ${payload.name} = ${payload.value}")
                connections.values.forEach { v -> println(v.user.identifier) }
                val friends = connections.values.find { u -> u.user.identifier== payload.id }!!.user.getFriends()
                for (friend in friends.friends) {
                    val friendSession = connections.values.find { f -> f.user.identifier == friend.id }!!
                    send(friendSession.ws.session, friendSession.ws.type, jsonStr = payload.toJSON())
                }
                GlobalBus.dropAll() // Doesn't get another event without this.
                return@subscribe
            }
            events.subscribe<SelfUpdatePayload> { payload ->
                logger.info("Self Update -> ${payload.self.id} ${payload.name} = ${payload.value}")
                val selfSocket = connections.values.find { u -> u.user.identifier == payload.self.id }
                if (selfSocket != null) {
                    send(selfSocket.ws.session, selfSocket.ws.type, jsonStr = payload.toJSON())
                }
                GlobalBus.dropAll() // Doesn't get another event without this.
                return@subscribe
            }
    
    opened by brys0 2
Releases(1.1)
Owner
Robert Kosakowski
Robert Kosakowski
MVVM + Kotlin + Jetpack Compose +Navigation Compose + Hilt + Retrofit + Unit Testing + Compose Testing + Coroutines + Kotlin Flow + Io mockK

MvvmKotlinJetpackCompose Why do we need an architecture even when you can make an app without it? let's say you created a project without any architec

Sayyed Rizwan 46 Nov 29, 2022
This Android app shows bus connections from Koleje Strahov station to Dejvická station and the other way in the city of Prague

This Android app shows bus connections from Koleje Strahov station to Dejvická station and the other way in the city of Prague. These are important for many students from the Czech Technical University in Prague.

Lašťa Apps 3 Jul 28, 2022
Shreyas Patil 2.1k Dec 30, 2022
Android multimodule project based on Kotlin, MVVM, SOLID, flow, coroutines and paging3.

TVMaze David Ferrándiz Features Retrieve TVMaze shows in a grid. See more information about the show in a new screen Tech Kotlin Retrofit Modularizati

David Ferrandiz 1 Nov 18, 2022
🦁 A Disney app using transformation motions based on MVVM (ViewModel, Coroutines, Flow, LiveData, Room, Repository, Koin) architecture.

DisneyMotions A demo Disney app using transformation motions based on MVVM architecture. The motion system is included in the 1.2.0-alpha05 released m

Jaewoong Eum 1.4k Dec 16, 2022
Patter Lock using Hilt, Coroutines, Flow and Custom View Components based on MVVM architecture.

Pattern Lock App Sample project for created Pattern Lock View using custom view. Preview Usage Step 1 Add the PatterLockView in your XML layout file.

Furkan Özcan 5 Aug 22, 2021
🦄 Android Pokedex-AR using ARCore, Sceneform, Hilt, Coroutines, Flow, Jetpack (Room, ViewModel, LiveData) based on MVVM architecture.

?? Android Pokedex-AR using ARCore, Sceneform, Hilt, Coroutines, Flow, Jetpack (Room, ViewModel, LiveData) based on MVVM architecture.

Jaewoong Eum 535 Dec 9, 2022
TzRecipes App With Retrofit,Coroutines,Flow

TzRecipesApp Main Stack : Retrofit,Coroutines,Flow,LiveData,Mvvm SOLID,OOP,ClenArchitecture Разбиение приложения на data, domain, presentation слои Ма

null 2 Nov 9, 2021
Note taking app using MVVM architecture with Hilt, Material Motion, Coroutines, Flow, Jetpack

Note taking app using MVVM architecture with Hilt, Material Motion, Coroutines, Flow, Jetpack (Room, ViewModel,Paging3).

Ranbir Singh 7 Apr 25, 2022
Simple Notes app demonstrates modern Android development with Hilt, Material Motion, Coroutines, Flow, Jetpack (Room, ViewModel) based on MVVM architecture.

Simple Notes app demonstrates modern Android development with Hilt, Material Motion, Coroutines, Flow, Jetpack (Room, ViewModel) based on MVVM architecture.

Aravind Chowdary 2 Sep 3, 2022