Commit 0271c9dd authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Geoffrey Métais
Browse files

Fix ConflatedBroadcastChannel consumption as Flow

parent af112f5e
Pipeline #14862 passed with stage
in 5 minutes and 2 seconds
......@@ -15,7 +15,7 @@ import androidx.lifecycle.OnLifecycleEvent
import androidx.lifecycle.ProcessLifecycleOwner
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.asFlow
import java.net.NetworkInterface
import java.net.SocketException
......@@ -24,7 +24,7 @@ class NetworkMonitor(private val context: Context) : LifecycleObserver {
private val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val connection = ConflatedBroadcastChannel(Connection(connected = false, mobile = true, vpn = false))
val connectionFlow : Flow<Connection>
get() = connection.openSubscription().consumeAsFlow()
get() = connection.asFlow()
val connected : Boolean
get() = connection.value.connected
val isLan : Boolean
......
......@@ -44,7 +44,7 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.asFlow
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.ACTION_CHECK_STORAGES
import org.videolan.resources.AppContextProvider
......@@ -111,7 +111,7 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
private val storageChannel = BroadcastChannel<DeviceAction>(BUFFERED)
val storageEvents : Flow<DeviceAction>
get() = storageChannel.openSubscription().consumeAsFlow()
get() = storageChannel.asFlow()
private var storageObserver: WeakReference<Activity>? = null
var devices = LiveDataset<UsbDevice>()
......
......@@ -44,16 +44,20 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.ServiceCompat
import androidx.core.content.ContextCompat
import androidx.lifecycle.*
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.lifecycle.ServiceLifecycleDispatcher
import androidx.lifecycle.lifecycleScope
import androidx.media.MediaBrowserServiceCompat
import androidx.media.session.MediaButtonReceiver
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.ConflatedBroadcastChannel
import kotlinx.coroutines.channels.SendChannel
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.asFlow
import org.videolan.libvlc.MediaPlayer
import org.videolan.libvlc.RendererItem
import org.videolan.libvlc.interfaces.IMedia
......@@ -1314,7 +1318,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
val instance : PlaybackService?
get() = instanceChannel.valueOrNull
val serviceFlow : Flow<PlaybackService?>
get() = instanceChannel.openSubscription().consumeAsFlow()
get() = instanceChannel.asFlow()
val renderer = RendererLiveData()
val restartPlayer = LiveEvent<Boolean>()
......
......@@ -34,6 +34,7 @@ import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.first
......@@ -121,7 +122,7 @@ open class FileBrowserFragment : BaseBrowserFragment() {
browseOtgDevice(rootUri, title)
} else {
lifecycleScope.launchWhenStarted {
val otgRoot = OtgAccess.otgRoot.openSubscription().consumeAsFlow()
val otgRoot = OtgAccess.otgRoot.asFlow()
val uri = otgRoot.filterNotNull().first()
browseOtgDevice(uri, title)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment