Hi I am kind of lost. I try to use swiping and the last function I get working is withTargets. The andCallbacks function refuses to compile in kotlin. I am not sure what I am doing wrong. This is the Code I try to use:
EpoxyTouchHelper.initSwiping(recyclerView)
.leftAndRight() // Which directions to allow
.withTargets(IncomingTextMessageLayoutElementBindingModel_::class.java, OutgoingTextMessageLayoutElementBindingModel_::class.java)
.andCallbacks(object : EpoxyTouchHelper.SwipeCallbacks<IncomingTextMessageLayoutElementBindingModel_>() {
override fun onSwipeCompleted(model: IncomingTextMessageLayoutElementBindingModel_?, itemView: View?, position: Int, direction: Int) {
//Todo
}
})
Any hints what is wrong with this? It tells me that this is the wrong expected type:
Type mismatch: inferred type is
but EpoxyTouchHelper.SwipeCallbacks !>! was expected
You are using two different target types, so the callback type needs to be generic. The callback can't specify both target types
EpoxyTouchHelper.initSwiping(recyclerView)
.leftAndRight() // Which directions to allow
.withTargets(DataBindingItemBindingModel_::class.java, ItemEpoxyHolder_::class.java)
.andCallbacks(object: EpoxyTouchHelper.SwipeCallbacks<EpoxyModel<*>?>() {
override fun onSwipeCompleted(
model: EpoxyModel<*>?,
itemView: View?,
position: Int,
direction: Int
) {
}
})
if you use a single target than the callback type can be specific
EpoxyTouchHelper.initSwiping(recyclerView)
.leftAndRight() // Which directions to allow
.withTarget(DataBindingItemBindingModel_::class.java)
.andCallbacks(object: EpoxyTouchHelper.SwipeCallbacks<DataBindingItemBindingModel_?>() {
override fun onSwipeCompleted(
model: DataBindingItemBindingModel_?,
itemView: View?,
position: Int,
direction: Int
) {
}
})
Ah thank you! that makes a lot more sense
@elihart Didn't want to open a new issue as it somehow is related to this:
How can I prevent a swipe from fully removing the item from the list? Basicly that it jumps back in place after the swipe.
Most helpful comment
You are using two different target types, so the callback type needs to be generic. The callback can't specify both target types
if you use a single target than the callback type can be specific