Merge pull request #201 from natilou/download-from-grid

Ability to download from grid
This commit is contained in:
Drew Weymouth
2023-06-20 09:38:22 -07:00
committed by GitHub
4 changed files with 41 additions and 1 deletions
+10
View File
@@ -113,6 +113,16 @@ func (a *PlaylistsPage) createGridView(playlists []*mediaprovider.Playlist) {
a.contr.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(pl.Tracks)) a.contr.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(pl.Tracks))
}() }()
} }
a.gridView.OnDownload = func(id string) {
go func() {
pl, err := a.contr.App.ServerManager.Server.GetPlaylist(id)
if err != nil {
log.Printf("error loading playlist: %s", err.Error())
return
}
a.contr.ShowDownloadDialog(pl.Tracks)
}()
}
} }
func (a *PlaylistsPage) showListView() { func (a *PlaylistsPage) showListView() {
+16
View File
@@ -143,6 +143,16 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
m.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(album.Tracks)) m.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(album.Tracks))
}() }()
} }
grid.OnDownload = func(albumID string) {
go func() {
album, err := m.App.ServerManager.Server.GetAlbum(albumID)
if err != nil {
log.Printf("error loading album: %s", err.Error())
return
}
m.ShowDownloadDialog(album.Tracks)
}()
}
} }
func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) { func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) {
@@ -155,6 +165,12 @@ func (m *Controller) ConnectArtistGridActions(grid *widgets.GridView) {
go m.DoAddTracksToPlaylistWorkflow( go m.DoAddTracksToPlaylistWorkflow(
sharedutil.TracksToIDs(m.GetArtistTracks(artistID))) sharedutil.TracksToIDs(m.GetArtistTracks(artistID)))
} }
grid.OnDownload = func(artistID string) {
go func() {
tracks := m.GetArtistTracks(artistID)
m.ShowDownloadDialog(tracks)
}()
}
} }
func (m *Controller) GetArtistTracks(artistID string) []*mediaprovider.Track { func (m *Controller) GetArtistTracks(artistID string) []*mediaprovider.Track {
+6
View File
@@ -89,6 +89,7 @@ type GridViewState struct {
OnPlay func(id string, shuffle bool) OnPlay func(id string, shuffle bool)
OnAddToQueue func(id string) OnAddToQueue func(id string)
OnAddToPlaylist func(id string) OnAddToPlaylist func(id string)
OnDownload func(id string)
OnShowItemPage func(id string) OnShowItemPage func(id string)
OnShowSecondaryPage func(id string) OnShowSecondaryPage func(id string)
@@ -217,6 +218,11 @@ func (g *GridView) createGridWrap() {
g.OnAddToPlaylist(card.ItemID()) g.OnAddToPlaylist(card.ItemID())
} }
} }
card.OnDownload = func() {
if g.OnDownload != nil {
g.OnDownload(card.itemID)
}
}
return card return card
}, },
// update func // update func
+9 -1
View File
@@ -129,6 +129,7 @@ type GridViewItem struct {
OnPlay func(shuffle bool) OnPlay func(shuffle bool)
OnAddToQueue func() OnAddToQueue func()
OnAddToPlaylist func() OnAddToPlaylist func()
OnDownload func()
OnShowItemPage func() OnShowItemPage func()
OnShowSecondaryPage func() OnShowSecondaryPage func()
} }
@@ -173,7 +174,8 @@ func (g *GridViewItem) showContextMenu(pos fyne.Position) {
fyne.NewMenuItem("Play", func() { g.onPlay(false) }), fyne.NewMenuItem("Play", func() { g.onPlay(false) }),
fyne.NewMenuItem("Shuffle", func() { g.onPlay(true) }), fyne.NewMenuItem("Shuffle", func() { g.onPlay(true) }),
fyne.NewMenuItem("Add to queue", g.onAddToQueue), fyne.NewMenuItem("Add to queue", g.onAddToQueue),
fyne.NewMenuItem("Add to playlist...", g.onAddToPlaylist)), fyne.NewMenuItem("Add to playlist...", g.onAddToPlaylist),
fyne.NewMenuItem("Download...", g.onDownload)),
fyne.CurrentApp().Driver().CanvasForObject(g)) fyne.CurrentApp().Driver().CanvasForObject(g))
} }
g.menu.ShowAtPosition(pos) g.menu.ShowAtPosition(pos)
@@ -218,3 +220,9 @@ func (g *GridViewItem) onAddToPlaylist() {
g.OnAddToPlaylist() g.OnAddToPlaylist()
} }
} }
func (g *GridViewItem) onDownload() {
if g.OnDownload != nil {
g.OnDownload()
}
}