From c3929d3ed1978dc938da08549688b0676a51d4ab Mon Sep 17 00:00:00 2001 From: Ruben Sousa Date: Sat, 15 Jun 2024 12:26:49 +0200 Subject: [PATCH] Expose isDragging state to clients and rename attachRecyclerView to attachToRecyclerView --- dpadrecyclerview/api/dpadrecyclerview.api | 3 ++- .../com/rubensousa/dpadrecyclerview/DpadDragHelper.kt | 9 +++++++-- .../sample/ui/screen/drag/DragAndDropFragment.kt | 2 +- .../sample/ui/screen/drag/DragAndDropGridFragment.kt | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dpadrecyclerview/api/dpadrecyclerview.api b/dpadrecyclerview/api/dpadrecyclerview.api index 85ab7aa2..5f00f602 100644 --- a/dpadrecyclerview/api/dpadrecyclerview.api +++ b/dpadrecyclerview/api/dpadrecyclerview.api @@ -33,8 +33,9 @@ public final class com/rubensousa/dpadrecyclerview/ChildAlignment$CREATOR : andr public final class com/rubensousa/dpadrecyclerview/DpadDragHelper { public fun (Lcom/rubensousa/dpadrecyclerview/DpadDragHelper$DragAdapter;Lcom/rubensousa/dpadrecyclerview/DpadDragHelper$DragCallback;Ljava/util/Set;)V public synthetic fun (Lcom/rubensousa/dpadrecyclerview/DpadDragHelper$DragAdapter;Lcom/rubensousa/dpadrecyclerview/DpadDragHelper$DragCallback;Ljava/util/Set;ILkotlin/jvm/internal/DefaultConstructorMarker;)V - public final fun attachRecyclerView (Lcom/rubensousa/dpadrecyclerview/DpadRecyclerView;)V + public final fun attachToRecyclerView (Lcom/rubensousa/dpadrecyclerview/DpadRecyclerView;)V public final fun detachFromRecyclerView ()V + public final fun isDragging ()Z public final fun startDrag (I)Z public final fun stopDrag ()V } diff --git a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadDragHelper.kt b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadDragHelper.kt index a5d0b2fd..3bb09ed3 100644 --- a/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadDragHelper.kt +++ b/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadDragHelper.kt @@ -37,8 +37,13 @@ class DpadDragHelper( ) ) { + /** + * True if the attached [DpadRecyclerView] is currently in drag mode, false otherwise + */ + var isDragging: Boolean = false + private set + private var currentRecyclerView: DpadRecyclerView? = null - private var isDragging: Boolean = false private var previousKeyInterceptListener: DpadRecyclerView.OnKeyInterceptListener? = null private var keyInterceptListener = object : DpadRecyclerView.OnKeyInterceptListener { override fun onInterceptKeyEvent(event: KeyEvent): Boolean { @@ -60,7 +65,7 @@ class DpadDragHelper( * Attaches the [DpadRecyclerView] that will be dragged. * This is required before calling [startDrag] */ - fun attachRecyclerView(recyclerView: DpadRecyclerView) { + fun attachToRecyclerView(recyclerView: DpadRecyclerView) { if (currentRecyclerView === recyclerView) { return } diff --git a/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropFragment.kt b/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropFragment.kt index 84e881d5..aa784dbe 100644 --- a/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropFragment.kt +++ b/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropFragment.kt @@ -66,7 +66,7 @@ class DragAndDropFragment : Fragment(R.layout.screen_drag_drop) { private fun setupRecyclerView() { binding.recyclerView.apply { adapter = dragAdapter - dragHelper.attachRecyclerView(this) + dragHelper.attachToRecyclerView(this) itemAnimator = DefaultItemAnimator().apply { // For faster moves moveDuration = 100 diff --git a/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropGridFragment.kt b/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropGridFragment.kt index ab834b76..c57ea9c7 100644 --- a/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropGridFragment.kt +++ b/sample/src/main/java/com/rubensousa/dpadrecyclerview/sample/ui/screen/drag/DragAndDropGridFragment.kt @@ -67,7 +67,7 @@ class DragAndDropGridFragment : Fragment(R.layout.screen_drag_drop_grid) { private fun setupRecyclerView() { binding.recyclerView.apply { adapter = dragAdapter - dragHelper.attachRecyclerView(this) + dragHelper.attachToRecyclerView(this) itemAnimator = DefaultItemAnimator().apply { // For faster moves moveDuration = 100