ProgressBus: replace deprecated implementation.
Convert Progress from deprecated BroadcastChannel to a StateFlow.
This commit is contained in:
parent
72b4aea35a
commit
6d1ad9cd78
|
@ -12,7 +12,6 @@ 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
|
||||||
import kotlinx.coroutines.channels.BroadcastChannel
|
import kotlinx.coroutines.channels.BroadcastChannel
|
||||||
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
|
|
||||||
import org.koin.core.context.startKoin
|
import org.koin.core.context.startKoin
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
@ -31,7 +30,6 @@ class FFA : Application() {
|
||||||
val eventBus: BroadcastChannel<Event> = BroadcastChannel(10)
|
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)
|
||||||
val progressBus: BroadcastChannel<Triple<Int, Int, Int>> = ConflatedBroadcastChannel()
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
|
@ -8,8 +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.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.asFlow
|
import kotlinx.coroutines.flow.asFlow
|
||||||
import kotlinx.coroutines.flow.conflate
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
sealed class Command {
|
sealed class Command {
|
||||||
|
@ -105,13 +106,13 @@ object RequestBus {
|
||||||
}
|
}
|
||||||
|
|
||||||
object ProgressBus {
|
object ProgressBus {
|
||||||
|
private var _progress = MutableStateFlow(Triple(0, 0, 0))
|
||||||
|
val progress = _progress.asStateFlow()
|
||||||
fun send(current: Int, duration: Int, percent: Int) {
|
fun send(current: Int, duration: Int, percent: Int) {
|
||||||
GlobalScope.launch(IO) {
|
_progress.value = Triple(current, duration, percent)
|
||||||
FFA.get().progressBus.send(Triple(current, duration, percent))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun get() = FFA.get().progressBus.asFlow().conflate()
|
fun get() = progress
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend inline fun <reified T> Channel<Response>.wait(): T? {
|
suspend inline fun <reified T> Channel<Response>.wait(): T? {
|
||||||
|
|
Loading…
Reference in New Issue