1

The main usage of my RecyclerView is to change the order of items. What's more, after order changes, I need to get data about the position from where drag started and where it was dropped(finished).

I've already implemented ItemTouchHelper.Callback() and covered it with interface, works great but the only problem is how to get only FIRST and LAST position of the item.

I haven't found any solution using ItemTouchHelper, tried combining onSelectedChanged and clearView but it doesn't work. Also, I'm using Subjects from RxJava2 to push the value but haven't found solution by using any kind of filter operator.

override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
    adapter.onItemMoved(viewHolder.adapterPosition, target.adapterPosition)
    return true
}

private fun swapItems(positionFrom: Int, positionTo: Int) {
    Collections.swap(myList, positionFrom, positionTo)

    myList.forEachIndexed { index, myObject -> myListUpdated.add(myObject.copy(index = index)) }
    myListSubject.onNext(myListUpdated.toList())

    notifyItemMoved(positionFrom, positionTo)
}

At this moment I'm getting every swapped position from onMove(so from 1 to 2, from 2 to 3, from 3 to 4). I would like to achieve from 1 to 4, without the middle steps.

Denathan
  • 141
  • 10

0 Answers0