From 45825c3902fdde686d03de45f824ff47d0260e7b Mon Sep 17 00:00:00 2001 From: Colin van Loo Date: Sat, 25 Jan 2025 17:23:29 +0100 Subject: [PATCH 1/3] feat: fetch full size artist cover on tapped --- ui/browsing/artistpage.go | 48 +++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/ui/browsing/artistpage.go b/ui/browsing/artistpage.go index e2403a1..aac8969 100644 --- a/ui/browsing/artistpage.go +++ b/ui/browsing/artistpage.go @@ -247,7 +247,7 @@ func (a *ArtistPage) load() { return } a.artistInfo = artist - a.header.Update(artist) + a.header.Update(artist, a.im) if a.activeView == 0 { a.showAlbumGrid(false /*reSort*/) } else { @@ -364,6 +364,7 @@ type ArtistPageHeader struct { artistID string artistPage *ArtistPage artistImage *widgets.ImagePlaceholder + artistImageID string titleDisp *widget.RichText biographyDisp *widgets.MaxRowsLabel similarArtists *fyne.Container @@ -372,6 +373,7 @@ type ArtistPageHeader struct { playRadioBtn *widget.Button menuBtn *widget.Button container *fyne.Container + fullSizeCoverFetching bool //shareMenuItem *fyne.MenuItem } @@ -388,11 +390,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader { SizeName: theme.SizeNameHeadingText, } a.artistImage = widgets.NewImagePlaceholder(myTheme.ArtistIcon, 225) - a.artistImage.OnTapped = func(*fyne.PointEvent) { - if im := a.artistImage.Image(); im != nil { - a.artistPage.contr.ShowPopUpImage(im) - } - } + a.artistImage.OnTapped = func(*fyne.PointEvent) { go a.showPopUpCover() } a.favoriteBtn = widgets.NewFavoriteButton(func() { go a.toggleFavorited() }) a.playBtn = widget.NewButtonWithIcon(lang.L("Play Discography"), theme.MediaPlayIcon(), func() { go a.artistPage.pm.PlayArtistDiscography(a.artistID, false /*shuffle*/) @@ -443,6 +441,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader { func (a *ArtistPageHeader) Clear() { a.artistID = "" + a.artistImageID = "" a.favoriteBtn.IsFavorited = false a.titleDisp.Segments[0].(*widget.TextSegment).Text = "" a.biographyDisp.Text = lang.L(artistBioNotAvailableKey) @@ -450,25 +449,28 @@ func (a *ArtistPageHeader) Clear() { obj.Hide() } a.artistImage.SetImage(nil, false) + a.fullSizeCoverFetching = false } -func (a *ArtistPageHeader) Update(artist *mediaprovider.ArtistWithAlbums) { +func (a *ArtistPageHeader) Update(artist *mediaprovider.ArtistWithAlbums, im *backend.ImageManager) { if artist == nil { return } a.favoriteBtn.IsFavorited = artist.Favorite a.favoriteBtn.Refresh() a.artistID = artist.ID + a.artistImageID = artist.CoverArtID a.titleDisp.Segments[0].(*widget.TextSegment).Text = artist.Name a.titleDisp.Refresh() - if artist.CoverArtID == "" { - return - } - if im, err := a.artistPage.im.GetCoverThumbnail(artist.CoverArtID); err != nil { - log.Printf("failed to load artist image: %v", err) - } else { - a.artistImage.SetImage(im, true /*tappable*/) - } + + go func() { + if cover, err := im.GetCoverThumbnail(artist.CoverArtID); err == nil { + a.artistImage.SetImage(cover, true) + a.artistImage.Refresh() + } else { + log.Printf("error fetching cover: %v", err) + } + }() } func (a *ArtistPageHeader) UpdateInfo(info *mediaprovider.ArtistInfo) { @@ -517,6 +519,22 @@ func (a *ArtistPageHeader) UpdateInfo(info *mediaprovider.ArtistInfo) { } } +func (a *ArtistPageHeader) showPopUpCover() { + if a.fullSizeCoverFetching { + return + } + a.fullSizeCoverFetching = true + defer func() { a.fullSizeCoverFetching = false }() + cover, err := a.artistPage.im.GetFullSizeCoverArt(a.artistImageID) + if err != nil { + log.Printf("error getting full size album cover: %s", err.Error()) + return + } + if a.artistPage != nil { + a.artistPage.contr.ShowPopUpImage(cover) + } +} + func (a *ArtistPageHeader) toggleFavorited() { params := mediaprovider.RatingFavoriteParameters{ArtistIDs: []string{a.artistID}} a.artistPage.mp.SetFavorite(params, a.favoriteBtn.IsFavorited) From a591643c0922b9191f223a2a2690c560f7bc9dec Mon Sep 17 00:00:00 2001 From: Colin van Loo Date: Sun, 26 Jan 2025 18:32:41 +0100 Subject: [PATCH 2/3] fix: use CoverArtID if available and LastFM image url otherwise --- ui/browsing/artistpage.go | 60 ++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/ui/browsing/artistpage.go b/ui/browsing/artistpage.go index aac8969..29328aa 100644 --- a/ui/browsing/artistpage.go +++ b/ui/browsing/artistpage.go @@ -361,18 +361,18 @@ const artistBioNotAvailableKey = "Artist biography not available." type ArtistPageHeader struct { widget.BaseWidget - artistID string - artistPage *ArtistPage - artistImage *widgets.ImagePlaceholder - artistImageID string - titleDisp *widget.RichText - biographyDisp *widgets.MaxRowsLabel - similarArtists *fyne.Container - favoriteBtn *widgets.FavoriteButton - playBtn *widget.Button - playRadioBtn *widget.Button - menuBtn *widget.Button - container *fyne.Container + artistID string + artistPage *ArtistPage + artistImage *widgets.ImagePlaceholder + artistImageID string + titleDisp *widget.RichText + biographyDisp *widgets.MaxRowsLabel + similarArtists *fyne.Container + favoriteBtn *widgets.FavoriteButton + playBtn *widget.Button + playRadioBtn *widget.Button + menuBtn *widget.Button + container *fyne.Container fullSizeCoverFetching bool //shareMenuItem *fyne.MenuItem } @@ -459,10 +459,12 @@ func (a *ArtistPageHeader) Update(artist *mediaprovider.ArtistWithAlbums, im *ba a.favoriteBtn.IsFavorited = artist.Favorite a.favoriteBtn.Refresh() a.artistID = artist.ID - a.artistImageID = artist.CoverArtID a.titleDisp.Segments[0].(*widget.TextSegment).Text = artist.Name a.titleDisp.Refresh() - + if artist.CoverArtID == "" { + return + } + a.artistImageID = artist.CoverArtID go func() { if cover, err := im.GetCoverThumbnail(artist.CoverArtID); err == nil { a.artistImage.SetImage(cover, true) @@ -520,18 +522,24 @@ func (a *ArtistPageHeader) UpdateInfo(info *mediaprovider.ArtistInfo) { } func (a *ArtistPageHeader) showPopUpCover() { - if a.fullSizeCoverFetching { - return - } - a.fullSizeCoverFetching = true - defer func() { a.fullSizeCoverFetching = false }() - cover, err := a.artistPage.im.GetFullSizeCoverArt(a.artistImageID) - if err != nil { - log.Printf("error getting full size album cover: %s", err.Error()) - return - } - if a.artistPage != nil { - a.artistPage.contr.ShowPopUpImage(cover) + if a.artistImageID == "" { + if im := a.artistImage.Image(); im != nil { + a.artistPage.contr.ShowPopUpImage(im) + } + } else { + if a.fullSizeCoverFetching { + return + } + a.fullSizeCoverFetching = true + defer func() { a.fullSizeCoverFetching = false }() + cover, err := a.artistPage.im.GetFullSizeCoverArt(a.artistImageID) + if err != nil { + log.Printf("error getting full size album cover: %s", err.Error()) + return + } + if a.artistPage != nil { + a.artistPage.contr.ShowPopUpImage(cover) + } } } From fd2602850ac79e061805cdba41340dbb5156989d Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Mon, 27 Jan 2025 09:19:22 -0300 Subject: [PATCH 3/3] remove extra Refresh --- ui/browsing/artistpage.go | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/browsing/artistpage.go b/ui/browsing/artistpage.go index 29328aa..8b8c793 100644 --- a/ui/browsing/artistpage.go +++ b/ui/browsing/artistpage.go @@ -468,7 +468,6 @@ func (a *ArtistPageHeader) Update(artist *mediaprovider.ArtistWithAlbums, im *ba go func() { if cover, err := im.GetCoverThumbnail(artist.CoverArtID); err == nil { a.artistImage.SetImage(cover, true) - a.artistImage.Refresh() } else { log.Printf("error fetching cover: %v", err) }