[Android] Code cleaning
Geoffrey Métais
git at videolan.org
Thu Oct 17 17:22:23 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 17 17:21:59 2019 +0200| [69657cbcbdc345aa88d1b53431fc0e2c064aba45] | committer: Geoffrey Métais
Code cleaning
> https://code.videolan.org/videolan/vlc-android/commit/69657cbcbdc345aa88d1b53431fc0e2c064aba45
---
vlc-android/src/org/videolan/vlc/MediaParsingService.kt | 12 ++++--------
vlc-android/src/org/videolan/vlc/util/FileUtils.kt | 13 +------------
2 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 204f088c3..7daac8a54 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -247,8 +247,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
}
private suspend fun addDevices(context: Context, addExternal: Boolean) {
- val devices = mutableListOf<String>()
- devices.addAll(DirectoryRepository.getInstance(context).getMediaDirectories())
+ val devices = DirectoryRepository.getInstance(context).getMediaDirectories()
val knownDevices = if (AndroidDevices.watchDevices) medialibrary.devices else null
for (device in devices) {
val isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
@@ -270,7 +269,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
medialibrary.discover(AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
}
else {
-
for (folder in preselectedStorages) {
medialibrary.discover(folder)
}
@@ -298,11 +296,11 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
val devices = AndroidDevices.externalStorageDirectories
Pair(devices, medialibrary.devices)
}
- val missingDevices = Util.arrayToArrayList(knownDevices)
+ val missingDevices = knownDevices.toMutableList()
missingDevices.remove("file://${AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY}")
for (device in devices) {
val uuid = FileUtils.getFileNameFromPath(device)
- if (TextUtils.isEmpty(device) || TextUtils.isEmpty(uuid) || !device.scanAllowed()) continue
+ if (device.isEmpty() || uuid.isEmpty() || !device.scanAllowed()) continue
if (containsDevice(knownDevices, device)) {
missingDevices.remove("file://$device")
continue
@@ -460,8 +458,7 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
}
private fun String.isSelected() : Boolean {
- if (preselectedStorages.isEmpty()) return false
- for (mrl in preselectedStorages) {
+ if (preselectedStorages.isNotEmpty()) for (mrl in preselectedStorages) {
if (mrl.substringAfter("file://").startsWith(this)) return true
}
return false
@@ -473,7 +470,6 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope, Lifec
val progress = MutableLiveData<ScanProgress>()
val newStorages = MutableLiveData<MutableList<String>>()
val preselectedStorages = mutableListOf<String>()
- var exceptionHandler : AbstractMedialibrary.MedialibraryExceptionHandler? = null
}
}
diff --git a/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index 400dae9ea..de2fe38de 100644
--- a/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -70,18 +70,7 @@ object FileUtils {
fun onResult(success: Boolean)
}
- fun getFileNameFromPath(path: String?): String {
- var path: String? = path ?: return ""
- var index = path!!.lastIndexOf('/')
- if (index == path.length - 1) {
- path = path.substring(0, index)
- index = path.lastIndexOf('/')
- }
- return if (index > -1)
- path.substring(index + 1)
- else
- path
- }
+ fun getFileNameFromPath(filePath: String?) = filePath?.substringBeforeLast('/') ?: ""
fun getParent(path: String?): String? {
if (path == null || TextUtils.equals("/", path))
More information about the Android
mailing list