Created
March 28, 2021 12:39
-
-
Save Kashif-E/095af68e23c30e8cb60bae69c1fbd2af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val itemTouchHelper by lazy { | |
val simpleItemTouchCallback = object : ItemTouchHelper.SimpleCallback(UP or DOWN or START or END, 0) { | |
override fun onMove(recyclerView: RecyclerView, | |
viewHolder: RecyclerView.ViewHolder, | |
target: RecyclerView.ViewHolder): Boolean { | |
//on move lets you check if an item has been moved from its position either up or down | |
return true | |
} | |
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | |
//on swipe tells you when an item is swiped left or right from its position ( swipe to delete) | |
} | |
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { | |
super.onSelectedChanged(viewHolder, actionState) | |
//when an item changes its location that is currently selected this funtion is called | |
} | |
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { | |
super.clearView(recyclerView, viewHolder) | |
//when we stop dragging , swiping or moving an item this function is called | |
} | |
} | |
ItemTouchHelper(simpleItemTouchCallback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment