Reciclador Ver drag and drop en diferentes types de vista

Implementé drag and drop para la vista de reciclador con el android ItemTouchHelper pnetworkingeterminado como la siguiente implementación.

https://github.com/iPaulPro/Android-ItemTouchHelper-Demo

Mi class de callback se ve de la siguiente manera.

 class ItemTouchHelperCallback(private val mAdapter: ItemTouchHelperAdapter) : ItemTouchHelper.Callback() { override fun isLongPressDragEnabled(): Boolean = true override fun isItemViewSwipeEnabled(): Boolean = false override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int { // Set movement flags based on the layout manager return if (recyclerView.layoutManager is GridLayoutManager) { val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN or ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT val swipeFlags = 0 ItemTouchHelper.Callback.makeMovementFlags(dragFlags, swipeFlags) } else { val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN or ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT val swipeFlags = ItemTouchHelper.START or ItemTouchHelper.END ItemTouchHelper.Callback.makeMovementFlags(dragFlags, swipeFlags) } } override fun onMove(recyclerView: RecyclerView, source: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { // Notify the adapter of the move mAdapter.onItemMove(source.adapterPosition, target.adapterPosition) return true } override fun onSwiped(viewHolder: RecyclerView.ViewHolder, i: Int) { // Notify the adapter of the dismissal mAdapter.onItemDismiss(viewHolder.adapterPosition) } override fun onChildDraw(c: Canvas, recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { // Fade out the view as it is swiped out of the parent's bounds val alpha = ALPHA_FULL - Math.abs(dX) / viewHolder.itemView.width.toFloat() viewHolder.itemView.alpha = alpha viewHolder.itemView.translationX = dX } else { super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive) } } override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { // We only want the active item to change if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) { if (viewHolder is ItemTouchHelperViewHolder) { // Let the view holder know that this item is being moved or dragged val itemViewHolder = viewHolder as ItemTouchHelperViewHolder? itemViewHolder!!.onItemSelected() } } super.onSelectedChanged(viewHolder, actionState) } override fun clearView(recyclerView: RecyclerView?, viewHolder: RecyclerView.ViewHolder) { super.clearView(recyclerView, viewHolder) viewHolder.itemView.alpha = ALPHA_FULL if (viewHolder is ItemTouchHelperViewHolder) { // Tell the view holder it's time to restre the idle state val itemViewHolder = viewHolder as ItemTouchHelperViewHolder itemViewHolder.onItemClear() } } companion object { val ALPHA_FULL = 1.0f } } 

Pero el drag and drop no se lleva a cabo correctamente. Cuando el elemento comienza a moverse, se llama a la siguiente class.

 override fun onMove(recyclerView: RecyclerView, source: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { // Notify the adapter of the move mAdapter.onItemMove(source.adapterPosition, target.adapterPosition) return true }