set placeholder image when album cover is not available

This commit is contained in:
Drew Weymouth
2023-03-16 21:32:48 -07:00
parent 78258a5457
commit 69314696a0
6 changed files with 21 additions and 6 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

+5
View File
File diff suppressed because one or more lines are too long
+2 -1
View File
@@ -1,6 +1,7 @@
#!/bin/sh
fyne bundle -package res -prefix Res appicon-250.png > bundled.go
fyne bundle -append -prefix Res albumplaceholder.png >> bundled.go
fyne bundle -append -prefix Res icons/freepik/disc.png >> bundled.go
fyne bundle -append -prefix Res icons/freepik/disc-invert.png >> bundled.go
fyne bundle -append -prefix Res icons/freepik/headphones.png >> bundled.go
@@ -29,4 +30,4 @@ fyne bundle -append -prefix Res icons/publicdomain/shuffle-invert.svg >> bundled
fyne bundle -append -prefix Res ../LICENSE >> bundled.go
fyne bundle -append -prefix Res licenses/BSDLICENSE >> bundled.go
fyne bundle -append -prefix Res licenses/MITLICENSE >> bundled.go
fyne bundle -append -prefix Res licenses/MITLICENSE >> bundled.go
+3 -1
View File
@@ -87,12 +87,14 @@ func (a *AboutDialog) buildCreditsContainer() fyne.CanvasObject {
freepikURL, _ := url.Parse("https://www.flaticon.com/authors/freepik")
appIconCredit := widget.NewLabel("The Supersonic app icon is a derivative of a work created by Piotr Siedlecki and placed in the public domain.")
appIconCredit.Wrapping = fyne.TextWrapWord
albumPlaceholderCredit := widget.NewLabel("The album cover placeholder image was created by @LaurenBacall originally for the MP3Tag project.")
albumPlaceholderCredit.Wrapping = fyne.TextWrapWord
return container.New(&layouts.VboxCustomPadding{ExtraPad: -10},
widget.NewLabel("Major frameworks and modules used in this application include:"),
container.NewHBox(widget.NewHyperlink("Fyne toolkit", fyneURL), widget.NewLabel("BSD 3-Clause License")),
container.NewHBox(widget.NewHyperlink("go-subsonic", goSubsonicURL), widget.NewLabel("GPL v3 License")),
container.NewHBox(widget.NewHyperlink("go-toml", goTomlURL), widget.NewLabel("MIT License")),
appIconCredit,
appIconCredit, albumPlaceholderCredit,
container.NewHBox(widget.NewLabel("Additional icons by:"), widget.NewHyperlink("Freepik on flaticon.com", freepikURL)),
)
}
+7
View File
@@ -89,10 +89,17 @@ func (a *albumCover) center() fyne.Position {
}
func (a *albumCover) SetImage(im image.Image) {
a.Im.Resource = nil
a.Im.Image = im
a.Refresh()
}
func (a *albumCover) SetImageResource(res *fyne.StaticResource) {
a.Im.Image = nil
a.Im.Resource = res
a.Refresh()
}
func isInside(origin fyne.Position, radius float32, point fyne.Position) bool {
x, y := (point.X - origin.X), (point.Y - origin.Y)
return x*x+y*y <= radius*radius
+4 -4
View File
@@ -5,6 +5,7 @@ import (
"image"
"log"
"supersonic/backend"
"supersonic/res"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
@@ -148,7 +149,6 @@ func (ag *AlbumGrid) doUpdateAlbumCard(albumIdx int, ac *AlbumCard) {
}
ac.Update(album)
ac.PrevAlbumID = album.ID
// TODO: set image to a placeholder before spinning off async fetch
// cancel any previous image fetch
if ac.ImgLoadCancel != nil {
ac.ImgLoadCancel()
@@ -156,9 +156,11 @@ func (ag *AlbumGrid) doUpdateAlbumCard(albumIdx int, ac *AlbumCard) {
}
if img, ok := ag.imageFetcher.GetAlbumThumbnailFromCache(album.ID); ok {
ac.Cover.SetImage(img)
ac.Cover.Refresh()
} else {
ac.Cover.SetImageResource(res.ResAlbumplaceholderPng)
// asynchronously fetch cover image
ctx, cancel := context.WithCancel(context.Background())
ac.ImgLoadCancel = cancel
go func(ctx context.Context) {
i, err := ag.imageFetcher.GetAlbumThumbnail(album.ID)
select {
@@ -167,13 +169,11 @@ func (ag *AlbumGrid) doUpdateAlbumCard(albumIdx int, ac *AlbumCard) {
default:
if err == nil {
ac.Cover.SetImage(i)
ac.Cover.Refresh()
} else {
log.Printf("error fetching image: %s", err.Error())
}
}
}(ctx)
ac.ImgLoadCancel = cancel
}
// if user has scrolled near the bottom, fetch more