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()
+4 -25
View File
@@ -86,18 +86,13 @@ func newPlaylistPage(
a.tracklist.OnVisibleColumnsChanged = func(cols []string) {
conf.TracklistColumns = cols
}
reorderMenu := fyne.NewMenuItem("Reorder tracks", nil)
reorderMenu.ChildMenu = fyne.NewMenu("", []*fyne.MenuItem{
fyne.NewMenuItem("Move to top", a.onMoveSelectedToTop),
fyne.NewMenuItem("Move up", a.onMoveSelectedUp),
fyne.NewMenuItem("Move down", a.onMoveSelectedDown),
fyne.NewMenuItem("Move to bottom", a.onMoveSelectedToBottom),
}...)
_, canRate := a.sm.Server.(mediaprovider.SupportsRating)
a.tracklist.Options = widgets.TracklistOptions{
DisableRating: !canRate,
AuxiliaryMenuItems: []*fyne.MenuItem{reorderMenu,
fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist)},
AuxiliaryMenuItems: []*fyne.MenuItem{
util.NewReorderTracksSubmenu(a.doSetNewTrackOrder),
fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist),
},
}
// connect tracklist actions
a.contr.ConnectTracklistActions(a.tracklist)
@@ -171,22 +166,6 @@ func renumberTracks(tracks []*mediaprovider.Track) {
}
}
func (a *PlaylistPage) onMoveSelectedToTop() {
a.doSetNewTrackOrder(sharedutil.MoveToTop)
}
func (a *PlaylistPage) onMoveSelectedUp() {
a.doSetNewTrackOrder(sharedutil.MoveUp)
}
func (a *PlaylistPage) onMoveSelectedDown() {
a.doSetNewTrackOrder(sharedutil.MoveDown)
}
func (a *PlaylistPage) onMoveSelectedToBottom() {
a.doSetNewTrackOrder(sharedutil.MoveToBottom)
}
func (a *PlaylistPage) 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
+12
View File
@@ -15,6 +15,7 @@ import (
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"golang.org/x/net/html"
@@ -180,6 +181,17 @@ func NewRatingSubmenu(onSetRating func(int)) *fyne.MenuItem {
return ratingMenu
}
func NewReorderTracksSubmenu(onReorderTracks func(sharedutil.TrackReorderOp)) *fyne.MenuItem {
reorderMenu := fyne.NewMenuItem("Reorder tracks", nil)
reorderMenu.ChildMenu = fyne.NewMenu("", []*fyne.MenuItem{
fyne.NewMenuItem("Move to top", func() { onReorderTracks(sharedutil.MoveToTop) }),
fyne.NewMenuItem("Move up", func() { onReorderTracks(sharedutil.MoveUp) }),
fyne.NewMenuItem("Move down", func() { onReorderTracks(sharedutil.MoveDown) }),
fyne.NewMenuItem("Move to bottom", func() { onReorderTracks(sharedutil.MoveToBottom) }),
}...)
return reorderMenu
}
func AddHeaderBackground(obj fyne.CanvasObject) *fyne.Container {
bgrnd := myTheme.NewThemedRectangle(myTheme.ColorNamePageHeader)
bgrnd.CornerRadiusName = theme.SizeNameInputRadius