From d64473820a4f72bfd2e8115e3acdb2cd65afe611 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 7 Nov 2020 23:30:11 +0100 Subject: [PATCH] adding support for horizontal item dragging --- build.gradle | 2 +- .../commons/interfaces/ItemMoveCallback.kt | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 32161007a..e02826a92 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 - propVersionName = '5.31.27' + propVersionName = '5.31.28' kotlin_version = '1.4.10' } diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/interfaces/ItemMoveCallback.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/interfaces/ItemMoveCallback.kt index d08854da8..4df864e30 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/interfaces/ItemMoveCallback.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/interfaces/ItemMoveCallback.kt @@ -4,7 +4,7 @@ import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter -open class ItemMoveCallback(private val mAdapter: ItemTouchHelperContract) : ItemTouchHelper.Callback() { +open class ItemMoveCallback(private val mAdapter: ItemTouchHelperContract, private val allowHorizontalDrag: Boolean = false) : ItemTouchHelper.Callback() { override fun isLongPressDragEnabled() = false override fun isItemViewSwipeEnabled() = false @@ -12,7 +12,10 @@ open class ItemMoveCallback(private val mAdapter: ItemTouchHelperContract) : Ite override fun onSwiped(viewHolder: RecyclerView.ViewHolder, i: Int) {} override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder): Int { - val dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN + var dragFlags = ItemTouchHelper.UP or ItemTouchHelper.DOWN + if (allowHorizontalDrag) { + dragFlags = dragFlags or ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT + } return makeMovementFlags(dragFlags, 0) }