hook up favorite status with GridView items

This commit is contained in:
Drew Weymouth
2024-12-28 16:37:59 -08:00
parent ee9fd597f9
commit f702ef5c31
4 changed files with 36 additions and 15 deletions
+6 -4
View File
@@ -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,
}
})
}
+8 -6
View File
@@ -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
+8 -4
View File
@@ -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,
}
})
}
+14 -1
View File
@@ -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)