[Android] Filter devices to add to medialibrary
Geoffrey Métais
git at videolan.org
Tue Jul 31 15:40:07 CEST 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Jul 31 14:23:41 2018 +0200| [5ba3ca5eeb1fe80e5c19ff13534066429964193c] | committer: Geoffrey Métais
Filter devices to add to medialibrary
> https://code.videolan.org/videolan/vlc-android/commit/5ba3ca5eeb1fe80e5c19ff13534066429964193c
---
vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 10eca84b4..c26d666b9 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -239,7 +239,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
}
}
- private fun initMedialib(parse: Boolean, context: Context, shouldInit: Boolean, upgrade: Boolean) {
+ private suspend fun initMedialib(parse: Boolean, context: Context, shouldInit: Boolean, upgrade: Boolean) {
addDevices(context, parse)
medialibrary.start()
localBroadcastManager.sendBroadcast(Intent(VLCApplication.ACTION_MEDIALIBRARY_READY))
@@ -247,15 +247,16 @@ class MediaParsingService : Service(), DevicesDiscoveryCb {
else exitCommand()
}
- private fun addDevices(context: Context, addExternal: Boolean) {
+ private suspend fun addDevices(context: Context, addExternal: Boolean) {
val devices = ArrayList<String>()
Collections.addAll(devices, *AndroidDevices.getMediaDirectories(context))
- val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
+ val sharedPreferences = withContext(VLCIO) { PreferenceManager.getDefaultSharedPreferences(context) }
for (device in devices) {
val isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
val uuid = FileUtils.getFileNameFromPath(device)
if (TextUtils.isEmpty(device) || TextUtils.isEmpty(uuid)) continue
- val isNew = (addExternal || isMainStorage) && medialibrary.addDevice(if (isMainStorage) "main-storage" else uuid, device, !isMainStorage)
+ val isNew = isMainStorage && (addExternal && withContext(VLCIO) { File(device).canRead() } )
+ && medialibrary.addDevice(if (isMainStorage) "main-storage" else uuid, device, !isMainStorage)
val isIgnored = sharedPreferences.getBoolean("ignore_$uuid", false)
if (!isMainStorage && isNew && !isIgnored) showStorageNotification(device)
}
More information about the Android
mailing list