[Android] DirectoryRepository: code cleaning

Geoffrey Métais git at videolan.org
Tue Feb 5 18:33:09 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Feb  5 18:04:11 2019 +0100| [2e76520c4493d09522bf7e24d52dbca11713ce0b] | committer: Geoffrey Métais

DirectoryRepository: code cleaning

> https://code.videolan.org/videolan/vlc-android/commit/2e76520c4493d09522bf7e24d52dbca11713ce0b
---

 .../src/org/videolan/vlc/MediaParsingService.kt    |  5 ++---
 .../videolan/vlc/repository/DirectoryRepository.kt | 24 ++++++++--------------
 .../vlc/viewmodels/browser/BrowserModel.kt         |  2 --
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
index 710493d4d..168259e2c 100644
--- a/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
+++ b/vlc-android/src/org/videolan/vlc/MediaParsingService.kt
@@ -49,7 +49,6 @@ import org.videolan.vlc.gui.wizard.startMLWizard
 import org.videolan.vlc.repository.DirectoryRepository
 import org.videolan.vlc.util.*
 import java.io.File
-import java.util.*
 
 private const val TAG = "VLC/MediaParsingService"
 private const val NOTIFICATION_DELAY = 1000L
@@ -205,8 +204,8 @@ class MediaParsingService : Service(), DevicesDiscoveryCb, CoroutineScope {
     }
 
     private suspend fun addDevices(context: Context, addExternal: Boolean) {
-        val devices = ArrayList<String>()
-        Collections.addAll(devices, *DirectoryRepository.getInstance(context).getMediaDirectories())
+        val devices = mutableListOf<String>()
+        devices.addAll(DirectoryRepository.getInstance(context).getMediaDirectories())
         val sharedPreferences = Settings.getInstance(context)
         for (device in devices) {
             val isMainStorage = TextUtils.equals(device, AndroidDevices.EXTERNAL_PUBLIC_DIRECTORY)
diff --git a/vlc-android/src/org/videolan/vlc/repository/DirectoryRepository.kt b/vlc-android/src/org/videolan/vlc/repository/DirectoryRepository.kt
index d81e0064f..f21054430 100644
--- a/vlc-android/src/org/videolan/vlc/repository/DirectoryRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/DirectoryRepository.kt
@@ -36,22 +36,14 @@ class DirectoryRepository (private val customDirectoryDao: CustomDirectoryDao) :
 
     suspend fun customDirectoryExists(path: String) = withContext(coroutineContext) { customDirectoryDao.get(path).isNotEmpty() }
 
-    suspend fun getMediaDirectoriesList(context: Context): List<MediaWrapper> {
-        val storages = getMediaDirectories()
-
-        return storages.filter { File(it).exists() }.map {
-            createDirectory(it, context)
-        }.toList()
-    }
-
-    suspend fun getMediaDirectories(): Array<String> {
-        val list = mutableListOf<String>()
-
-        list.add(EXTERNAL_PUBLIC_DIRECTORY)
-        list.addAll(getExternalStorageDirectories())
-        list.addAll(getCustomDirectories().map { it.path })
-
-        return list.toTypedArray()
+    suspend fun getMediaDirectoriesList(context: Context) = getMediaDirectories().filter {
+        File(it).exists()
+    }.map { createDirectory(it, context) }
+
+    suspend fun getMediaDirectories() = mutableListOf<String>().apply {
+        add(EXTERNAL_PUBLIC_DIRECTORY)
+        addAll(getExternalStorageDirectories())
+        addAll(getCustomDirectories().map { it.path })
     }
 
     companion object : SingletonHolder<DirectoryRepository, Context>({ DirectoryRepository(MediaDatabase.getInstance(it).customDirectoryDao()) })
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
index 9a28371a5..3280b4a38 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/browser/BrowserModel.kt
@@ -81,8 +81,6 @@ open class BrowserModel(context: Context, val url: String?, type: Int, showHidde
 
     suspend fun customDirectoryExists(path: String) = DirectoryRepository.getInstance(context).customDirectoryExists(path)
 
-    suspend fun getMediaDirectories() = DirectoryRepository.getInstance(context).getMediaDirectories()
-
     class Factory(val context: Context, val url: String?, private val type: Int,  private val showHiddenFiles: Boolean): ViewModelProvider.NewInstanceFactory() {
         override fun <T : ViewModel> create(modelClass: Class<T>): T {
             @Suppress("UNCHECKED_CAST")



More information about the Android mailing list