filter wrong directories sooner

This commit is contained in:
tibbi 2017-02-26 12:26:32 +01:00
parent e243de95d1
commit ad8cd557ce
2 changed files with 19 additions and 22 deletions

View file

@ -25,32 +25,29 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
val parents = context.getParents() val parents = context.getParents()
parents.forEach { parents.forEach {
val dir = File(it) val filenames = File(it).list()
if (dir.isDirectory) { if (filenames?.size ?: 0 > 0) {
val filenames = dir.list() for (filename in filenames) {
if (filenames?.size ?: 0 > 0) { val isImage = filename.isImageFast() || filename.isGif()
for (filename in filenames) { val isVideo = if (isImage) false else filename.isVideoFast()
val isImage = filename.isImageFast() || filename.isGif()
val isVideo = if (isImage) false else filename.isVideoFast()
if (!isImage && !isVideo) if (!isImage && !isVideo)
continue continue
if (isVideo && (isPickImage || showMedia == IMAGES)) if (isVideo && (isPickImage || showMedia == IMAGES))
continue continue
if (isImage && (isPickVideo || showMedia == VIDEOS)) if (isImage && (isPickVideo || showMedia == VIDEOS))
continue continue
val file = File(it, filename) val file = File(it, filename)
val size = file.length() val size = file.length()
if (size == 0L) if (size == 0L)
continue continue
val dateModified = file.lastModified() val dateModified = file.lastModified()
val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size) val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size)
media.add(medium) media.add(medium)
}
} }
} }
} }

View file

@ -68,7 +68,7 @@ fun Context.getParents(): ArrayList<String> {
} }
val parents = ArrayList<String>() val parents = ArrayList<String>()
parentsSet.mapTo(parents, { it }) parentsSet.filterTo(parents, { File(it).isDirectory })
if (config.showHiddenFolders) { if (config.showHiddenFolders) {
parents.addAll(getNoMediaFolders()) parents.addAll(getNoMediaFolders())