Browse Source

CommandBus: replace deprecated implementation.

Convert CommandBus from deprecated BroadcastChannel to a SharedFlow.
technical/upgrade-appcompat-1.5.x
Hugh Daschbach 2 years ago committed by Ryan Harg
parent
commit
1a038b2355
No known key found for this signature in database
GPG Key ID: 89106F3A84E6958C
  1. 2
      app/src/main/java/audio/funkwhale/ffa/FFA.kt
  2. 6
      app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt

2
app/src/main/java/audio/funkwhale/ffa/FFA.kt

@ -6,7 +6,6 @@ import androidx.appcompat.app.AppCompatDelegate @@ -6,7 +6,6 @@ import androidx.appcompat.app.AppCompatDelegate
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.FFACache
import audio.funkwhale.ffa.utils.Request
import com.preference.PowerPreference
@ -26,7 +25,6 @@ class FFA : Application() { @@ -26,7 +25,6 @@ class FFA : Application() {
var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
val commandBus: BroadcastChannel<Command> = BroadcastChannel(10)
val requestBus: BroadcastChannel<Request> = BroadcastChannel(10)
override fun onCreate() {

6
app/src/main/java/audio/funkwhale/ffa/utils/Bus.kt

@ -86,13 +86,15 @@ object EventBus { @@ -86,13 +86,15 @@ object EventBus {
}
object CommandBus {
private var _commands = MutableSharedFlow<Command>()
var commands = _commands.asSharedFlow()
fun send(command: Command) {
GlobalScope.launch(IO) {
FFA.get().commandBus.trySend(command).isSuccess
_commands.emit(command)
}
}
fun get() = FFA.get().commandBus.asFlow()
fun get() = commands
}
object RequestBus {

Loading…
Cancel
Save