Skip to content

Commit

Permalink
Refactor and temporarily disable sharing artists
Browse files Browse the repository at this point in the history
  • Loading branch information
adamantike committed Mar 4, 2024
1 parent d9bbe03 commit a6fefc9
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 84 deletions.
1 change: 1 addition & 0 deletions backend/mediaprovider/mediaprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ type SupportsRating interface {

type SupportsSharing interface {
CreateShareURL(id string) (*url.URL, error)
CanShareArtists() bool
}

type JukeboxProvider interface {
Expand Down
6 changes: 6 additions & 0 deletions backend/mediaprovider/subsonic/subsonicmediaprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ func (s *subsonicMediaProvider) CreateShareURL(id string) (*url.URL, error) {
return shareUrl, nil
}

func (s *subsonicMediaProvider) CanShareArtists() bool {
// TODO: Change to true when we decide to allow sharing artists, in case an OpenSubsonic extension
// is approved to share artists in addition to albums and tracks.
return false
}

func (s *subsonicMediaProvider) DownloadTrack(trackID string) (io.Reader, error) {
return s.client.Download(trackID)
}
Expand Down
23 changes: 10 additions & 13 deletions ui/browsing/albumpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func newAlbumPage(
a.tracklist.SetVisibleColumns(a.cfg.TracklistColumns)
a.tracklist.SetSorting(sort)
_, canRate := a.mp.(mediaprovider.SupportsRating)
_, canShare := a.mp.(mediaprovider.SupportsRating)
_, canShare := a.mp.(mediaprovider.SupportsSharing)
a.tracklist.Options.DisableRating = !canRate
a.tracklist.Options.HideSharing = !canShare
a.tracklist.Options.DisableSharing = !canShare
a.tracklist.OnVisibleColumnsChanged = func(cols []string) {
a.cfg.TracklistColumns = cols
}
Expand Down Expand Up @@ -185,6 +185,7 @@ type AlbumPageHeader struct {
artistLabelSpace *util.HSpace // TODO: remove when no longer needed
genreLabel *widgets.MultiHyperlink
miscLabel *widget.Label
shareMenuItem *fyne.MenuItem

toggleFavButton *widgets.FavoriteButton

Expand Down Expand Up @@ -248,19 +249,15 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
a.page.contr.ShowAlbumInfoDialog(a.albumID, a.titleLabel.String(), a.cover.Image())
})
info.Icon = theme.InfoIcon()
menuItems := []*fyne.MenuItem{queue, playlist, download, info}

_, canShare := page.mp.(mediaprovider.SupportsSharing)
if canShare {
share := fyne.NewMenuItem("Share...", func() {
a.page.contr.ShowShareDialog(a.albumID)
})
share.Icon = myTheme.ShareIcon
menuItems = append(menuItems, share)
}
menu := fyne.NewMenu("", menuItems...)
a.shareMenuItem = fyne.NewMenuItem("Share...", func() {
a.page.contr.ShowShareDialog(a.albumID)
})
a.shareMenuItem.Icon = myTheme.ShareIcon
menu := fyne.NewMenu("", queue, playlist, download, info, a.shareMenuItem)
pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
}
_, canShare := page.mp.(mediaprovider.SupportsSharing)
a.shareMenuItem.Disabled = !canShare
pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(menuBtn)
pop.ShowAtPosition(fyne.NewPos(pos.X, pos.Y+menuBtn.Size().Height))
}
Expand Down
40 changes: 22 additions & 18 deletions ui/browsing/artistpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func (a *ArtistPage) showTopTracks() {
_, canRate := a.mp.(mediaprovider.SupportsRating)
_, canShare := a.mp.(mediaprovider.SupportsSharing)
tl.Options.DisableRating = !canRate
tl.Options.HideSharing = !canShare
tl.Options.DisableSharing = !canShare
tl.SetVisibleColumns(a.cfg.TracklistColumns)
tl.SetSorting(a.trackSort)
tl.OnVisibleColumnsChanged = func(cols []string) {
Expand Down Expand Up @@ -296,6 +296,7 @@ type ArtistPageHeader struct {
playRadioBtn *widget.Button
menuBtn *widget.Button
container *fyne.Container
shareMenuItem *fyne.MenuItem
}

func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
Expand All @@ -322,23 +323,26 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
})
a.playRadioBtn = widget.NewButtonWithIcon("Play Artist Radio", myTheme.ShuffleIcon, a.artistPage.playArtistRadio)

