From 13620df112f8702136f1fa1f53b1d89e02e06e20 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 6 Jun 2017 23:26:48 +0200 Subject: [PATCH] properly include files from manually Included folders --- .../gallery/extensions/context.kt | 37 +++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) 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 4a47f7ce9..b8f37cf99 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/context.kt @@ -70,12 +70,11 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP val config = context.config val showMedia = config.showMedia val showHidden = config.shouldShowHidden + val excludedFolders = config.excludedFolders + val noMediaFolders = context.getNoMediaFolders() cur.use { cur -> if (cur.moveToFirst()) { - val excludedFolders = config.excludedFolders - val noMediaFolders = context.getNoMediaFolders() - do { try { val path = cur.getStringValue(MediaStore.Images.Media.DATA) @@ -140,6 +139,38 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP } } + if (curPath.isEmpty()) { + config.includedFolders.mapNotNull { File(it).listFiles() }.forEach { + for (file in it) { + val size = file.length() + if (size <= 0L) { + continue + } + + val filename = file.name + val isImage = filename.isImageFast() || filename.isGif() + val isVideo = if (isImage) false else filename.isVideoFast() + + if (!isImage && !isVideo) + continue + + if (isVideo && (isPickImage || showMedia == IMAGES)) + continue + + if (isImage && (isPickVideo || showMedia == VIDEOS)) + continue + + val dateTaken = file.lastModified() + val dateModified = file.lastModified() + + val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateTaken, size) + val isAlreadyAdded = curMedia.any { it.path == file.absolutePath } + if (!isAlreadyAdded) + curMedia.add(medium) + } + } + } + Medium.sorting = config.getFileSorting(curPath) curMedia.sort()