Skip to content

Commit

Permalink
set placeholder image when album cover is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Mar 17, 2023
1 parent 78258a5 commit 6931469
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Binary file added res/albumplaceholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions res/bundled.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion res/bundled_gen.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion ui/dialogs/aboutdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
)
}
Expand Down
7 changes: 7 additions & 0 deletions ui/widgets/albumcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions ui/widgets/albumgrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"image"
"log"
"supersonic/backend"
"supersonic/res"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
Expand Down Expand Up @@ -148,17 +149,18 @@ 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()
ac.ImgLoadCancel = nil
}
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 {
Expand All @@ -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
Expand Down

0 comments on commit 6931469

Please sign in to comment.