From ec5fd3d08819c50c2962dd6d086599e294d762c9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 12 May 2021 23:32:03 +0200 Subject: [PATCH] add the reordering animation at drag and drop --- .../gallery/pro/adapters/DirectoryAdapter.kt | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) 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 09ee897f1..c7ea3253f 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 @@ -8,6 +8,7 @@ import android.graphics.drawable.ColorDrawable import android.graphics.drawable.Icon import android.text.TextUtils import android.view.Menu +import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.RelativeLayout @@ -48,6 +49,9 @@ import kotlinx.android.synthetic.main.directory_item_list.view.dir_drag_handle import kotlinx.android.synthetic.main.directory_item_list.view.dir_holder import kotlinx.android.synthetic.main.directory_item_list.view.photo_cnt import java.io.File +import java.util.* +import kotlin.collections.ArrayList +import kotlin.collections.HashMap class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView, val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : @@ -98,7 +102,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList - setupView(itemView, dir) + setupView(itemView, dir, holder) } bindViewHolder(holder) } @@ -699,7 +703,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + if (event.action == MotionEvent.ACTION_DOWN) { + startReorderDragListener.requestDrag(holder) + } + false + } + } } } - override fun onRowClear(myViewHolder: ViewHolder?) { - } - override fun onRowMoved(fromPosition: Int, toPosition: Int) { + if (fromPosition < toPosition) { + for (i in fromPosition until toPosition) { + Collections.swap(dirs, i, i + 1) + } + } else { + for (i in fromPosition downTo toPosition + 1) { + Collections.swap(dirs, i, i - 1) + } + } + + notifyItemMoved(fromPosition, toPosition) } - override fun onRowSelected(myViewHolder: ViewHolder?) { - } + override fun onRowClear(myViewHolder: ViewHolder?) {} + + override fun onRowSelected(myViewHolder: ViewHolder?) {} }