Skip to content

Commit

Permalink
fix: prevent null pointer exception when queue is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Nov 27, 2024
1 parent eef3458 commit b85a0d4
Showing 1 changed file with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,21 @@ class RadioQueue(private val symphony: Symphony) {

fun setShuffleMode(to: Boolean) {
currentShuffleMode = to
val currentSongId = getSongIdAt(currentSongIndex)!!
currentSongIndex = if (currentShuffleMode) {
val newQueue = originalQueue.toMutableList()
newQueue.removeAt(currentSongIndex)
newQueue.shuffle()
newQueue.add(0, currentSongId)
currentQueue.clear()
currentQueue.addAll(newQueue)
0
} else {
currentQueue.clear()
currentQueue.addAll(originalQueue)
currentQueue.indexOfFirst { it == currentSongId }
if (currentQueue.isNotEmpty()) {
val currentSongId = getSongIdAt(currentSongIndex) ?: getSongIdAt(0)!!
currentSongIndex = if (currentShuffleMode) {
val newQueue = originalQueue.toMutableList()
newQueue.removeAt(currentSongIndex)
newQueue.shuffle()
newQueue.add(0, currentSongId)
currentQueue.clear()
currentQueue.addAll(newQueue)
0
} else {
currentQueue.clear()
currentQueue.addAll(originalQueue)
currentQueue.indexOfFirst { it == currentSongId }
}
}
symphony.radio.onUpdate.dispatch(Radio.Events.Queue.Modified)
}
Expand Down

0 comments on commit b85a0d4

Please sign in to comment.