kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale-android
EventBus: replace deprecated implementation.
Convert EventBus from deprecated BroadcastChannel to a SharedFlow.technical/upgrade-appcompat-1.5.x
rodzic
6d1ad9cd78
commit
be8901390e
|
@ -7,7 +7,6 @@ import audio.funkwhale.ffa.koin.authModule
|
|||
import audio.funkwhale.ffa.koin.exoplayerModule
|
||||
import audio.funkwhale.ffa.utils.AppContext
|
||||
import audio.funkwhale.ffa.utils.Command
|
||||
import audio.funkwhale.ffa.utils.Event
|
||||
import audio.funkwhale.ffa.utils.FFACache
|
||||
import audio.funkwhale.ffa.utils.Request
|
||||
import com.preference.PowerPreference
|
||||
|
@ -27,7 +26,6 @@ class FFA : Application() {
|
|||
|
||||
var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
||||
|
||||
val eventBus: BroadcastChannel<Event> = BroadcastChannel(10)
|
||||
val commandBus: BroadcastChannel<Command> = 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.GlobalScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.coroutines.launch
|
||||
|
@ -72,13 +74,15 @@ sealed class Response {
|
|||
}
|
||||
|
||||
object EventBus {
|
||||
private var _events = MutableSharedFlow<Event>()
|
||||
val events = _events.asSharedFlow()
|
||||
fun send(event: Event) {
|
||||
GlobalScope.launch(IO) {
|
||||
FFA.get().eventBus.trySend(event).isSuccess
|
||||
_events.emit(event)
|
||||
}
|
||||
}
|
||||
|
||||
fun get() = FFA.get().eventBus.asFlow()
|
||||
fun get() = events
|
||||
}
|
||||
|
||||
object CommandBus {
|
||||
|
|
Ładowanie…
Reference in New Issue