From 1b1fac9b56eb5eeb7db5618b5d5ce180b9a6c15a Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 24 Apr 2020 17:48:26 +0200 Subject: [PATCH] flip some checks at Portrait photos to make it quicker --- .../simplemobiletools/gallery/pro/activities/MainActivity.kt | 3 ++- .../com/simplemobiletools/gallery/pro/extensions/Context.kt | 2 +- .../com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 6ca984710..086f853a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -954,6 +954,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { if (!directory.isRecycleBin()) { mediaDB.insertAll(curMedia) } + getCachedMedia(directory.path, getVideosOnly, getImagesOnly) { it.forEach { if (!curMedia.contains(it)) { @@ -1163,7 +1164,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } else if (it.path != config.tempFolderPath) { val children = if (isPathOnOTG(it.path)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() val hasMediaFile = children?.any { - it != null && (it.isMediaFile() || (File(it).isDirectory && it.startsWith("img_", true))) + it != null && (it.isMediaFile() || (it.startsWith("img_", true) && File(it).isDirectory)) } ?: false if (!hasMediaFile) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index 5c4bfabd2..cd68b5c55 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -564,7 +564,7 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag val foldersToAdd = ArrayList() for (folder in foldersToScan) { val allFiles = File(folder).listFiles() ?: continue - allFiles.filter { it.isDirectory && it.name.startsWith("img_", true) }.forEach { + allFiles.filter { it.name.startsWith("img_", true) && it.isDirectory }.forEach { foldersToAdd.add(it.absolutePath) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index ddf73d713..4145ba453 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -172,7 +172,7 @@ class MediaFetcher(val context: Context) { val config = context.config val includedFolders = config.includedFolders val OTGPath = config.OTGPath - var foldersToScan = config.everShownFolders.filter { it == FAVORITES || it == RECYCLE_BIN || context.getDoesFilePathExist(it, OTGPath) }.toHashSet() + val foldersToScan = config.everShownFolders.filter { it == FAVORITES || it == RECYCLE_BIN || context.getDoesFilePathExist(it, OTGPath) }.toHashSet() cursor.use { if (cursor.moveToFirst()) { @@ -244,7 +244,7 @@ class MediaFetcher(val context: Context) { val isSvg = if (isImage || isVideo || isGif || isRaw) false else path.isSvg() if (!isImage && !isVideo && !isGif && !isRaw && !isSvg) { - if (showPortraits && file.isDirectory && file.name.startsWith("img_", true)) { + if (showPortraits && file.name.startsWith("img_", true) && file.isDirectory) { val portraitFiles = file.listFiles() ?: continue val cover = portraitFiles.firstOrNull { it.name.contains("cover", true) } ?: portraitFiles.firstOrNull() if (cover != null && !files.contains(cover)) {