Skip to content

Commit

Permalink
Expose isDragging state to clients and rename attachRecyclerView to a…
Browse files Browse the repository at this point in the history
…ttachToRecyclerView
  • Loading branch information
rubensousa committed Jun 15, 2024
1 parent 58dbd95 commit c3929d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion dpadrecyclerview/api/dpadrecyclerview.api
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public final class com/rubensousa/dpadrecyclerview/ChildAlignment$CREATOR : andr
public final class com/rubensousa/dpadrecyclerview/DpadDragHelper {
public fun <init> (Lcom/rubensousa/dpadrecyclerview/DpadDragHelper$DragAdapter;Lcom/rubensousa/dpadrecyclerview/DpadDragHelper$DragCallback;Ljava/util/Set;)V
public synthetic fun <init> (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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ class DpadDragHelper<T>(
)
) {

/**
* 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 {
Expand All @@ -60,7 +65,7 @@ class DpadDragHelper<T>(
* 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c3929d3

Please sign in to comment.