From ad8cd557cee6aa26355df1cf683c1ca9a2353c19 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 26 Feb 2017 12:26:32 +0100 Subject: [PATCH] filter wrong directories sooner --- .../asynctasks/GetDirectoriesAsynctask.kt | 39 +++++++++---------- .../gallery/extensions/context.kt | 2 +- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 0260ade1d..10d99b9a6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -25,32 +25,29 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va val parents = context.getParents() parents.forEach { - val dir = File(it) - if (dir.isDirectory) { - val filenames = dir.list() - if (filenames?.size ?: 0 > 0) { - for (filename in filenames) { - val isImage = filename.isImageFast() || filename.isGif() - val isVideo = if (isImage) false else filename.isVideoFast() + val filenames = File(it).list() + if (filenames?.size ?: 0 > 0) { + for (filename in filenames) { + val isImage = filename.isImageFast() || filename.isGif() + val isVideo = if (isImage) false else filename.isVideoFast() - if (!isImage && !isVideo) - continue + if (!isImage && !isVideo) + continue - if (isVideo && (isPickImage || showMedia == IMAGES)) - continue + if (isVideo && (isPickImage || showMedia == IMAGES)) + continue - if (isImage && (isPickVideo || showMedia == VIDEOS)) - continue + if (isImage && (isPickVideo || showMedia == VIDEOS)) + continue - val file = File(it, filename) - val size = file.length() - if (size == 0L) - continue + val file = File(it, filename) + val size = file.length() + if (size == 0L) + continue - val dateModified = file.lastModified() - val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size) - media.add(medium) - } + val dateModified = file.lastModified() + val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateModified, size) + media.add(medium) } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt index ccdad77d3..47042f219 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -68,7 +68,7 @@ fun Context.getParents(): ArrayList { } val parents = ArrayList() - parentsSet.mapTo(parents, { it }) + parentsSet.filterTo(parents, { File(it).isDirectory }) if (config.showHiddenFolders) { parents.addAll(getNoMediaFolders())