Skip to content

Commit

Permalink
hook up favorite status with GridView items
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Dec 29, 2024
1 parent ee9fd59 commit f702ef5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
10 changes: 6 additions & 4 deletions ui/browsing/artistpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,12 @@ func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel {
sort.Slice(a.artistInfo.Albums, sortFunc)
return sharedutil.MapSlice(a.artistInfo.Albums, func(al *mediaprovider.Album) widgets.GridViewItemModel {
return widgets.GridViewItemModel{
Name: al.Name,
ID: al.ID,
CoverArtID: al.CoverArtID,
Secondary: []string{strconv.Itoa(al.YearOrZero())},
Name: al.Name,
ID: al.ID,
CoverArtID: al.CoverArtID,
Secondary: []string{strconv.Itoa(al.YearOrZero())},
CanFavorite: true,
IsFavorite: al.Favorite,
}
})
}
Expand Down
14 changes: 8 additions & 6 deletions ui/browsing/favoritespage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (a *FavoritesPage) createHeader(activeBtnIdx int) {
a.shuffleBtn.Hidden = activeBtnIdx != 2 /*favorite songs*/
a.searcher = widgets.NewSearchEntry()
a.searcher.PlaceHolder = lang.L("Search page")
a.searcher.OnSearched = a.OnSearched
a.searcher.OnSearched = a.onSearched
a.searcher.Entry.Text = a.searchText
a.filterBtn = widgets.NewAlbumFilterButton(a.filter, a.mp.GetGenres)
a.filterBtn.FavoriteDisabled = true
Expand Down Expand Up @@ -267,7 +267,7 @@ func (a *FavoritesPage) SearchWidget() fyne.Focusable {
return a.searcher
}

func (a *FavoritesPage) OnSearched(query string) {
func (a *FavoritesPage) onSearched(query string) {
if query == "" {
a.albumGrid.ResetFromState(a.gridState)
a.searchGridState = nil
Expand Down Expand Up @@ -386,10 +386,12 @@ func buildArtistGridViewModel(artists []*mediaprovider.Artist) []widgets.GridVie
albums = lang.L("album")
}
model = append(model, widgets.GridViewItemModel{
ID: ar.ID,
CoverArtID: ar.CoverArtID,
Name: ar.Name,
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albums)},
ID: ar.ID,
CoverArtID: ar.CoverArtID,
Name: ar.Name,
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albums)},
CanFavorite: true,
IsFavorite: ar.Favorite,
})
}
return model
Expand Down
12 changes: 8 additions & 4 deletions ui/widgets/gridview.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (g gridViewAlbumIterator) NextN(n int) []GridViewItemModel {
CoverArtID: al.CoverArtID,
Secondary: al.ArtistNames,
SecondaryIDs: al.ArtistIDs,
CanFavorite: true,
IsFavorite: al.Favorite,
}
if y := al.Date.Year; y != nil {
model.Suffix = strconv.Itoa(*al.Date.Year)
Expand All @@ -84,10 +86,12 @@ func (g gridViewArtistIterator) NextN(n int) []GridViewItemModel {
albumsLabel = lang.L("album")
}
return GridViewItemModel{
Name: ar.Name,
ID: ar.ID,
CoverArtID: ar.CoverArtID,
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albumsLabel)},
Name: ar.Name,
ID: ar.ID,
CoverArtID: ar.CoverArtID,
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albumsLabel)},
CanFavorite: true,
IsFavorite: ar.Favorite,
}
})
}
Expand Down
15 changes: 14 additions & 1 deletion ui/widgets/gridviewitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var _ fyne.Widget = (*coverImage)(nil)
type coverImage struct {
widget.BaseWidget

EnableFavorite bool
IsFavorite bool

Im *ImagePlaceholder
playbtn *canvas.Image
favoriteButton *canvas.Image
Expand Down Expand Up @@ -118,11 +121,11 @@ func (c *coverImage) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(
container.NewStack(
c.Im,
container.NewCenter(c.playbtn),
container.NewGridWithRows(2,
layout.NewSpacer(),
c.bottomPanel,
),
container.NewCenter(c.playbtn),
),
)
}
Expand Down Expand Up @@ -151,6 +154,12 @@ func (c *coverImage) TappedSecondary(e *fyne.PointEvent) {

func (a *coverImage) MouseIn(*desktop.MouseEvent) {
a.playbtn.Hidden = false
if a.IsFavorite {
a.favoriteButton.Resource = heartFilledResource
} else {
a.favoriteButton.Resource = heartUnfilledResource
}
a.favoriteButton.Hidden = !a.EnableFavorite
a.bottomPanel.Hidden = false
a.Refresh()
}
Expand Down Expand Up @@ -204,6 +213,8 @@ type GridViewItemModel struct {
Secondary []string
SecondaryIDs []string
Suffix string
CanFavorite bool
IsFavorite bool
}

type GridViewItem struct {
Expand Down Expand Up @@ -282,6 +293,8 @@ func (g *GridViewItem) NeedsUpdate(model GridViewItemModel) bool {
}

func (g *GridViewItem) Update(model GridViewItemModel) {
g.Cover.IsFavorite = model.IsFavorite
g.Cover.EnableFavorite = model.CanFavorite
g.itemID = model.ID
g.secondaryIDs = model.SecondaryIDs
g.primaryText.SetText(model.Name)
Expand Down

0 comments on commit f702ef5

Please sign in to comment.