RequentBus: replace deprecated implementation.
Convert RequestBus from deprecated BroadcastChannel to a SharedFlow.
This commit is contained in:
parent
1a038b2355
commit
4827fbccc1
|
@ -7,9 +7,7 @@ import audio.funkwhale.ffa.koin.authModule
|
|||
import audio.funkwhale.ffa.koin.exoplayerModule
|
||||
import audio.funkwhale.ffa.utils.AppContext
|
||||
import audio.funkwhale.ffa.utils.FFACache
|
||||
import audio.funkwhale.ffa.utils.Request
|
||||
import com.preference.PowerPreference
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import org.koin.core.context.startKoin
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
@ -25,8 +23,6 @@ class FFA : Application() {
|
|||
|
||||
var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null
|
||||
|
||||
val requestBus: BroadcastChannel<Request> = BroadcastChannel(10)
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package audio.funkwhale.ffa.utils
|
||||
|
||||
import audio.funkwhale.ffa.FFA
|
||||
import audio.funkwhale.ffa.model.Radio
|
||||
import audio.funkwhale.ffa.model.Track
|
||||
import com.google.android.exoplayer2.offline.Download
|
||||
|
@ -12,7 +11,6 @@ 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
|
||||
|
||||
sealed class Command {
|
||||
|
@ -98,17 +96,19 @@ object CommandBus {
|
|||
}
|
||||
|
||||
object RequestBus {
|
||||
private var _requests = MutableSharedFlow<Request>()
|
||||
var requests = _requests.asSharedFlow()
|
||||
fun send(request: Request): Channel<Response> {
|
||||
return Channel<Response>().also {
|
||||
GlobalScope.launch(IO) {
|
||||
request.channel = it
|
||||
|
||||
FFA.get().requestBus.trySend(request).isSuccess
|
||||
_requests.emit(request)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun get() = FFA.get().requestBus.asFlow()
|
||||
fun get() = requests
|
||||
}
|
||||
|
||||
object ProgressBus {
|
||||
|
|
Loading…
Reference in New Issue