feat: Add Share option for artists, albums, and tracks
This feature is only available on the Subsonic media provider. Using a Jellyfin server will make Supersonic hide the "Share" option. * Artists: Option available in grid view and in Artist view. * Albums: Option available in grid view and in Album view. * Tracks: Option available in tracklist, when a single track is selected.
This commit is contained in:
+11
-1
@@ -93,6 +93,7 @@ type GridViewState struct {
|
||||
OnAddToQueue func(id string)
|
||||
OnAddToPlaylist func(id string)
|
||||
OnDownload func(id string)
|
||||
OnShare func(id string)
|
||||
OnShowItemPage func(id string)
|
||||
OnShowSecondaryPage func(id string)
|
||||
|
||||
@@ -407,8 +408,17 @@ func (g *GridView) showContextMenu(card *GridViewItem, pos fyne.Position) {
|
||||
}
|
||||
})
|
||||
download.Icon = theme.DownloadIcon()
|
||||
menuItems := []*fyne.MenuItem{play, shuffle, queue, playlist, download}
|
||||
|
||||
g.menu = widget.NewPopUpMenu(fyne.NewMenu("", play, shuffle, queue, playlist, download),
|
||||
if g.OnShare != nil {
|
||||
share := fyne.NewMenuItem("Share...", func() {
|
||||
g.OnShare(g.menuGridViewItemId)
|
||||
})
|
||||
share.Icon = myTheme.ShareIcon
|
||||
menuItems = append(menuItems, share)
|
||||
}
|
||||
|
||||
g.menu = widget.NewPopUpMenu(fyne.NewMenu("", menuItems...),
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g))
|
||||
}
|
||||
g.menu.ShowAtPosition(pos)
|
||||
|
||||
@@ -72,6 +72,9 @@ type TracklistOptions struct {
|
||||
|
||||
// Disables the five star rating widget.
|
||||
DisableRating bool
|
||||
|
||||
// Hides the sharing option.
|
||||
HideSharing bool
|
||||
}
|
||||
|
||||
type Tracklist struct {
|
||||
@@ -87,6 +90,7 @@ type Tracklist struct {
|
||||
OnSetFavorite func(trackIDs []string, fav bool)
|
||||
OnSetRating func(trackIDs []string, rating int)
|
||||
OnDownload func(tracks []*mediaprovider.Track, downloadName string)
|
||||
OnShare func(trackID string)
|
||||
|
||||
OnShowArtistPage func(artistID string)
|
||||
OnShowAlbumPage func(albumID string)
|
||||
@@ -108,6 +112,7 @@ type Tracklist struct {
|
||||
list *FocusList
|
||||
ctxMenu *fyne.Menu
|
||||
ratingSubmenu *fyne.MenuItem
|
||||
shareMenuItem *fyne.MenuItem
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
@@ -555,6 +560,13 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||
})
|
||||
unfavorite.Icon = myTheme.NotFavoriteIcon
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items, playlist, download)
|
||||
if !t.Options.HideSharing {
|
||||
t.shareMenuItem = fyne.NewMenuItem("Share...", func() {
|
||||
t.onShare(t.selectedTracks())
|
||||
})
|
||||
t.shareMenuItem.Icon = myTheme.ShareIcon
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items, t.shareMenuItem)
|
||||
}
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
|
||||
t.ctxMenu.Items = append(t.ctxMenu.Items, favorite, unfavorite)
|
||||
t.ratingSubmenu = util.NewRatingSubmenu(func(rating int) {
|
||||
@@ -567,6 +579,9 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||
}
|
||||
}
|
||||
t.ratingSubmenu.Disabled = t.Options.DisableRating
|
||||
if t.shareMenuItem != nil {
|
||||
t.shareMenuItem.Disabled = len(t.selectedTracks()) != 1
|
||||
}
|
||||
widget.ShowPopUpMenuAtPosition(t.ctxMenu, fyne.CurrentApp().Driver().CanvasForObject(t), e.AbsolutePosition)
|
||||
}
|
||||
|
||||
@@ -629,6 +644,15 @@ func (t *Tracklist) onDownload(tracks []*mediaprovider.Track, downloadName strin
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracklist) onShare(tracks []*mediaprovider.Track) {
|
||||
if t.OnShare != nil {
|
||||
selectedTrackIDs := t.SelectedTrackIDs()
|
||||
if len(selectedTrackIDs) > 0 {
|
||||
t.OnShare(selectedTrackIDs[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Tracklist) selectedTracks() []*mediaprovider.Track {
|
||||
t.tracksMutex.RLock()
|
||||
defer t.tracksMutex.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user