Refactor and temporarily disable sharing artists
This commit is contained in:
+9
-11
@@ -79,6 +79,7 @@ type GridView struct {
|
||||
itemForIndex map[int]*GridViewItem
|
||||
itemWidth float32
|
||||
numColsCached int
|
||||
shareMenuItem *fyne.MenuItem
|
||||
}
|
||||
|
||||
type GridViewState struct {
|
||||
@@ -89,6 +90,8 @@ type GridViewState struct {
|
||||
highestShown int
|
||||
done bool
|
||||
|
||||
DisableSharing bool
|
||||
|
||||
OnPlay func(id string, shuffle bool)
|
||||
OnAddToQueue func(id string)
|
||||
OnAddToPlaylist func(id string)
|
||||
@@ -408,19 +411,14 @@ func (g *GridView) showContextMenu(card *GridViewItem, pos fyne.Position) {
|
||||
}
|
||||
})
|
||||
download.Icon = theme.DownloadIcon()
|
||||
menuItems := []*fyne.MenuItem{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...),
|
||||
g.shareMenuItem = fyne.NewMenuItem("Share...", func() {
|
||||
g.OnShare(g.menuGridViewItemId)
|
||||
})
|
||||
g.shareMenuItem.Icon = myTheme.ShareIcon
|
||||
g.menu = widget.NewPopUpMenu(fyne.NewMenu("", play, shuffle, queue, playlist, download, g.shareMenuItem),
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g))
|
||||
}
|
||||
g.shareMenuItem.Disabled = g.DisableSharing
|
||||
g.menu.ShowAtPosition(pos)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ const thumbnailSize = 52
|
||||
type PlayQueueList struct {
|
||||
widget.BaseWidget
|
||||
|
||||
DisableRating bool
|
||||
DisableRating bool
|
||||
DisableSharing bool
|
||||
|
||||
// user action callbacks
|
||||
OnAddToPlaylist func(trackIDs []string)
|
||||
@@ -34,6 +35,7 @@ type PlayQueueList struct {
|
||||
OnSetRating func(trackIDs []string, rating int)
|
||||
OnRemoveFromQueue func(trackIDs []string)
|
||||
OnDownload func(tracks []*mediaprovider.Track, downloadName string)
|
||||
OnShare func(tracks []*mediaprovider.Track)
|
||||
OnShowArtistPage func(artistID string)
|
||||
OnPlayTrackAt func(idx int)
|
||||
OnReorderTracks func(trackIDs []string, op sharedutil.TrackReorderOp)
|
||||
@@ -41,6 +43,7 @@ type PlayQueueList struct {
|
||||
list *FocusList
|
||||
menu *widget.PopUpMenu
|
||||
ratingSubmenu *fyne.MenuItem
|
||||
shareMenuItem *fyne.MenuItem
|
||||
|
||||
nowPlayingID string
|
||||
colLayout *layouts.ColumnsLayout
|
||||
@@ -200,6 +203,12 @@ func (p *PlayQueueList) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||
}
|
||||
})
|
||||
download.Icon = theme.DownloadIcon()
|
||||
p.shareMenuItem = fyne.NewMenuItem("Share...", func() {
|
||||
if p.OnShare != nil {
|
||||
p.OnShare(p.selectedTracks())
|
||||
}
|
||||
})
|
||||
p.shareMenuItem.Icon = myTheme.ShareIcon
|
||||
favorite := fyne.NewMenuItem("Set favorite", func() {
|
||||
if p.OnSetFavorite != nil {
|
||||
p.OnSetFavorite(p.selectedTrackIDs(), true)
|
||||
@@ -233,6 +242,7 @@ func (p *PlayQueueList) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||
fyne.NewMenu("",
|
||||
playlist,
|
||||
download,
|
||||
p.shareMenuItem,
|
||||
fyne.NewMenuItemSeparator(),
|
||||
favorite,
|
||||
unfavorite,
|
||||
@@ -245,6 +255,7 @@ func (p *PlayQueueList) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||
)
|
||||
}
|
||||
p.ratingSubmenu.Disabled = p.DisableRating
|
||||
p.shareMenuItem.Disabled = p.DisableSharing || len(p.selectedTracks()) != 1
|
||||
p.menu.ShowAtPosition(e.AbsolutePosition)
|
||||
}
|
||||
|
||||
|
||||
+10
-15
@@ -73,8 +73,8 @@ type TracklistOptions struct {
|
||||
// Disables the five star rating widget.
|
||||
DisableRating bool
|
||||
|
||||
// Hides the sharing option.
|
||||
HideSharing bool
|
||||
// Disables the sharing option.
|
||||
DisableSharing bool
|
||||
}
|
||||
|
||||
type Tracklist struct {
|
||||
@@ -560,13 +560,11 @@ 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.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) {
|
||||
@@ -579,9 +577,7 @@ 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
|
||||
}
|
||||
t.shareMenuItem.Disabled = t.Options.DisableSharing || len(t.selectedTracks()) != 1
|
||||
widget.ShowPopUpMenuAtPosition(t.ctxMenu, fyne.CurrentApp().Driver().CanvasForObject(t), e.AbsolutePosition)
|
||||
}
|
||||
|
||||
@@ -646,9 +642,8 @@ 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])
|
||||
if len(tracks) > 0 {
|
||||
t.OnShare(tracks[0].ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user