diff --git a/ui/browsing/artistpage.go b/ui/browsing/artistpage.go index 34d8c3b6..9ddc0c2a 100644 --- a/ui/browsing/artistpage.go +++ b/ui/browsing/artistpage.go @@ -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, } }) } diff --git a/ui/browsing/favoritespage.go b/ui/browsing/favoritespage.go index 82a2f353..d0b1f872 100644 --- a/ui/browsing/favoritespage.go +++ b/ui/browsing/favoritespage.go @@ -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 @@ -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 @@ -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 diff --git a/ui/widgets/gridview.go b/ui/widgets/gridview.go index a438ee60..f8957491 100644 --- a/ui/widgets/gridview.go +++ b/ui/widgets/gridview.go @@ -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) @@ -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, } }) } diff --git a/ui/widgets/gridviewitem.go b/ui/widgets/gridviewitem.go index 735827eb..b98413f0 100644 --- a/ui/widgets/gridviewitem.go +++ b/ui/widgets/gridviewitem.go @@ -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 @@ -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), ), ) } @@ -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() } @@ -204,6 +213,8 @@ type GridViewItemModel struct { Secondary []string SecondaryIDs []string Suffix string + CanFavorite bool + IsFavorite bool } type GridViewItem struct { @@ -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)