diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index cf5812187..d4b0780a0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -35,6 +35,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList() val config = Config.newInstance(activity) + var pinnedFolders = config.pinnedFolders companion object { var actMode: ActionMode? = null @@ -174,11 +175,17 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList (Unit)) : SwappingHolder(view, MultiSelector()) { - fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory, pos: Int): View { + fun bindView(activity: SimpleActivity, multiSelectorCallback: ModalMultiSelectorCallback, multiSelector: MultiSelector, directory: Directory, pos: Int, isPinned: Boolean) + : View { itemView.dir_name.text = directory.name itemView.photo_cnt.text = directory.mediaCnt.toString() + itemView.dir_pin.visibility = if (isPinned) View.VISIBLE else View.GONE toggleItemSelection(itemView, markedItems.contains(pos), pos) val tmb = directory.thumbnail 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 c33a834aa..2ea315e34 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetDirectoriesAsynctask.kt @@ -80,10 +80,26 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va } context.scanFiles(invalidFiles) {} - val dirs = ArrayList(directories.values) + var dirs = ArrayList(directories.values) filterDirectories(dirs) Directory.sorting = mConfig.directorySorting dirs.sort() + + dirs = movePinnedToFront(dirs) + + return dirs + } + + private fun movePinnedToFront(dirs: ArrayList): ArrayList { + if (dirs.isEmpty()) + return dirs + + val foundFolders = ArrayList() + val pinnedFolders = mConfig.pinnedFolders + + dirs.forEach { if (pinnedFolders.contains(it.path)) foundFolders.add(it) } + dirs.removeAll(foundFolders) + dirs.addAll(0, foundFolders) return dirs }