queue: use mdc drag handle

Use a real mdc drag handle on the queue sheet.

The accessibility functions won't even be enabled, but that
would need to be communicated in a special way anyway.
This commit is contained in:
Alexander Capehart 2023-05-29 10:37:36 -06:00
parent d97eaf67b9
commit 40af4adc51
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
5 changed files with 24 additions and 36 deletions

View file

@ -122,8 +122,7 @@ class MainFragment :
logD("Configuring stacked bottom sheets")
val playbackSheetBehavior =
binding.playbackSheet.coordinatorLayoutBehavior as PlaybackBottomSheetBehavior
// TODO: Use the material handle
unlikelyToBeNull(binding.handleWrapper).setOnClickListener {
unlikelyToBeNull(binding.queueHandleWrapper).setOnClickListener {
if (playbackSheetBehavior.state == BackportBottomSheetBehavior.STATE_EXPANDED &&
queueSheetBehavior.state == BackportBottomSheetBehavior.STATE_COLLAPSED) {
// Playback sheet is expanded and queue sheet is collapsed, we can expand it.
@ -515,7 +514,8 @@ class MainFragment :
// TODO: Debug why this fails sometimes on the playback sheet
// TODO: Add playlist editing to enabled check
// TODO: Can this be split up?
// TODO: Chain these listeners in some way instead of keeping them all here,
// assuming listeners added later have more priority
isEnabled =
queueSheetBehavior?.state == BackportBottomSheetBehavior.STATE_EXPANDED ||

View file

@ -201,13 +201,15 @@ class EditableQueue : Queue {
}
/**
* Add [Song]s to the top of the queue. Will start playback if nothing is playing.
* Add [Song]s to the "top" of the queue (right next to the currently playing song). Will start
* playback if nothing is playing.
*
* @param songs The [Song]s to add.
* @return A [Queue.Change] instance that reflects the changes made.
*/
fun playNext(songs: List<Song>): Queue.Change {
fun addToTop(songs: List<Song>): Queue.Change {
logD("Adding ${songs.size} songs to the front of the queue")
val insertAt = index + 1
val heapIndices = songs.map(::addSongToHeap)
if (shuffledMapping.isNotEmpty()) {
// Add the new songs in front of the current index in the shuffled mapping and in front
@ -215,15 +217,14 @@ class EditableQueue : Queue {
logD("Must append songs to shuffled mapping")
val orderedIndex = orderedMapping.indexOf(shuffledMapping[index])
orderedMapping.addAll(orderedIndex + 1, heapIndices)
shuffledMapping.addAll(index + 1, heapIndices)
shuffledMapping.addAll(insertAt, heapIndices)
} else {
// Add the new song in front of the current index in the ordered mapping.
logD("Only appending songs to ordered mapping")
orderedMapping.addAll(index + 1, heapIndices)
orderedMapping.addAll(insertAt, heapIndices)
}
check()
return Queue.Change(
Queue.Change.Type.MAPPING, UpdateInstructions.Add(index + 1, songs.size))
return Queue.Change(Queue.Change.Type.MAPPING, UpdateInstructions.Add(insertAt, songs.size))
}
/**
@ -232,9 +233,9 @@ class EditableQueue : Queue {
* @param songs The [Song]s to add.
* @return A [Queue.Change] instance that reflects the changes made.
*/
fun addToQueue(songs: List<Song>): Queue.Change {
fun addToBottom(songs: List<Song>): Queue.Change {
logD("Adding ${songs.size} songs to the back of the queue")
val point = orderedMapping.size
val insertAt = orderedMapping.size
val heapIndices = songs.map(::addSongToHeap)
// Can simple append the new songs to the end of both mappings.
orderedMapping.addAll(heapIndices)
@ -243,7 +244,7 @@ class EditableQueue : Queue {
shuffledMapping.addAll(heapIndices)
}
check()
return Queue.Change(Queue.Change.Type.MAPPING, UpdateInstructions.Add(point, songs.size))
return Queue.Change(Queue.Change.Type.MAPPING, UpdateInstructions.Add(insertAt, songs.size))
}
/**
@ -367,7 +368,7 @@ class EditableQueue : Queue {
}
}
logD("Serialized heap [max shift=$currentShift]")
logD("Created adjustment mapping [max shift=$currentShift]")
heap = savedState.heap.filterNotNull().toMutableList()
orderedMapping =

View file

@ -444,7 +444,7 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
play(songs[0], null, songs, false)
} else {
logD("Adding ${songs.size} songs to start of queue")
notifyQueueChanged(queue.playNext(songs))
notifyQueueChanged(queue.addToTop(songs))
}
}
@ -455,7 +455,7 @@ class PlaybackStateManagerImpl @Inject constructor() : PlaybackStateManager {
play(songs[0], null, songs, false)
} else {
logD("Adding ${songs.size} songs to end of queue")
notifyQueueChanged(queue.addToQueue(songs))
notifyQueueChanged(queue.addToBottom(songs))
}
}

View file

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="32dp"
android:height="4dp" />
<corners android:radius="2dp" />
<solid android:color="#FFF" />
</shape>

View file

@ -46,20 +46,16 @@
app:layout_behavior="org.oxycblt.auxio.playback.queue.QueueBottomSheetBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/handle_wrapper"
android:id="@+id/queue_handle_wrapper"
android:contentDescription="@string/desc_queue_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/size_bottom_sheet_bar">
<ImageView
android:id="@+id/handle"
<com.google.android.material.bottomsheet.BottomSheetDragHandleView
android:id="@+id/queue_handle"
android:layout_width="match_parent"
android:layout_height="@dimen/size_btn"
android:contentDescription="@string/desc_queue_bar"
android:paddingBottom="@dimen/spacing_mid_large"
android:scaleType="center"
android:src="@drawable/ui_queue_drag_handle"
app:layout_constraintTop_toTopOf="parent"
app:tint="?attr/colorOnSurfaceVariant" />
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/queue_title"
@ -68,8 +64,8 @@
android:text="@string/lbl_queue"
android:textAppearance="@style/TextAppearance.Auxio.LabelLarge"
android:textColor="?attr/colorOnSurfaceVariant"
app:layout_constraintBottom_toBottomOf="@+id/handle"
app:layout_constraintEnd_toEndOf="@+id/handle"
app:layout_constraintBottom_toBottomOf="@+id/queue_handle"
app:layout_constraintEnd_toEndOf="@+id/queue_handle"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>