add the reordering animation at drag and drop

This commit is contained in:
tibbi 2021-05-12 23:32:03 +02:00
parent c73300ccd2
commit ec5fd3d088
1 changed files with 30 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.text.TextUtils import android.text.TextUtils
import android.view.Menu import android.view.Menu
import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.RelativeLayout 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.dir_holder
import kotlinx.android.synthetic.main.directory_item_list.view.photo_cnt import kotlinx.android.synthetic.main.directory_item_list.view.photo_cnt
import java.io.File import java.io.File
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView, class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
@ -98,7 +102,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val dir = dirs.getOrNull(position) ?: return val dir = dirs.getOrNull(position) ?: return
holder.bindView(dir, true, !isPickIntent) { itemView, adapterPosition -> holder.bindView(dir, true, !isPickIntent) { itemView, adapterPosition ->
setupView(itemView, dir) setupView(itemView, dir, holder)
} }
bindViewHolder(holder) bindViewHolder(holder)
} }
@ -699,7 +703,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
notifyDataSetChanged() notifyDataSetChanged()
} }
private fun setupView(view: View, directory: Directory) { private fun setupView(view: View, directory: Directory, holder: ViewHolder) {
val isSelected = selectedKeys.contains(directory.path.hashCode()) val isSelected = selectedKeys.contains(directory.path.hashCode())
view.apply { view.apply {
dir_path?.text = "${directory.path.substringBeforeLast("/")}/" dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
@ -795,15 +799,34 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} else { } else {
dir_drag_handle_wrapper.beVisibleIf(isChangingOrder) dir_drag_handle_wrapper.beVisibleIf(isChangingOrder)
} }
if (isChangingOrder) {
dir_drag_handle.applyColorFilter(textColor)
dir_drag_handle.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
startReorderDragListener.requestDrag(holder)
}
false
}
}
} }
} }
override fun onRowClear(myViewHolder: ViewHolder?) {
}
override fun onRowMoved(fromPosition: Int, toPosition: Int) { 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?) {}
} }