Merge pull request #540 from cvanloo/fix-fetch-full-size-artist-image

feat: fetch full size artist cover on tapped
This commit is contained in:
Drew Weymouth
2025-01-27 09:42:16 -03:00
committed by GitHub
+35 -10
View File
@@ -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,9 +449,10 @@ 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
}
@@ -464,11 +464,14 @@ func (a *ArtistPageHeader) Update(artist *mediaprovider.ArtistWithAlbums) {
if artist.CoverArtID == "" {
return
}
if im, err := a.artistPage.im.GetCoverThumbnail(artist.CoverArtID); err != nil {
log.Printf("failed to load artist image: %v", err)
a.artistImageID = artist.CoverArtID
go func() {
if cover, err := im.GetCoverThumbnail(artist.CoverArtID); err == nil {
a.artistImage.SetImage(cover, true)
} else {
a.artistImage.SetImage(im, true /*tappable*/)
log.Printf("error fetching cover: %v", err)
}
}()
}
func (a *ArtistPageHeader) UpdateInfo(info *mediaprovider.ArtistInfo) {
@@ -517,6 +520,28 @@ func (a *ArtistPageHeader) UpdateInfo(info *mediaprovider.ArtistInfo) {
}
}
func (a *ArtistPageHeader) showPopUpCover() {
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)
}
}
}
func (a *ArtistPageHeader) toggleFavorited() {
params := mediaprovider.RatingFavoriteParameters{ArtistIDs: []string{a.artistID}}
a.artistPage.mp.SetFavorite(params, a.favoriteBtn.IsFavorited)