From e61dace0ddcb5713bcef10b55f3b77d478bd6c96 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Wed, 19 Apr 2023 18:13:31 -0700 Subject: [PATCH] #136: add menu button to album page with options to add album to queue or playlist --- CHANGELOG.md | 1 + sharedutil/sharedutil.go | 8 ++++++++ ui/browsing/albumpage.go | 19 ++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e2dfc6..3d39303 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - [#55](https://github.com/dweymouth/supersonic/issues/55) Show disc number and disc count for multi-disc albums - [#115](https://github.com/dweymouth/supersonic/issues/115) Add search bar to artist, genres, and playlists pages - [#104](https://github.com/dweymouth/supersonic/issues/104) Add alternate (e.g. external) hostname to server connection config +- [#136](https://github.com/dweymouth/supersonic/issues/136) Add "..." button to album page with menu to add album to queue or playlist ### Fixes - **todo-commithash** Don't show update available prompt if the found version is the same as the running app version diff --git a/sharedutil/sharedutil.go b/sharedutil/sharedutil.go index 1dbbee4..e62703f 100644 --- a/sharedutil/sharedutil.go +++ b/sharedutil/sharedutil.go @@ -51,6 +51,14 @@ func TrackIDOrEmptyStr(track *subsonic.Child) string { return track.ID } +func TracksToIDs(tracks []*subsonic.Child) []string { + ret := make([]string, len(tracks)) + for i, tr := range tracks { + ret[i] = tr.ID + } + return ret +} + type TrackReorderOp int const ( diff --git a/ui/browsing/albumpage.go b/ui/browsing/albumpage.go index b3b6368..0cd8f46 100644 --- a/ui/browsing/albumpage.go +++ b/ui/browsing/albumpage.go @@ -175,6 +175,23 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader { page.pm.LoadTracks(page.tracklist.Tracks, false, true) page.pm.PlayFromBeginning() }) + var pop *widget.PopUpMenu + menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil) + menuBtn.OnTapped = func() { + if pop == nil { + menu := fyne.NewMenu("", + fyne.NewMenuItem("Add to queue", func() { + a.page.pm.LoadAlbum(a.albumID, true /*append*/, false /*shuffle*/) + }), + fyne.NewMenuItem("Add to playlist...", func() { + a.page.contr.DoAddTracksToPlaylistWorkflow( + sharedutil.TracksToIDs(a.page.tracklist.Tracks)) + })) + pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a)) + } + pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(menuBtn) + pop.ShowAtPosition(fyne.NewPos(pos.X, pos.Y+menuBtn.Size().Height)) + } a.toggleFavButton = widgets.NewFavoriteButton(func() { go a.toggleFavorited() }) // Todo: there's got to be a way to make this less convoluted. Custom layout? @@ -184,7 +201,7 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader { container.NewVBox( container.New(&layouts.VboxCustomPadding{ExtraPad: -12}, a.artistLabel, a.genreLabel, a.miscLabel), container.NewVBox( - container.NewHBox(util.NewHSpace(2), playButton, shuffleBtn), + container.NewHBox(util.NewHSpace(2), playButton, shuffleBtn, menuBtn), container.NewHBox(util.NewHSpace(2), a.toggleFavButton), ), ),