Ability to download from grid

- Adding the option to download the album or tracks in grid view from Artist and Album pages.
This commit is contained in:
natilou
2023-06-20 12:35:59 -03:00
parent 7f907267fa
commit 0dfbe685e1
3 changed files with 27 additions and 1 deletions
+12
View File
@@ -143,6 +143,14 @@ func (m *Controller) ConnectAlbumGridActions(grid *widgets.GridView) {
m.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(album.Tracks)) m.DoAddTracksToPlaylistWorkflow(sharedutil.TracksToIDs(album.Tracks))
}() }()
} }
grid.OnDownload = func(albumID string) {
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 +163,10 @@ 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) {
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()
}
}