Fix #33: allow reordering of play queue

This commit is contained in:
Drew Weymouth
2024-01-06 14:22:18 -08:00
parent 8683999f29
commit 9c2f72d9f2
4 changed files with 93 additions and 25 deletions
+21
View File
@@ -77,6 +77,7 @@ func NewNowPlayingPage(
DisablePlaybackMenu: true,
DisableRating: !canRate,
AuxiliaryMenuItems: []*fyne.MenuItem{
util.NewReorderTracksSubmenu(a.doSetNewTrackOrder),
fyne.NewMenuItem("Remove from queue", a.onRemoveSelectedFromQueue),
},
}
@@ -208,6 +209,26 @@ func (a *NowPlayingPage) onRemoveSelectedFromQueue() {
a.Reload()
}
func (a *NowPlayingPage) doSetNewTrackOrder(op sharedutil.TrackReorderOp) {
// Since the tracklist view may be sorted in a different order than the
// actual running order, we need to get the IDs of the selected tracks
// from the tracklist and convert them to indices in the *original* run order
ids := a.tracklist.SelectedTrackIDs()
idxs := make([]int, 0, len(ids))
for i, tr := range a.queue {
if sharedutil.SliceContains(ids, tr.ID) {
idxs = append(idxs, i)
}
}
newTracks := sharedutil.ReorderTracks(a.queue, idxs, op)
a.pm.UpdatePlayQueue(newTracks)
// force-switch back to unsorted view to show new track order
a.tracklist.SetSorting(widgets.TracklistSort{})
a.tracklist.SetTracks(newTracks)
a.tracklist.UnselectAll()
}
// does not make calls to server - can safely be run in UI callbacks
func (a *NowPlayingPage) load(highlightedTrackID string) {
a.queue = a.pm.GetPlayQueue()