-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove use of org.greenrobot.eventbus
- Loading branch information
Showing
11 changed files
with
105 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
android/app/src/main/kotlin/org/getlantern/lantern/event/EventBus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.getlantern.lantern.event | ||
|
||
import kotlin.coroutines.coroutineContext | ||
import kotlinx.coroutines.ensureActive | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.flow.filter | ||
import kotlinx.coroutines.flow.filterIsInstance | ||
import org.getlantern.lantern.model.Bandwidth | ||
import org.getlantern.lantern.model.Stats | ||
|
||
object EventBus { | ||
private val _events = MutableSharedFlow<Any>() | ||
val events = _events.asSharedFlow() | ||
|
||
suspend fun publish(event: Any) { | ||
_events.emit(event) | ||
} | ||
|
||
suspend inline fun <reified T> subscribe(crossinline onEvent: (T) -> Unit) { | ||
events.filterIsInstance<T>() | ||
.collectLatest { event -> | ||
coroutineContext.ensureActive() | ||
onEvent(event) | ||
} | ||
} | ||
} | ||
|
||
sealed class AppEvent { | ||
data class StatsEvent(val stats: Stats) : AppEvent() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.