Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,35 @@ class RadioQueue(private val symphony: Symphony) {
}
}

// UI drop area is before the song, so we put fromI before toI
fun handleDragAndDrop(fromIndex: Int, fromSongId: String, toIndex: Int) {
if (fromIndex == toIndex || fromIndex == toIndex - 1) {
return
}
val newIndex = if (fromIndex < toIndex) toIndex - 1 else toIndex
originalQueue.removeAt(fromIndex)
currentQueue.removeAt(fromIndex)
originalQueue.add(newIndex, fromSongId)
currentQueue.add(newIndex, fromSongId)
if (newIndex <= currentSongIndex) { // song moved to before currently playing
currentSongIndex++
}
if (fromIndex < currentSongIndex) { // song moved was before currently playing
currentSongIndex--
} else if (fromIndex == currentSongIndex) { // song moved is currently playing
//TODO: this introduces a small break in playback
symphony.radio.play(
Radio.PlayOptions(
index = newIndex,
autostart = symphony.radio.isPlaying,
startPosition = symphony.radio.currentPlaybackPosition?.played
)
)
currentSongIndex = newIndex
}
symphony.radio.onUpdate.dispatch(Radio.Events.Queue.Modified)
}

fun setLoopMode(loopMode: LoopMode) {
currentLoopMode = loopMode
}
Expand Down
Loading