Created
March 28, 2021 12:50
-
-
Save Kashif-E/a59b732d13b03b6074bb3548ee43c681 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 { | |
//getting the adapter | |
val adapter = recyclerView.adapter as MoviesAdapter | |
//the position from where item has been moved | |
val from = viewHolder.adapterPosition | |
//the position where the item is moved | |
val to = target.adapterPosition | |
//telling the adapter to move the item | |
adapter.notifyItemMoved(from, to) | |
return true | |
} | |
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { | |
} | |
override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { | |
super.onSelectedChanged(viewHolder, actionState) | |
} | |
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) { | |
super.clearView(recyclerView, viewHolder) | |
} | |
} | |
ItemTouchHelper(simpleItemTouchCallback) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment