improve folder Distinction to avoid showing duplicate folders

This commit is contained in:
tibbi 2018-04-29 09:24:20 +02:00
parent 55ee8c710b
commit 16e5529375
4 changed files with 8 additions and 3 deletions

View File

@ -680,7 +680,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
private fun showSortedDirs(dirs: ArrayList<Directory>) { private fun showSortedDirs(dirs: ArrayList<Directory>) {
var sortedDirs = getSortedDirectories(dirs).clone() as ArrayList<Directory> var sortedDirs = getSortedDirectories(dirs).clone() as ArrayList<Directory>
sortedDirs = sortedDirs.distinctBy { it.path.toLowerCase() } as ArrayList<Directory> sortedDirs = sortedDirs.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>
runOnUiThread { runOnUiThread {
(directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs) (directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs)

View File

@ -276,7 +276,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
} }
}) as ArrayList<Directory> }) as ArrayList<Directory>
callback(filteredDirectories.distinctBy { it.path.toLowerCase() } as ArrayList<Directory>) callback(filteredDirectories.distinctBy { it.path.getDistinctPath() } as ArrayList<Directory>)
removeInvalidDBDirectories(directories, directoryDao) removeInvalidDBDirectories(directories, directoryDao)
}.start() }.start()

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.gallery.extensions package com.simplemobiletools.gallery.extensions
import com.bumptech.glide.signature.ObjectKey import com.bumptech.glide.signature.ObjectKey
import com.simplemobiletools.commons.helpers.OTG_PATH
import java.io.File import java.io.File
fun String.getFileSignature(): ObjectKey { fun String.getFileSignature(): ObjectKey {
@ -32,3 +33,6 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
true 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()

View File

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.photoExtensions import com.simplemobiletools.commons.helpers.photoExtensions
import com.simplemobiletools.commons.helpers.videoExtensions import com.simplemobiletools.commons.helpers.videoExtensions
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getDistinctPath
import com.simplemobiletools.gallery.extensions.getOTGFolderChildren import com.simplemobiletools.gallery.extensions.getOTGFolderChildren
import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
@ -139,7 +140,7 @@ class MediaFetcher(val context: Context) {
foldersToScan.add(curPath) foldersToScan.add(curPath)
} }
return foldersToScan.distinctBy { it.toLowerCase() } as ArrayList<String> return foldersToScan.distinctBy { it.getDistinctPath() } as ArrayList<String>
} }
private fun addFolder(curFolders: ArrayList<String>, folder: String) { private fun addFolder(curFolders: ArrayList<String>, folder: String) {