DevAhamed / MultiViewAdapter

Easily create complex recyclerview adapters in android
https://devahamed.github.io/MultiViewAdapter
Apache License 2.0
820 stars 149 forks source link

Disable swipe to dismiss for certain positions #96

Closed vkotovv closed 5 years ago

vkotovv commented 5 years ago

Swipe to dismiss feature is working nice, thanks. But can I disable this feature for certain positions/items (e.g. first item) in the RecyclerView? I'd like to use the same section for all items, because they are literally the same.

I'm using 3.x branch.

DevAhamed commented 5 years ago

Hi,

You can enable/disable swipe gesture for different ItemBinders. If you are using same ItemBinder, you have to override 'getSwipeDirections' and return different flags based on adapter position.

vkotovv commented 5 years ago

How do I get current position inside ViewHolder class (if I'm using the same binder)?

vkotovv commented 5 years ago

I've used a flag in my model to indicate if swipe is enabled. Thanks for the info!

Here is the code in my ViewHolder:

        override fun getSwipeDirections(): Int {
            return if (item.canSwipe) {
                ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
            } else {
                0
            }
        }