feat: fetch full size artist cover on tapped

This commit is contained in:
Colin van Loo
2025-01-25 17:23:29 +01:00
parent 29cc82d116
commit 45825c3902
+33 -15
View File
@@ -247,7 +247,7 @@ func (a *ArtistPage) load() {
return return
} }
a.artistInfo = artist a.artistInfo = artist
a.header.Update(artist) a.header.Update(artist, a.im)
if a.activeView == 0 { if a.activeView == 0 {
a.showAlbumGrid(false /*reSort*/) a.showAlbumGrid(false /*reSort*/)
} else { } else {
@@ -364,6 +364,7 @@ type ArtistPageHeader struct {
artistID string artistID string
artistPage *ArtistPage artistPage *ArtistPage
artistImage *widgets.ImagePlaceholder artistImage *widgets.ImagePlaceholder
artistImageID string
titleDisp *widget.RichText titleDisp *widget.RichText
biographyDisp *widgets.MaxRowsLabel biographyDisp *widgets.MaxRowsLabel
similarArtists *fyne.Container similarArtists *fyne.Container
@@ -372,6 +373,7 @@ type ArtistPageHeader struct {
playRadioBtn *widget.Button playRadioBtn *widget.Button
menuBtn *widget.Button menuBtn *widget.Button
container *fyne.Container container *fyne.Container
fullSizeCoverFetching bool
//shareMenuItem *fyne.MenuItem //shareMenuItem *fyne.MenuItem
} }
@@ -388,11 +390,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
SizeName: theme.SizeNameHeadingText, SizeName: theme.SizeNameHeadingText,
} }
a.artistImage = widgets.NewImagePlaceholder(myTheme.ArtistIcon, 225) a.artistImage = widgets.NewImagePlaceholder(myTheme.ArtistIcon, 225)
a.artistImage.OnTapped = func(*fyne.PointEvent) { a.artistImage.OnTapped = func(*fyne.PointEvent) { go a.showPopUpCover() }
if im := a.artistImage.Image(); im != nil {
a.artistPage.contr.ShowPopUpImage(im)
}
}
a.favoriteBtn = widgets.NewFavoriteButton(func() { go a.toggleFavorited() }) a.favoriteBtn = widgets.NewFavoriteButton(func() { go a.toggleFavorited() })
a.playBtn = widget.NewButtonWithIcon(lang.L("Play Discography"), theme.MediaPlayIcon(), func() { a.playBtn = widget.NewButtonWithIcon(lang.L("Play Discography"), theme.MediaPlayIcon(), func() {
go a.artistPage.pm.PlayArtistDiscography(a.artistID, false /*shuffle*/) go a.artistPage.pm.PlayArtistDiscography(a.artistID, false /*shuffle*/)
@@ -443,6 +441,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
func (a *ArtistPageHeader) Clear() { func (a *ArtistPageHeader) Clear() {
a.artistID = "" a.artistID = ""
a.artistImageID = ""
a.favoriteBtn.IsFavorited = false a.favoriteBtn.IsFavorited = false
a.titleDisp.Segments[0].(*widget.TextSegment).Text = "" a.titleDisp.Segments[0].(*widget.TextSegment).Text = ""
a.biographyDisp.Text = lang.L(artistBioNotAvailableKey) a.biographyDisp.Text = lang.L(artistBioNotAvailableKey)
@@ -450,25 +449,28 @@ func (a *ArtistPageHeader) Clear() {
obj.Hide() obj.Hide()
} }
a.artistImage.SetImage(nil, false) 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 { if artist == nil {
return return
} }
a.favoriteBtn.IsFavorited = artist.Favorite a.favoriteBtn.IsFavorited = artist.Favorite
a.favoriteBtn.Refresh() a.favoriteBtn.Refresh()
a.artistID = artist.ID a.artistID = artist.ID
a.artistImageID = artist.CoverArtID
a.titleDisp.Segments[0].(*widget.TextSegment).Text = artist.Name a.titleDisp.Segments[0].(*widget.TextSegment).Text = artist.Name
a.titleDisp.Refresh() a.titleDisp.Refresh()
if artist.CoverArtID == "" {
return go func() {
} if cover, err := im.GetCoverThumbnail(artist.CoverArtID); err == nil {
if im, err := a.artistPage.im.GetCoverThumbnail(artist.CoverArtID); err != nil { a.artistImage.SetImage(cover, true)
log.Printf("failed to load artist image: %v", err) a.artistImage.Refresh()
} else { } else {
a.artistImage.SetImage(im, true /*tappable*/) log.Printf("error fetching cover: %v", err)
} }
}()
} }
func (a *ArtistPageHeader) UpdateInfo(info *mediaprovider.ArtistInfo) { 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() { func (a *ArtistPageHeader) toggleFavorited() {
params := mediaprovider.RatingFavoriteParameters{ArtistIDs: []string{a.artistID}} params := mediaprovider.RatingFavoriteParameters{ArtistIDs: []string{a.artistID}}
a.artistPage.mp.SetFavorite(params, a.favoriteBtn.IsFavorited) a.artistPage.mp.SetFavorite(params, a.favoriteBtn.IsFavorited)