_, canShare := a.artistPage.mp.(mediaprovider.SupportsSharing)
if canShare {
var pop *widget.PopUpMenu
a.menuBtn = widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
a.menuBtn.OnTapped = func() {
if pop == nil {
share := fyne.NewMenuItem("Share...", func() {
a.artistPage.contr.ShowShareDialog(a.artistID)
})
share.Icon = myTheme.ShareIcon
menu := fyne.NewMenu("", share)
pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
}
pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(a.menuBtn)
pop.ShowAtPosition(fyne.NewPos(pos.X, pos.Y+a.menuBtn.Size().Height))
}
}
// TODO: Uncomment when at least one media provider supports sharing artists.
// a.shareMenuItem = fyne.NewMenuItem("Share...", func() {
// a.artistPage.contr.ShowShareDialog(a.artistID)
// })
// a.shareMenuItem.Icon = myTheme.ShareIcon
// var pop *widget.PopUpMenu
// a.menuBtn = widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
// a.menuBtn.OnTapped = func() {
// if pop == nil {
// menu := fyne.NewMenu("", a.shareMenuItem)
// pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
// }
// pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(a.menuBtn)
// pop.ShowAtPosition(fyne.NewPos(pos.X, pos.Y+a.menuBtn.Size().Height))
// }
// canShareArtists := false
// if r, canShare := a.artistPage.mp.(mediaprovider.SupportsSharing); canShare {
// canShareArtists = r.CanShareArtists()
// }
// a.shareMenuItem.Disabled = !canShareArtists

a.biographyDisp.Wrapping = fyne.TextWrapWord
a.biographyDisp.Truncation = fyne.TextTruncateEllipsis
Expand Down
5 changes: 5 additions & 0 deletions ui/browsing/artistspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ func newArtistsPage(
} else {
a.grid = widgets.NewFixedGridView(nil, a.im, myTheme.ArtistIcon)
}
canShareArtists := false
if r, canShare := mp.(mediaprovider.SupportsSharing); canShare {
canShareArtists = r.CanShareArtists()
}
a.grid.DisableSharing = !canShareArtists
a.contr.ConnectArtistGridActions(a.grid)

searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
Expand Down
7 changes: 6 additions & 1 deletion ui/browsing/favoritespage.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ func (a *FavoritesPage) onShowFavoriteArtists() {
} else {
a.artistGrid = widgets.NewFixedGridView(model, a.im, myTheme.ArtistIcon)
}
canShareArtists := false
if r, canShare := a.mp.(mediaprovider.SupportsSharing); canShare {
canShareArtists = r.CanShareArtists()
}
a.artistGrid.DisableSharing = !canShareArtists
a.contr.ConnectArtistGridActions(a.artistGrid)
a.container.Objects[0] = a.artistGrid
a.Refresh()
Expand Down Expand Up @@ -397,7 +402,7 @@ func (a *FavoritesPage) onShowFavoriteSongs() {
_, canRate := a.mp.(mediaprovider.SupportsRating)
_, canShare := a.mp.(mediaprovider.SupportsSharing)
tracklist.Options.DisableRating = !canRate
tracklist.Options.HideSharing = !canShare
tracklist.Options.DisableSharing = !canShare
tracklist.SetVisibleColumns(a.cfg.TracklistColumns)
tracklist.SetSorting(a.trackSort)
tracklist.OnVisibleColumnsChanged = func(cols []string) {
Expand Down
2 changes: 2 additions & 0 deletions ui/browsing/gridviewpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func NewGridViewPage(
gp.ExtendBaseWidget(gp)
gp.createTitleAndSort()

_, canShare := mp.(mediaprovider.SupportsSharing)
iter := adapter.Iter(gp.getSortOrder(), gp.getFilter())
if g := pool.Obtain(util.WidgetTypeGridView); g != nil {
gp.grid = g.(*widgets.GridView)
Expand All @@ -120,6 +121,7 @@ func NewGridViewPage(
} else {
gp.grid = widgets.NewGridView(iter, im, adapter.PlaceholderResource())
}
gp.grid.DisableSharing = !canShare
adapter.ConnectGridActions(gp.grid)
gp.createSearchAndFilter()
gp.createContainer()
Expand Down
23 changes: 16 additions & 7 deletions ui/browsing/nowplayingpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ type NowPlayingPage struct {
}

type nowPlayingPageState struct {
contr *controller.Controller
pool *util.WidgetPool
pm *backend.PlaybackManager
im *backend.ImageManager
canRate bool
contr *controller.Controller
pool *util.WidgetPool
pm *backend.PlaybackManager
im *backend.ImageManager
canRate bool
canShare bool
}

func NewNowPlayingPage(
Expand All @@ -56,9 +57,10 @@ func NewNowPlayingPage(
im *backend.ImageManager,
pm *backend.PlaybackManager,
canRate bool,
canShare bool,
) *NowPlayingPage {
a := &NowPlayingPage{nowPlayingPageState: nowPlayingPageState{
contr: contr, pool: pool, im: im, pm: pm, canRate: canRate,
contr: contr, pool: pool, im: im, pm: pm, canRate: canRate, canShare: canShare,
}}
a.ExtendBaseWidget(a)

Expand All @@ -82,8 +84,15 @@ func NewNowPlayingPage(
}

a.queueList = widgets.NewPlayQueueList(a.im)
a.queueList.DisableRating = !canRate
a.queueList.DisableSharing = !canShare
a.queueList.OnReorderTracks = a.doSetNewTrackOrder
a.queueList.OnDownload = contr.ShowDownloadDialog
a.queueList.OnShare = func(tracks []*mediaprovider.Track) {
if len(tracks) > 0 {
a.contr.ShowShareDialog(tracks[0].ID)
}
}
a.queueList.OnAddToPlaylist = contr.DoAddTracksToPlaylistWorkflow
a.queueList.OnPlayTrackAt = func(tracknum int) {
_ = a.pm.PlayTrackAt(tracknum)
Expand Down Expand Up @@ -199,7 +208,7 @@ func (s *nowPlayingPageState) Restore() Page {
page.Reload()
return page
}
return NewNowPlayingPage(s.contr, s.pool, s.im, s.pm, s.canRate)
return NewNowPlayingPage(s.contr, s.pool, s.im, s.pm, s.canRate, s.canShare)
}

var _ CanShowPlayTime = (*NowPlayingPage)(nil)
Expand Down
4 changes: 2 additions & 2 deletions ui/browsing/playlistpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func newPlaylistPage(
remove := fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist)
remove.Icon = theme.ContentClearIcon()
a.tracklist.Options = widgets.TracklistOptions{
DisableRating: !canRate,
HideSharing: !canShare,
DisableRating: !canRate,
DisableSharing: !canShare,
AuxiliaryMenuItems: []*fyne.MenuItem{
util.NewReorderTracksSubmenu(a.doSetNewTrackOrder),
remove,
Expand Down
5 changes: 3 additions & 2 deletions ui/browsing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewRouter(app *backend.App, controller *controller.Controller, nav Navigati

func (r Router) CreatePage(rte controller.Route) Page {
_, canRate := r.App.ServerManager.Server.(mediaprovider.SupportsRating)
_, canShare := r.App.ServerManager.Server.(mediaprovider.SupportsSharing)
switch rte.Page {
case controller.Album:
return NewAlbumPage(rte.Arg, &r.App.Config.AlbumPage, r.widgetPool, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager, r.Controller)
Expand All @@ -43,13 +44,13 @@ func (r Router) CreatePage(rte controller.Route) Page {
case controller.Favorites:
return NewFavoritesPage(&r.App.Config.FavoritesPage, r.widgetPool, r.Controller, r.App.ServerManager.Server, r.App.PlaybackManager, r.App.ImageManager)
case controller.Fullscreen:
return NewNowPlayingPage(r.Controller, r.widgetPool, r.App.ImageManager, r.App.PlaybackManager, canRate)
return NewNowPlayingPage(r.Controller, r.widgetPool, r.App.ImageManager, r.App.PlaybackManager, canRate, canShare)
case controller.Genre:
return NewGenrePage(rte.Arg, r.widgetPool, r.Controller, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager)
case controller.Genres:
return NewGenresPage(r.Controller, r.App.ServerManager.Server)
case controller.NowPlaying:
return NewNowPlayingPage(r.Controller, r.widgetPool, r.App.ImageManager, r.App.PlaybackManager, canRate)
return NewNowPlayingPage(r.Controller, r.widgetPool, r.App.ImageManager, r.App.PlaybackManager, canRate, canShare)
case controller.Playlist:
return NewPlaylistPage(rte.Arg, &r.App.Config.PlaylistPage, r.widgetPool, r.Controller, r.App.ServerManager, r.App.PlaybackManager, r.App.ImageManager)
case controller.Playlists:
Expand Down
4 changes: 2 additions & 2 deletions ui/browsing/trackspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewTracksPage(contr *controller.Controller, conf *backend.TracksPageConfig,
t.tracklist.Options = widgets.TracklistOptions{
DisableSorting: true,
DisableRating: !t.canRate,
HideSharing: !t.canShare,
DisableSharing: !t.canShare,
AutoNumber: true,
}
t.tracklist.SetVisibleColumns(conf.TracklistColumns)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (t *TracksPage) doSearch(query string) {
AutoNumber: true,
DisableSorting: true,
DisableRating: !t.canRate,
HideSharing: !t.canShare,
DisableSharing: !t.canShare,
}
t.searchTracklist.SetVisibleColumns(t.conf.TracklistColumns)
t.searchTracklist.SetNowPlaying(t.nowPlayingID)
Expand Down
16 changes: 4 additions & 12 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,8 @@ func (m *Controller) connectTracklistActionsWithReplayGainMode(tracklist *widget
m.ClosePopUpOnEscape(pop)
}
tracklist.OnDownload = m.ShowDownloadDialog

_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
if canShare {
tracklist.OnShare = func(trackID string) {
go m.ShowShareDialog(trackID)
}
tracklist.OnShare = func(trackID string) {
go m.ShowShareDialog(trackID)
}
}

Expand Down Expand Up @@ -183,12 +179,8 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
m.ShowDownloadDialog(album.Tracks, album.Name)
}()
}

_, canShare := m.App.ServerManager.Server.(mediaprovider.SupportsSharing)
if canShare {
grid.OnShare = func(albumID string) {
go m.ShowShareDialog(albumID)
}
grid.OnShare = func(albumID string) {
go m.ShowShareDialog(albumID)
}
}

Expand Down
20 changes: 9 additions & 11 deletions ui/widgets/gridview.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type GridView struct {
itemForIndex map[int]*GridViewItem
itemWidth float32
numColsCached int
shareMenuItem *fyne.MenuItem
}

type GridViewState struct {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
Loading

0 comments on commit a6fefc9

Please sign in to comment.