ui: disable default actions in drag helpers

Disable the default long-press action in the ItemTouchHelper usages.

ItemTouchHelper provides a long-press action to start an item drag by
default. However, because Auxio adds a drag handle on top of this
action, this actually results in a conflict with the default behavior
in certain cases. Replace it with a custom version of the long-press
action within the viewholders themselves.
This commit is contained in:
OxygenCobalt 2022-03-07 08:29:58 -07:00
parent d3d6d18d5d
commit 7b5c49a5b3
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
6 changed files with 24 additions and 7 deletions

View file

@ -16,6 +16,8 @@ from the system theme was used [#80]
- Fixed years deliberately set as "0" showing up as "No Date" - Fixed years deliberately set as "0" showing up as "No Date"
- Fixed headset management unexpectedly starting audio when the app initially opens - Fixed headset management unexpectedly starting audio when the app initially opens
- Fixed crash that would occur during a playback restore with specific queue states [#89] - Fixed crash that would occur during a playback restore with specific queue states [#89]
- Partially fixed buggy behavior when multiple queue items were dragged in quick
succession
#### What's Changed #### What's Changed
- All cover art is now cropped to a 1:1 aspect ratio - All cover art is now cropped to a 1:1 aspect ratio

View file

@ -70,14 +70,19 @@ class TabAdapter(
isChecked = tab is Tab.Visible isChecked = tab is Tab.Visible
} }
// Roll our own drag handlers as the default ones suck
binding.tabDragHandle.setOnTouchListener { _, motionEvent -> binding.tabDragHandle.setOnTouchListener { _, motionEvent ->
binding.tabDragHandle.performClick() binding.tabDragHandle.performClick()
if (motionEvent.actionMasked == MotionEvent.ACTION_DOWN) { if (motionEvent.actionMasked == MotionEvent.ACTION_DOWN) {
touchHelper.startDrag(this) touchHelper.startDrag(this)
true true
} else false } else false
} }
binding.root.setOnLongClickListener {
touchHelper.startDrag(this)
true
}
} }
} }
} }

View file

@ -25,6 +25,8 @@ import androidx.recyclerview.widget.RecyclerView
/** /**
* A simple [ItemTouchHelper.Callback] that handles dragging items in the tab customization menu. * A simple [ItemTouchHelper.Callback] that handles dragging items in the tab customization menu.
* Unlike QueueAdapter's ItemTouchHelper, this one is bare and simple. * Unlike QueueAdapter's ItemTouchHelper, this one is bare and simple.
* TODO: Consider unifying the shared behavior between this and QueueDragCallback into a single
* class.
*/ */
class TabDragCallback(private val getTabs: () -> Array<Tab>) : ItemTouchHelper.Callback() { class TabDragCallback(private val getTabs: () -> Array<Tab>) : ItemTouchHelper.Callback() {
private val tabs: Array<Tab> get() = getTabs() private val tabs: Array<Tab> get() = getTabs()
@ -70,6 +72,9 @@ class TabDragCallback(private val getTabs: () -> Array<Tab>) : ItemTouchHelper.C
override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {} override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {}
// We use a custom drag handle, so disable the long press action.
override fun isLongPressDragEnabled(): Boolean = false
/** /**
* Add the tab adapter to this callback. * Add the tab adapter to this callback.
* Done because there's a circular dependency between the two objects * Done because there's a circular dependency between the two objects

View file

@ -142,14 +142,19 @@ class QueueAdapter(
binding.songName.requestLayout() binding.songName.requestLayout()
binding.songInfo.requestLayout() binding.songInfo.requestLayout()
// Roll our own drag handlers as the default ones suck
binding.songDragHandle.setOnTouchListener { _, motionEvent -> binding.songDragHandle.setOnTouchListener { _, motionEvent ->
binding.songDragHandle.performClick() binding.songDragHandle.performClick()
if (motionEvent.actionMasked == MotionEvent.ACTION_DOWN) { if (motionEvent.actionMasked == MotionEvent.ACTION_DOWN) {
touchHelper.startDrag(this) touchHelper.startDrag(this)
true true
} else false } else false
} }
binding.body.setOnLongClickListener {
touchHelper.startDrag(this)
true
}
} }
} }

View file

@ -128,7 +128,7 @@ class QueueDragCallback(private val playbackModel: PlaybackViewModel) : ItemTouc
// When an elevated item is cleared, we reset the elevation using another animation. // When an elevated item is cleared, we reset the elevation using another animation.
val holder = viewHolder as QueueAdapter.QueueSongViewHolder val holder = viewHolder as QueueAdapter.QueueSongViewHolder
if (holder.itemView.translationZ != 0.0f) { if (holder.itemView.translationZ != 0f) {
logD("Dropping queue item") logD("Dropping queue item")
val bg = holder.bodyView.background as MaterialShapeDrawable val bg = holder.bodyView.background as MaterialShapeDrawable
@ -165,6 +165,8 @@ class QueueDragCallback(private val playbackModel: PlaybackViewModel) : ItemTouc
} }
} }
override fun isLongPressDragEnabled(): Boolean = false
/** /**
* Add the queue adapter to this callback. * Add the queue adapter to this callback.
* Done because there's a circular dependency between the two objects * Done because there's a circular dependency between the two objects

View file

@ -43,15 +43,13 @@ class QueueFragment : Fragment() {
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View { ): View {
val binding = FragmentQueueBinding.inflate(inflater) val binding = FragmentQueueBinding.inflate(inflater)
val callback = QueueDragCallback(playbackModel) val callback = QueueDragCallback(playbackModel)
val helper = ItemTouchHelper(callback) val helper = ItemTouchHelper(callback)
val queueAdapter = QueueAdapter(helper) val queueAdapter = QueueAdapter(helper)
var lastShuffle = playbackModel.isShuffling.value
callback.addQueueAdapter(queueAdapter) callback.addQueueAdapter(queueAdapter)
var lastShuffle = playbackModel.isShuffling.value
// --- UI SETUP --- // --- UI SETUP ---
binding.lifecycleOwner = viewLifecycleOwner binding.lifecycleOwner = viewLifecycleOwner