Browse Source

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

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
50c8dac297
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 8
      app/src/main/java/com/github/apognu/otter/fragments/QueueFragment.kt
  2. 1
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  3. 21
      app/src/main/java/com/github/apognu/otter/playback/QueueManager.kt
  4. 1
      app/src/main/java/com/github/apognu/otter/utils/Bus.kt
  5. 45
      app/src/main/res/layout/partial_queue.xml
  6. 1
      app/src/main/res/values-fr/strings.xml
  7. 1
      app/src/main/res/values/strings.xml

8
app/src/main/java/com/github/apognu/otter/fragments/QueueFragment.kt

@ -62,6 +62,14 @@ class QueueFragment : BottomSheetDialogFragment() { @@ -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()
}

1
app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

@ -186,6 +186,7 @@ class PlayerService : Service() { @@ -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()

21
app/src/main/java/com/github/apognu/otter/playback/QueueManager.kt

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

1
app/src/main/java/com/github/apognu/otter/utils/Bus.kt

@ -27,6 +27,7 @@ sealed class Command { @@ -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()

45
app/src/main/res/layout/partial_queue.xml

@ -1,8 +1,47 @@ @@ -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 @@ @@ -26,4 +65,4 @@
android:visibility="gone"
tools:visibility="visible" />
</FrameLayout>
</LinearLayout>

1
app/src/main/res/values-fr/strings.xml

@ -63,6 +63,7 @@ @@ -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>

1
app/src/main/res/values/strings.xml

@ -64,6 +64,7 @@ @@ -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…
Cancel
Save