From 16e5529375661505e693d4e8a93fd2d71d399659 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 29 Apr 2018 09:24:20 +0200 Subject: [PATCH] improve folder Distinction to avoid showing duplicate folders --- .../com/simplemobiletools/gallery/activities/MainActivity.kt | 2 +- .../com/simplemobiletools/gallery/extensions/Context.kt | 2 +- .../kotlin/com/simplemobiletools/gallery/extensions/String.kt | 4 ++++ .../com/simplemobiletools/gallery/helpers/MediaFetcher.kt | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 33c1ab8f8..76e45fc22 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -680,7 +680,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun showSortedDirs(dirs: ArrayList) { var sortedDirs = getSortedDirectories(dirs).clone() as ArrayList - sortedDirs = sortedDirs.distinctBy { it.path.toLowerCase() } as ArrayList + sortedDirs = sortedDirs.distinctBy { it.path.getDistinctPath() } as ArrayList runOnUiThread { (directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs) 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 8ef8e068c..c465a9c5e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -276,7 +276,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: } }) as ArrayList - callback(filteredDirectories.distinctBy { it.path.toLowerCase() } as ArrayList) + callback(filteredDirectories.distinctBy { it.path.getDistinctPath() } as ArrayList) removeInvalidDBDirectories(directories, directoryDao) }.start() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt index dd28e208b..a8f4a9f57 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/String.kt @@ -1,6 +1,7 @@ package com.simplemobiletools.gallery.extensions import com.bumptech.glide.signature.ObjectKey +import com.simplemobiletools.commons.helpers.OTG_PATH import java.io.File fun String.getFileSignature(): ObjectKey { @@ -32,3 +33,6 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet, includedPath true } } + +// recognize /sdcard/DCIM as the same folder as /storage/emulated/0/DCIM +fun String.getDistinctPath() = if (startsWith(OTG_PATH)) toLowerCase() else File(this).canonicalPath.toLowerCase() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 41d876701..3b04c9598 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -9,6 +9,7 @@ import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.photoExtensions import com.simplemobiletools.commons.helpers.videoExtensions import com.simplemobiletools.gallery.extensions.config +import com.simplemobiletools.gallery.extensions.getDistinctPath import com.simplemobiletools.gallery.extensions.getOTGFolderChildren import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.models.Medium @@ -139,7 +140,7 @@ class MediaFetcher(val context: Context) { foldersToScan.add(curPath) } - return foldersToScan.distinctBy { it.toLowerCase() } as ArrayList + return foldersToScan.distinctBy { it.getDistinctPath() } as ArrayList } private fun addFolder(curFolders: ArrayList, folder: String) {