Skip to content

Commit

Permalink
Fix bug causing track to get queued at unexpected location
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Jun 16, 2024
1 parent cd4f747 commit df0c88e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion music/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
subprojects {
version = "3.8.1-SNAPSHOT"
version = "3.8.2-SNAPSHOT"
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Queue(private var tracksList: MutableList<QueuedTrack> = mutableListOf())

fun poll(): QueuedTrack {
val queuedTrack = tracksList[order.poll()]
nextIndex = nextIndex.coerceAtMost(order.size)
if (order.size == 0) {
nextIndex--
if (order.isEmpty()) {
shuffle = false
}
return queuedTrack
Expand Down
13 changes: 13 additions & 0 deletions music/player/src/test/kotlin/QueueTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@ class QueueTest {

assertFalse(queue.shuffle)
}

@Test
fun `test index gets updated after non-shuffle queue finishes`() {
val queue = makeMockQueue()
queue.shuffle = true
queue.addTracks(mockTrack(23))
queue.addTracks(mockTrack(24))
queue.addTracks(mockTrack(25))
repeat(3) { queue.poll() }
val track = mockTrack(26)
queue.addTracks(track)
assertEquals(track, queue.poll())
}
}

private fun makeMockQueue() = Queue(MutableList(10, ::mockTrack))
Expand Down

0 comments on commit df0c88e

Please sign in to comment.