#66: add queue actions to clear or shuffle the queue.
This commit is contained in:
parent
1dd38e87fb
commit
50c8dac297
|
@ -62,6 +62,14 @@ class QueueFragment : BottomSheetDialogFragment() {
|
|||
included.queue?.visibility = View.GONE
|
||||
placeholder?.visibility = View.VISIBLE
|
||||
|
||||
queue_shuffle.setOnClickListener {
|
||||
CommandBus.send(Command.ShuffleQueue)
|
||||
}
|
||||
|
||||
queue_clear.setOnClickListener {
|
||||
CommandBus.send(Command.ClearQueue)
|
||||
}
|
||||
|
||||
refresh()
|
||||
}
|
||||
|
||||
|
|
|
@ -186,6 +186,7 @@ class PlayerService : Service() {
|
|||
is Command.Seek -> seek(command.progress)
|
||||
|
||||
is Command.ClearQueue -> queue.clear()
|
||||
is Command.ShuffleQueue -> queue.shuffle()
|
||||
|
||||
is Command.PlayRadio -> {
|
||||
queue.clear()
|
||||
|
|
|
@ -179,4 +179,25 @@ class QueueManager(val context: Context) {
|
|||
datasources.clear()
|
||||
current = -1
|
||||
}
|
||||
|
||||
fun shuffle() {
|
||||
if (metadata.size == 0) return
|
||||
|
||||
if (current == -1) {
|
||||
replace(metadata.shuffled())
|
||||
} else {
|
||||
val track = metadata[current]
|
||||
val shuffled = metadata.filter { it != track }.shuffled()
|
||||
|
||||
shuffled.forEach {
|
||||
metadata.remove(it)
|
||||
}
|
||||
|
||||
append(shuffled)
|
||||
|
||||
current = 0
|
||||
}
|
||||
|
||||
EventBus.send(Event.QueueChanged)
|
||||
}
|
||||
}
|
|
@ -27,6 +27,7 @@ sealed class Command {
|
|||
class RemoveFromQueue(val track: Track) : Command()
|
||||
class MoveFromQueue(val oldPosition: Int, val newPosition: Int) : Command()
|
||||
object ClearQueue : Command()
|
||||
object ShuffleQueue : Command()
|
||||
class PlayRadio(val radio: Radio) : Command()
|
||||
|
||||
class SetRepeatMode(val mode: Int) : Command()
|
||||
|
|
|
@ -1,8 +1,47 @@
|
|||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/surface"
|
||||
android:layout_height="wrap_content">
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="8dp"
|
||||
android:paddingVertical="4dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/queue_shuffle"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/playback_shuffle"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textSize="12sp"
|
||||
app:icon="@drawable/shuffle"
|
||||
app:iconTint="@color/colorPrimary"
|
||||
app:rippleColor="@color/ripple" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/queue_clear"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton.Icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/playback_queue_clear"
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textSize="12sp"
|
||||
app:icon="@drawable/delete"
|
||||
app:iconTint="@color/colorPrimary"
|
||||
app:rippleColor="@color/ripple" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/queue"
|
||||
|
@ -26,4 +65,4 @@
|
|||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
|
@ -63,6 +63,7 @@
|
|||
<string name="playback_queue_add_item">Ajouter à la liste de lecture</string>
|
||||
<string name="playback_queue_play_next">Prochaine écoute</string>
|
||||
<string name="playback_queue_download">Télécharger</string>
|
||||
<string name="playback_queue_clear">Effacer</string>
|
||||
<string name="manage_add_to_favorites">Ajouter aux favoris</string>
|
||||
<string name="control_toggle">Lecture / pause</string>
|
||||
<string name="control_previous">Piste précédente</string>
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
<string name="playback_queue_add_item">Add to queue</string>
|
||||
<string name="playback_queue_play_next">Play next</string>
|
||||
<string name="playback_queue_download">Download</string>
|
||||
<string name="playback_queue_clear">Clear</string>
|
||||
<string name="manage_add_to_favorites">Add to favorites</string>
|
||||
<string name="control_toggle">Toggle playback</string>
|
||||
<string name="control_previous">Previous track</string>
|
||||
|
|
Loading…
Reference in New Issue