hook up favorite status with GridView items
This commit is contained in:
@@ -219,10 +219,12 @@ func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel {
|
|||||||
sort.Slice(a.artistInfo.Albums, sortFunc)
|
sort.Slice(a.artistInfo.Albums, sortFunc)
|
||||||
return sharedutil.MapSlice(a.artistInfo.Albums, func(al *mediaprovider.Album) widgets.GridViewItemModel {
|
return sharedutil.MapSlice(a.artistInfo.Albums, func(al *mediaprovider.Album) widgets.GridViewItemModel {
|
||||||
return widgets.GridViewItemModel{
|
return widgets.GridViewItemModel{
|
||||||
Name: al.Name,
|
Name: al.Name,
|
||||||
ID: al.ID,
|
ID: al.ID,
|
||||||
CoverArtID: al.CoverArtID,
|
CoverArtID: al.CoverArtID,
|
||||||
Secondary: []string{strconv.Itoa(al.YearOrZero())},
|
Secondary: []string{strconv.Itoa(al.YearOrZero())},
|
||||||
|
CanFavorite: true,
|
||||||
|
IsFavorite: al.Favorite,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ func (a *FavoritesPage) createHeader(activeBtnIdx int) {
|
|||||||
a.shuffleBtn.Hidden = activeBtnIdx != 2 /*favorite songs*/
|
a.shuffleBtn.Hidden = activeBtnIdx != 2 /*favorite songs*/
|
||||||
a.searcher = widgets.NewSearchEntry()
|
a.searcher = widgets.NewSearchEntry()
|
||||||
a.searcher.PlaceHolder = lang.L("Search page")
|
a.searcher.PlaceHolder = lang.L("Search page")
|
||||||
a.searcher.OnSearched = a.OnSearched
|
a.searcher.OnSearched = a.onSearched
|
||||||
a.searcher.Entry.Text = a.searchText
|
a.searcher.Entry.Text = a.searchText
|
||||||
a.filterBtn = widgets.NewAlbumFilterButton(a.filter, a.mp.GetGenres)
|
a.filterBtn = widgets.NewAlbumFilterButton(a.filter, a.mp.GetGenres)
|
||||||
a.filterBtn.FavoriteDisabled = true
|
a.filterBtn.FavoriteDisabled = true
|
||||||
@@ -267,7 +267,7 @@ func (a *FavoritesPage) SearchWidget() fyne.Focusable {
|
|||||||
return a.searcher
|
return a.searcher
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *FavoritesPage) OnSearched(query string) {
|
func (a *FavoritesPage) onSearched(query string) {
|
||||||
if query == "" {
|
if query == "" {
|
||||||
a.albumGrid.ResetFromState(a.gridState)
|
a.albumGrid.ResetFromState(a.gridState)
|
||||||
a.searchGridState = nil
|
a.searchGridState = nil
|
||||||
@@ -386,10 +386,12 @@ func buildArtistGridViewModel(artists []*mediaprovider.Artist) []widgets.GridVie
|
|||||||
albums = lang.L("album")
|
albums = lang.L("album")
|
||||||
}
|
}
|
||||||
model = append(model, widgets.GridViewItemModel{
|
model = append(model, widgets.GridViewItemModel{
|
||||||
ID: ar.ID,
|
ID: ar.ID,
|
||||||
CoverArtID: ar.CoverArtID,
|
CoverArtID: ar.CoverArtID,
|
||||||
Name: ar.Name,
|
Name: ar.Name,
|
||||||
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albums)},
|
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albums)},
|
||||||
|
CanFavorite: true,
|
||||||
|
IsFavorite: ar.Favorite,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return model
|
return model
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ func (g gridViewAlbumIterator) NextN(n int) []GridViewItemModel {
|
|||||||
CoverArtID: al.CoverArtID,
|
CoverArtID: al.CoverArtID,
|
||||||
Secondary: al.ArtistNames,
|
Secondary: al.ArtistNames,
|
||||||
SecondaryIDs: al.ArtistIDs,
|
SecondaryIDs: al.ArtistIDs,
|
||||||
|
CanFavorite: true,
|
||||||
|
IsFavorite: al.Favorite,
|
||||||
}
|
}
|
||||||
if y := al.Date.Year; y != nil {
|
if y := al.Date.Year; y != nil {
|
||||||
model.Suffix = strconv.Itoa(*al.Date.Year)
|
model.Suffix = strconv.Itoa(*al.Date.Year)
|
||||||
@@ -84,10 +86,12 @@ func (g gridViewArtistIterator) NextN(n int) []GridViewItemModel {
|
|||||||
albumsLabel = lang.L("album")
|
albumsLabel = lang.L("album")
|
||||||
}
|
}
|
||||||
return GridViewItemModel{
|
return GridViewItemModel{
|
||||||
Name: ar.Name,
|
Name: ar.Name,
|
||||||
ID: ar.ID,
|
ID: ar.ID,
|
||||||
CoverArtID: ar.CoverArtID,
|
CoverArtID: ar.CoverArtID,
|
||||||
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albumsLabel)},
|
Secondary: []string{fmt.Sprintf("%d %s", ar.AlbumCount, albumsLabel)},
|
||||||
|
CanFavorite: true,
|
||||||
|
IsFavorite: ar.Favorite,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ var _ fyne.Widget = (*coverImage)(nil)
|
|||||||
type coverImage struct {
|
type coverImage struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
|
EnableFavorite bool
|
||||||
|
IsFavorite bool
|
||||||
|
|
||||||
Im *ImagePlaceholder
|
Im *ImagePlaceholder
|
||||||
playbtn *canvas.Image
|
playbtn *canvas.Image
|
||||||
favoriteButton *canvas.Image
|
favoriteButton *canvas.Image
|
||||||
@@ -118,11 +121,11 @@ func (c *coverImage) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
return widget.NewSimpleRenderer(
|
return widget.NewSimpleRenderer(
|
||||||
container.NewStack(
|
container.NewStack(
|
||||||
c.Im,
|
c.Im,
|
||||||
container.NewCenter(c.playbtn),
|
|
||||||
container.NewGridWithRows(2,
|
container.NewGridWithRows(2,
|
||||||
layout.NewSpacer(),
|
layout.NewSpacer(),
|
||||||
c.bottomPanel,
|
c.bottomPanel,
|
||||||
),
|
),
|
||||||
|
container.NewCenter(c.playbtn),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -151,6 +154,12 @@ func (c *coverImage) TappedSecondary(e *fyne.PointEvent) {
|
|||||||
|
|
||||||
func (a *coverImage) MouseIn(*desktop.MouseEvent) {
|
func (a *coverImage) MouseIn(*desktop.MouseEvent) {
|
||||||
a.playbtn.Hidden = false
|
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.bottomPanel.Hidden = false
|
||||||
a.Refresh()
|
a.Refresh()
|
||||||
}
|
}
|
||||||
@@ -204,6 +213,8 @@ type GridViewItemModel struct {
|
|||||||
Secondary []string
|
Secondary []string
|
||||||
SecondaryIDs []string
|
SecondaryIDs []string
|
||||||
Suffix string
|
Suffix string
|
||||||
|
CanFavorite bool
|
||||||
|
IsFavorite bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type GridViewItem struct {
|
type GridViewItem struct {
|
||||||
@@ -282,6 +293,8 @@ func (g *GridViewItem) NeedsUpdate(model GridViewItemModel) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewItem) Update(model GridViewItemModel) {
|
func (g *GridViewItem) Update(model GridViewItemModel) {
|
||||||
|
g.Cover.IsFavorite = model.IsFavorite
|
||||||
|
g.Cover.EnableFavorite = model.CanFavorite
|
||||||
g.itemID = model.ID
|
g.itemID = model.ID
|
||||||
g.secondaryIDs = model.SecondaryIDs
|
g.secondaryIDs = model.SecondaryIDs
|
||||||
g.primaryText.SetText(model.Name)
|
g.primaryText.SetText(model.Name)
|
||||||
|
|||||||
Reference in New Issue
Block a user