mikepenz/FastAdapter

Suggestion - Extend ISwipeable

MFlisar opened this issue · 6 comments

About this issue

I want to distinguish between items the do allow swipe left / swipe right / both. Currently I can only distinguish can swipe / can not swipe.

My suggestion is to extend the ISwipeable interface:

interface ISwipeable {
    /** @return true if swipeable */
    val isSwipeable: Boolean

    /** @return true if the provided direction is supported */
    fun isDirectionSupported(direction: Int) : Boolean = true
}

What do you think about this? It's a very small and backwards compatible change with the default implementation inside the interface. isDirectionSupported will only be called if isSwipeable return true.

Details

  •  Used library version: 5.4.1
  •  Used support library version: androidx

@MFlisar being able to identify the swipeable direction makes sense.

How would the real implementation for isDirectionSupported look like?
Would a different interface not also fullfil this requirement? (As the implementation itself would also fall in the target apps responsibility it looks like?)

How would the real implementation for isDirectionSupported look like?

I do have items that do support "starting" them and sections, that do not support this. But both items do support delete. so I would use it like following:

In my case like following:

class ItemSection(val data: Data) : IItem, ISwipeable  {

	val isSwipeable: Boolean = true
	
	fun isDirectionSupported(direction: Int) : Boolean {
		return direction = ItemTouchHelper.RIGHT; // only right swipe is supported, sections can only be deleted and can't be started
	}
	
}

class Item(val data: Data) : IItem, ISwipeable  {
	
	val isSwipeable: Boolean = true
	
	fun isDirectionSupported(direction: Int) : Boolean {
		return true; // items can be started and deleted, so both swipe directions are supported
	}
	
}

Would a different interface not also fullfil this requirement?

Sure, but personally I think an interface with default implementation is more discoverable (especially if the features are so closely)

By the way, if backwards compatibility is not required, I would even replace the interface with following for the sake of simplicity:

interface ISwipeable {
    fun isSwipeable(direction: Int) : Boolean
}

Migration guide would simply look like following:

Replace

  override val isSwipeable = true|false

With

 override fun isSwipeable(direction: Int) = true|false

I'd opt for the backwards compatible form. Looked over it, and your proposal makes sense.
It will also need to be integrated SimpleSwipeDrawerCallback and SimpleSwipeCallback

Would you like to open a PR for this?

Would you like to open a PR for this?

Done

Thank you so much. Will be in the next update