Commit 2e76520c authored by Geoffrey Métais's avatar Geoffrey Métais

DirectoryRepository: code cleaning

parent 60a65906
......@@ -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)
......
......@@ -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()) })
......
......@@ -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")
......
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