From 18332d847838f198e3d3b8160355c6ba459ca045 Mon Sep 17 00:00:00 2001 From: Jay Date: Thu, 12 Nov 2026 16:32:39 -0500 Subject: [PATCH] list: rubber-band the swipe reveal, mute swipes while playlist-editing --- .../oxycblt/auxio/detail/DetailFragment.kt | 10 +++++-- .../list/recycler/SwipeActionsCallback.kt | 29 +++++++++++++++---- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/oxycblt/auxio/detail/DetailFragment.kt b/app/src/main/java/org/oxycblt/auxio/detail/DetailFragment.kt index 172ce8930..b0e98cccf 100644 --- a/app/src/main/java/org/oxycblt/auxio/detail/DetailFragment.kt +++ b/app/src/main/java/org/oxycblt/auxio/detail/DetailFragment.kt @@ -125,8 +125,14 @@ abstract class DetailFragment

: binding.detailRecycler.apply { adapter = getDetailListAdapter() } ItemTouchHelper( - SwipeActionsCallback(isEnabled = { listModel.selected.value.isEmpty() }) { - song, + SwipeActionsCallback( + // Queue swipes are inert during multi-select and while a playlist is being + // edited (the editing gestures — reorder, remove — own the rows then). + isEnabled = { + listModel.selected.value.isEmpty() && + detailModel.editedPlaylist.value == null + } + ) { song, action -> when (action) { SwipeActionsCallback.SwipeAction.QUEUE -> playbackModel.addToQueue(song) diff --git a/app/src/main/java/org/oxycblt/auxio/list/recycler/SwipeActionsCallback.kt b/app/src/main/java/org/oxycblt/auxio/list/recycler/SwipeActionsCallback.kt index 049a91f5a..12846f84c 100644 --- a/app/src/main/java/org/oxycblt/auxio/list/recycler/SwipeActionsCallback.kt +++ b/app/src/main/java/org/oxycblt/auxio/list/recycler/SwipeActionsCallback.kt @@ -28,6 +28,7 @@ import androidx.recyclerview.widget.RecyclerView import com.google.android.material.R as MR import kotlin.math.abs import kotlin.math.min +import kotlin.math.sign import org.oxycblt.auxio.R import org.oxycblt.auxio.list.adapter.FlexibleListAdapter import org.oxycblt.auxio.util.getAttrColorCompat @@ -98,8 +99,9 @@ class SwipeActionsCallback( song, if (direction == ItemTouchHelper.END) SwipeAction.QUEUE else SwipeAction.PLAY_NEXT, ) - // The row stays: rebind it in place, cancelling the swipe-out animation. - recyclerView.adapter?.notifyItemChanged(position) + // The row stays: rebind it in place, cancelling the swipe-out animation. The payload + // keeps the item animator from cross-fading the row. + recyclerView.adapter?.notifyItemChanged(position, PAYLOAD_SWIPE_COMMIT) } /** @@ -123,11 +125,10 @@ class SwipeActionsCallback( actionState: Int, isCurrentlyActive: Boolean, ) { - // Clamp the slide to the square underlay: the row resists past the reveal. + // Free slide up to the square cell, then rubber-band resistance past it. val clampedDX = if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) { - val reveal = revealWidth(viewHolder).toFloat() - dX.coerceIn(-reveal, reveal) + rubberBand(dX, revealWidth(viewHolder).toFloat()) } else { dX } @@ -137,6 +138,19 @@ class SwipeActionsCallback( super.onChildDraw(c, recyclerView, viewHolder, clampedDX, dY, actionState, isCurrentlyActive) } + /** + * Map a raw drag to its visual translation: one-to-one up to [reveal], then increasing + * resistance asymptotic to twice the reveal, so the row can be pulled past the cell but + * fights back more the further it goes. + */ + private fun rubberBand(dX: Float, reveal: Float): Float { + val past = abs(dX) - reveal + if (past <= 0f) { + return dX + } + return sign(dX) * (reveal + past / (1f + past / reveal)) + } + /** The square underlay cell's width: a standard large touchable size. */ private fun revealWidth(viewHolder: RecyclerView.ViewHolder) = viewHolder.itemView.context.getDimenPixels(R.dimen.size_touchable_large) @@ -199,4 +213,9 @@ class SwipeActionsCallback( ) icon.draw(c) } + + private companion object { + /** Payload for the in-place rebind after a committed swipe; avoids the cross-fade. */ + val PAYLOAD_SWIPE_COMMIT = Any() + } }