0

I have created a recyclerView with swipe to delete functionality.

I am having an item that I don't want to it to be archived.

I want to implement the swipe on the items that cant be deleted so that the user can scroll a little bit, when he scroll he see's a red background indicating that the item can't be archived and once he stops swiping the swipe will close instead of doing the animation to archive the item.

I have managed to make the item scroll less by doing add this line to my onDrawChild method:

            if (hasActiveActions) {
                // layout that I don't want to be deleted
                super.onChildDraw(c, recyclerView, viewHolder, dX / 5, dY, actionState, isCurrentlyActive)
            } else {
                super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
            }

The problem is that the animation to delete the item still occurs once the user scrolled enough, I want to get the same behaviour that the item is swipe a little bit but then closes instead of having the animation.

I also tried overriding getMovementFlags:

override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int {
              val adapter = recyclerView.adapter
              if (adapter is NotificationsRecyclerViewAdapter) {
                  if (adapter.itemCount > 0 && adapter.notifications[viewHolder.adapterPosition].hasActiveNotifications())
                      // disable swipe for item with actions
                      return 0
              }
              return super.getMovementFlags(recyclerView, viewHolder)

The problem that it disables the scroll.

Gal
  • 422
  • 5
  • 21

0 Answers0