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>) {
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 {
(directories_grid.adapter as DirectoryAdapter).updateDirs(sortedDirs)

View file

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

View file

@ -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<String>, 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()

View file

@ -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<String>
return foldersToScan.distinctBy { it.getDistinctPath() } as ArrayList<String>
}
private fun addFolder(curFolders: ArrayList<String>, folder: String) {