#66: add queue actions to clear or shuffle the queue.

This commit is contained in:
Antoine POPINEAU 2020-09-01 21:06:00 +02:00
parent 1dd38e87fb
commit 50c8dac297
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
7 changed files with 75 additions and 3 deletions

View File

@ -62,6 +62,14 @@ class QueueFragment : BottomSheetDialogFragment() {
included.queue?.visibility = View.GONE included.queue?.visibility = View.GONE
placeholder?.visibility = View.VISIBLE placeholder?.visibility = View.VISIBLE
queue_shuffle.setOnClickListener {
CommandBus.send(Command.ShuffleQueue)
}
queue_clear.setOnClickListener {
CommandBus.send(Command.ClearQueue)
}
refresh() refresh()
} }

View File

@ -186,6 +186,7 @@ class PlayerService : Service() {
is Command.Seek -> seek(command.progress) is Command.Seek -> seek(command.progress)
is Command.ClearQueue -> queue.clear() is Command.ClearQueue -> queue.clear()
is Command.ShuffleQueue -> queue.shuffle()
is Command.PlayRadio -> { is Command.PlayRadio -> {
queue.clear() queue.clear()

View File

@ -179,4 +179,25 @@ class QueueManager(val context: Context) {
datasources.clear() datasources.clear()
current = -1 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)
}
} }

View File

@ -27,6 +27,7 @@ sealed class Command {
class RemoveFromQueue(val track: Track) : Command() class RemoveFromQueue(val track: Track) : Command()
class MoveFromQueue(val oldPosition: Int, val newPosition: Int) : Command() class MoveFromQueue(val oldPosition: Int, val newPosition: Int) : Command()
object ClearQueue : Command() object ClearQueue : Command()
object ShuffleQueue : Command()
class PlayRadio(val radio: Radio) : Command() class PlayRadio(val radio: Radio) : Command()
class SetRepeatMode(val mode: Int) : Command() class SetRepeatMode(val mode: Int) : Command()

View File

@ -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" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/surface" 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 <androidx.recyclerview.widget.RecyclerView
android:id="@+id/queue" android:id="@+id/queue"
@ -26,4 +65,4 @@
android:visibility="gone" android:visibility="gone"
tools:visibility="visible" /> tools:visibility="visible" />
</FrameLayout> </LinearLayout>

View File

@ -63,6 +63,7 @@
<string name="playback_queue_add_item">Ajouter à la liste de lecture</string> <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_play_next">Prochaine écoute</string>
<string name="playback_queue_download">Télécharger</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="manage_add_to_favorites">Ajouter aux favoris</string>
<string name="control_toggle">Lecture / pause</string> <string name="control_toggle">Lecture / pause</string>
<string name="control_previous">Piste précédente</string> <string name="control_previous">Piste précédente</string>

View File

@ -64,6 +64,7 @@
<string name="playback_queue_add_item">Add to queue</string> <string name="playback_queue_add_item">Add to queue</string>
<string name="playback_queue_play_next">Play next</string> <string name="playback_queue_play_next">Play next</string>
<string name="playback_queue_download">Download</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="manage_add_to_favorites">Add to favorites</string>
<string name="control_toggle">Toggle playback</string> <string name="control_toggle">Toggle playback</string>
<string name="control_previous">Previous track</string> <string name="control_previous">Previous track</string>