import android.graphics.Canvas
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import java.util.*
class WorkOrderICreatedItemCallback(val adapter: WorkOrderICreatedAdapter)
: ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP or ItemTouchHelper.DOWN, ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
Collections.swap(adapter.list, viewHolder.absoluteAdapterPosition, target.absoluteAdapterPosition)
adapter.notifyItemMoved(viewHolder.absoluteAdapterPosition, target.absoluteAdapterPosition)
return true
}
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
adapter.list.removeAt(viewHolder.absoluteAdapterPosition);
adapter.notifyItemRemoved(viewHolder.absoluteAdapterPosition);
}
override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) {
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
// viewHolder.itemView.translationX = dX
}
}
val callback = WorkOrderICreatedItemCallback(adapter)
val helper = ItemTouchHelper(callback)
helper.attachToRecyclerView(binding.container)