EventBus: replace deprecated implementation.
Convert EventBus from deprecated BroadcastChannel to a SharedFlow.
This commit is contained in:
parent
6d1ad9cd78
commit
be8901390e
|
@ -7,7 +7,6 @@ import audio.funkwhale.ffa.koin.authModule
|
||||||
import audio.funkwhale.ffa.koin.exoplayerModule
|
import audio.funkwhale.ffa.koin.exoplayerModule
|
||||||
import audio.funkwhale.ffa.utils.AppContext
|
import audio.funkwhale.ffa.utils.AppContext
|
||||||
import audio.funkwhale.ffa.utils.Command
|
import audio.funkwhale.ffa.utils.Command
|
||||||
import audio.funkwhale.ffa.utils.Event
|
|
||||||
import audio.funkwhale.ffa.utils.FFACache
|
import audio.funkwhale.ffa.utils.FFACache
|
||||||
import audio.funkwhale.ffa.utils.Request
|
import audio.funkwhale.ffa.utils.Request
|
||||||
import com.preference.PowerPreference
|
import com.preference.PowerPreference
|
||||||
|
@ -27,7 +26,6 @@ class FFA : Application() {
|
||||||
|
|
||||||
var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
||||||
|
|
||||||
val eventBus: BroadcastChannel<Event> = BroadcastChannel(10)
|
|
||||||
val commandBus: BroadcastChannel<Command> = BroadcastChannel(10)
|
val commandBus: BroadcastChannel<Command> = BroadcastChannel(10)
|
||||||
val requestBus: BroadcastChannel<Request> = BroadcastChannel(10)
|
val requestBus: BroadcastChannel<Request> = BroadcastChannel(10)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@ import com.google.android.exoplayer2.offline.DownloadCursor
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.channels.Channel
|
import kotlinx.coroutines.channels.Channel
|
||||||
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asSharedFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.asFlow
|
import kotlinx.coroutines.flow.asFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
@ -72,13 +74,15 @@ sealed class Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
object EventBus {
|
object EventBus {
|
||||||
|
private var _events = MutableSharedFlow<Event>()
|
||||||
|
val events = _events.asSharedFlow()
|
||||||
fun send(event: Event) {
|
fun send(event: Event) {
|
||||||
GlobalScope.launch(IO) {
|
GlobalScope.launch(IO) {
|
||||||
FFA.get().eventBus.trySend(event).isSuccess
|
_events.emit(event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get() = FFA.get().eventBus.asFlow()
|
fun get() = events
|
||||||
}
|
}
|
||||||
|
|
||||||
object CommandBus {
|
object CommandBus {
|
||||||
|
|
Loading…
Reference in New Issue