Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Geoffrey Métais
VLC-Android
Commits
4b6d909d
Commit
4b6d909d
authored
May 11, 2020
by
Geoffrey Métais
Browse files
Replace ConflatedBroadcastChannels by StateFlows
parent
252ab303
Pipeline
#17191
passed with stage
in 3 minutes and 41 seconds
Changes
5
Pipelines
1
Show whitespace changes
Inline
Side-by-side
application/tools/src/main/java/org/videolan/tools/NetworkMonitor.kt
View file @
4b6d909d
...
...
@@ -13,24 +13,20 @@ import androidx.lifecycle.Lifecycle
import
androidx.lifecycle.LifecycleObserver
import
androidx.lifecycle.OnLifecycleEvent
import
androidx.lifecycle.ProcessLifecycleOwner
import
kotlinx.coroutines.channels.ConflatedBroadcastChannel
import
kotlinx.coroutines.flow.Flow
import
kotlinx.coroutines.flow.asFlow
import
kotlinx.coroutines.flow.MutableStateFlow
import
java.net.NetworkInterface
import
java.net.SocketException
class
NetworkMonitor
(
private
val
context
:
Context
)
:
LifecycleObserver
{
private
var
registered
=
false
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
.
asFlow
()
val
connectionFlow
=
MutableStateFlow
(
Connection
(
connected
=
false
,
mobile
=
true
,
vpn
=
false
))
val
connected
:
Boolean
get
()
=
connection
.
value
.
connected
get
()
=
connection
Flow
.
value
.
connected
val
isLan
:
Boolean
get
()
=
connection
.
value
.
run
{
connected
&&
!
mobile
}
get
()
=
connection
Flow
.
value
.
run
{
connected
&&
!
mobile
}
val
lanAllowed
:
Boolean
get
()
=
connection
.
value
.
run
{
connected
&&
(!
mobile
||
vpn
)
}
get
()
=
connection
Flow
.
value
.
run
{
connected
&&
(!
mobile
||
vpn
)
}
val
receiver
=
object
:
BroadcastReceiver
()
{
@SuppressLint
(
"MissingPermission"
)
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
...
...
@@ -40,8 +36,7 @@ class NetworkMonitor(private val context: Context) : LifecycleObserver {
val
isConnected
=
networkInfo
!=
null
&&
networkInfo
.
isConnected
val
isMobile
=
isConnected
&&
networkInfo
!!
.
type
==
ConnectivityManager
.
TYPE_MOBILE
val
isVPN
=
isConnected
&&
updateVPNStatus
()
val
conn
=
Connection
(
isConnected
,
isMobile
,
isVPN
)
if
(
connection
.
value
!=
conn
)
connection
.
offer
(
conn
)
connectionFlow
.
value
=
Connection
(
isConnected
,
isMobile
,
isVPN
)
}
}
...
...
application/vlc-android/src/org/videolan/vlc/ExternalMonitor.kt
View file @
4b6d909d
...
...
@@ -105,7 +105,7 @@ object ExternalMonitor : BroadcastReceiver(), LifecycleObserver, CoroutineScope
}
}
UsbManager
.
ACTION_USB_DEVICE_DETACHED
->
if
(
intent
.
hasExtra
(
UsbManager
.
EXTRA_DEVICE
))
{
OtgAccess
.
otgRoot
.
offer
(
null
)
OtgAccess
.
otgRoot
.
value
=
null
val
device
=
intent
.
getParcelableExtra
<
UsbDevice
>(
UsbManager
.
EXTRA_DEVICE
)
devices
.
remove
(
device
)
}
...
...
application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
View file @
4b6d909d
...
...
@@ -52,11 +52,9 @@ import androidx.media.MediaBrowserServiceCompat
import
androidx.media.session.MediaButtonReceiver
import
kotlinx.coroutines.*
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.asFlow
import
kotlinx.coroutines.flow.MutableStateFlow
import
org.videolan.libvlc.MediaPlayer
import
org.videolan.libvlc.RendererItem
import
org.videolan.libvlc.interfaces.IMedia
...
...
@@ -496,7 +494,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
restartPlayer
.
observe
(
this
,
Observer
{
restartMediaPlayer
()
})
headSetDetection
.
observe
(
this
,
Observer
{
detectHeadset
(
it
)
})
equalizer
.
observe
(
this
,
Observer
{
setEqualizer
(
it
)
})
instanceChannel
.
safeOffer
(
this
)
serviceFlow
.
value
=
this
}
private
fun
setupScope
()
{
...
...
@@ -564,7 +562,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
}
override
fun
onDestroy
()
{
instanceChannel
.
safeOffer
(
null
)
serviceFlow
.
value
=
null
dispatcher
.
onServicePreSuperOnDestroy
()
super
.
onDestroy
()
handler
.
removeCallbacksAndMessages
(
null
)
...
...
@@ -1316,11 +1314,9 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
}
companion
object
{
private
val
instanceChannel
=
ConflatedBroadcastChannel
<
PlaybackService
?>(
null
)
val
serviceFlow
=
MutableStateFlow
<
PlaybackService
?>(
null
)
val
instance
:
PlaybackService
?
get
()
=
instanceChannel
.
valueOrNull
val
serviceFlow
:
Flow
<
PlaybackService
?>
get
()
=
instanceChannel
.
asFlow
()
get
()
=
serviceFlow
.
value
val
renderer
=
RendererLiveData
()
val
restartPlayer
=
LiveEvent
<
Boolean
>()
...
...
application/vlc-android/src/org/videolan/vlc/gui/browser/FileBrowserFragment.kt
View file @
4b6d909d
...
...
@@ -118,8 +118,7 @@ open class FileBrowserFragment : BaseBrowserFragment() {
browseOtgDevice
(
rootUri
,
title
)
}
else
{
lifecycleScope
.
launchWhenStarted
{
val
otgRoot
=
OtgAccess
.
otgRoot
.
asFlow
()
val
uri
=
otgRoot
.
filterNotNull
().
first
()
val
uri
=
OtgAccess
.
otgRoot
.
filterNotNull
().
first
()
browseOtgDevice
(
uri
,
title
)
}
requireActivity
().
requestOtgRoot
()
...
...
application/vlc-android/src/org/videolan/vlc/gui/helpers/hf/OtgAccess.kt
View file @
4b6d909d
...
...
@@ -31,10 +31,9 @@ import android.util.Log
import
androidx.annotation.WorkerThread
import
androidx.documentfile.provider.DocumentFile
import
androidx.fragment.app.FragmentActivity
import
kotlinx.coroutines.
channels.ConflatedBroadcastChannel
import
kotlinx.coroutines.
flow.MutableStateFlow
import
org.videolan.medialibrary.MLServiceLocator
import
org.videolan.medialibrary.interfaces.media.MediaWrapper
import
org.videolan.tools.safeOffer
const
val
SAF_REQUEST
=
85
const
val
TAG
=
"OtgAccess"
...
...
@@ -58,13 +57,13 @@ class OtgAccess : BaseHeadlessFragment() {
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
intent
:
Intent
?)
{
if
(
intent
!=
null
&&
requestCode
==
SAF_REQUEST
)
otgRoot
.
safeOffer
(
intent
.
data
)
if
(
intent
!=
null
&&
requestCode
==
SAF_REQUEST
)
otgRoot
.
value
=
intent
.
data
else
super
.
onActivityResult
(
requestCode
,
resultCode
,
intent
)
exit
()
}
companion
object
{
val
otgRoot
=
ConflatedBroadcastChannel
<
Uri
?>(
null
)
val
otgRoot
=
MutableStateFlow
<
Uri
?>(
null
)
}
}
...
...
@@ -74,7 +73,7 @@ fun FragmentActivity.requestOtgRoot() {
@WorkerThread
fun
getDocumentFiles
(
context
:
Context
,
path
:
String
)
:
List
<
MediaWrapper
>?
{
val
rootUri
=
OtgAccess
.
otgRoot
.
value
OrNull
?:
return
null
val
rootUri
=
OtgAccess
.
otgRoot
.
value
?:
return
null
// else Uri.Builder().scheme("content")
// .authority(OTG_CONTENT_AUTHORITY)
// .path(path.substringBefore(':'))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment