diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt index 10d99b9a6..2dd0e0f76 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -55,6 +55,15 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va Medium.sorting = fileSorting media.sort() + val directories = groupDirectories(media) + val dirs = ArrayList(directories.values.filter { File(it.path).exists() }) + Directory.sorting = config.directorySorting + dirs.sort() + + return movePinnedToFront(dirs) + } + + private fun groupDirectories(media: ArrayList): Map { val hidden = context.resources.getString(R.string.hidden) val directories = LinkedHashMap() for ((name, path, isVideo, dateModified, dateTaken, size) in media) { @@ -80,12 +89,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va directories.put(parentDir, directory) } } - - val dirs = ArrayList(directories.values.filter { File(it.path).exists() }) - Directory.sorting = config.directorySorting - dirs.sort() - - return movePinnedToFront(dirs) + return directories } private fun movePinnedToFront(dirs: ArrayList): ArrayList {