mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
move pinned items to front
This commit is contained in:
parent
0857391189
commit
411ae47136
2 changed files with 31 additions and 5 deletions
|
@ -35,6 +35,7 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
val multiSelector = MultiSelector()
|
||||
val views = ArrayList<View>()
|
||||
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<Direc
|
|||
}
|
||||
|
||||
private fun pinFolder() {
|
||||
|
||||
config.addPinnedFolders(getSelectedPaths())
|
||||
pinnedFolders = config.pinnedFolders
|
||||
listener?.refreshItems()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun unpinFolder() {
|
||||
|
||||
config.removePinnedFolders(getSelectedPaths())
|
||||
pinnedFolders = config.pinnedFolders
|
||||
listener?.refreshItems()
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun displayCopyDialog() {
|
||||
|
@ -233,15 +240,18 @@ class DirectoryAdapter(val activity: SimpleActivity, val dirs: MutableList<Direc
|
|||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
views.add(holder.bindView(activity, multiSelectorMode, multiSelector, dirs[position], position))
|
||||
val dir = dirs[position]
|
||||
views.add(holder.bindView(activity, multiSelectorMode, multiSelector, dir, position, pinnedFolders.contains(dir.path)))
|
||||
}
|
||||
|
||||
override fun getItemCount() = dirs.size
|
||||
|
||||
class ViewHolder(view: View, val itemClick: (Directory) -> (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
|
||||
|
|
|
@ -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<Directory>): ArrayList<Directory> {
|
||||
if (dirs.isEmpty())
|
||||
return dirs
|
||||
|
||||
val foundFolders = ArrayList<Directory>()
|
||||
val pinnedFolders = mConfig.pinnedFolders
|
||||
|
||||
dirs.forEach { if (pinnedFolders.contains(it.path)) foundFolders.add(it) }
|
||||
dirs.removeAll(foundFolders)
|
||||
dirs.addAll(0, foundFolders)
|
||||
return dirs
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue