From da47c199d92ad3263eaaf83743fab7c277feede1 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 13 May 2021 21:53:29 +0200 Subject: [PATCH] add some menu buttons for quickly moving a folder to the top or bottom --- app/build.gradle | 2 +- .../gallery/pro/adapters/DirectoryAdapter.kt | 43 ++++++++++++++++--- app/src/main/res/menu/cab_directories.xml | 10 +++++ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 59547752c..66366e3b9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -78,7 +78,7 @@ android { } dependencies { - implementation 'com.github.SimpleMobileTools:Simple-Commons:94718a76cb' + implementation 'com.github.SimpleMobileTools:Simple-Commons:5c4094baf8' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.22' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index 88241ab2e..caf048394 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -67,7 +67,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() - private var isChangingOrder = false + private var isDragAndDropping = false private var startReorderDragListener: StartReorderDragListener private var showMediaCount = config.showFolderMediaCount @@ -111,6 +111,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList moveSelectedItemsToTop() + R.id.cab_move_to_bottom -> moveSelectedItemsToBottom() R.id.cab_properties -> showProperties() R.id.cab_rename -> renameDir() R.id.cab_pin -> pinFolders(true) @@ -173,7 +179,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + val position = dirs.indexOfFirst { it.path.hashCode() == key } + val tempItem = dirs[position] + dirs.removeAt(position) + dirs.add(0, tempItem) + } + + notifyDataSetChanged() + } + + private fun moveSelectedItemsToBottom() { + selectedKeys.forEach { key -> + val position = dirs.indexOfFirst { it.path.hashCode() == key } + val tempItem = dirs[position] + dirs.removeAt(position) + dirs.add(dirs.size, tempItem) + } + + notifyDataSetChanged() + } + private fun showProperties() { if (selectedKeys.size <= 1) { val path = getFirstSelectedItemPath() ?: return @@ -463,8 +491,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList if (event.action == MotionEvent.ACTION_DOWN) { diff --git a/app/src/main/res/menu/cab_directories.xml b/app/src/main/res/menu/cab_directories.xml index b1265795e..196107fda 100644 --- a/app/src/main/res/menu/cab_directories.xml +++ b/app/src/main/res/menu/cab_directories.xml @@ -1,6 +1,16 @@ + +