From 295d87a3a59465fd10f866d9e417354211d63d15 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 6 Jul 2025 10:58:46 -0700 Subject: [PATCH] start updating artist page --- ui/browsing/artistpage.go | 62 ++++++++++++++++++++++++++++------- ui/widgets/groupedreleases.go | 14 ++++---- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/ui/browsing/artistpage.go b/ui/browsing/artistpage.go index b5b95c1..8c11948 100644 --- a/ui/browsing/artistpage.go +++ b/ui/browsing/artistpage.go @@ -194,6 +194,54 @@ func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel { if a.artistInfo == nil { return nil } + + a.sortAlbumsSlices(a.artistInfo.Albums) + return sharedutil.MapSlice(a.artistInfo.Albums, a.albumToGridViewItemModel) +} + +func (a *ArtistPage) albumToGridViewItemModel(al *mediaprovider.Album) widgets.GridViewItemModel { + return widgets.GridViewItemModel{ + Name: al.Name, + ID: al.ID, + CoverArtID: al.CoverArtID, + Secondary: []string{strconv.Itoa(al.YearOrZero())}, + CanFavorite: true, + IsFavorite: al.Favorite, + } +} + +func (a *ArtistPage) getGroupedReleasesModel() widgets.GroupedReleasesModel { + if a.artistInfo == nil { + return widgets.GroupedReleasesModel{} + } + albums := []*mediaprovider.Album{} + compilations := []*mediaprovider.Album{} + eps := []*mediaprovider.Album{} + singles := []*mediaprovider.Album{} + + for _, album := range a.artistInfo.Albums { + switch rt := album.ReleaseTypes; { + case rt&mediaprovider.ReleaseTypeEP > 0: + eps = append(eps, album) + case rt&mediaprovider.ReleaseTypeCompilation > 0: + compilations = append(compilations, album) + case rt&mediaprovider.ReleaseTypeSingle > 0: + singles = append(singles, album) + default: + albums = append(albums, album) + } + } + + a.sortAlbumsSlices(albums, compilations, eps, singles) + return widgets.GroupedReleasesModel{ + Albums: sharedutil.MapSlice(albums, a.albumToGridViewItemModel), + Compilations: sharedutil.MapSlice(compilations, a.albumToGridViewItemModel), + EPs: sharedutil.MapSlice(eps, a.albumToGridViewItemModel), + Singles: sharedutil.MapSlice(singles, a.albumToGridViewItemModel), + } +} + +func (a *ArtistPage) sortAlbumsSlices(slices ...[]*mediaprovider.Album) { sortFunc := func(x, y int) bool { return a.artistInfo.Albums[y].Date.After(a.artistInfo.Albums[x].Date) } @@ -208,17 +256,9 @@ 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())}, - CanFavorite: true, - IsFavorite: al.Favorite, - } - }) + for _, slice := range slices { + sort.Slice(slice, sortFunc) + } } // should be called asynchronously diff --git a/ui/widgets/groupedreleases.go b/ui/widgets/groupedreleases.go index d740929..e22f277 100644 --- a/ui/widgets/groupedreleases.go +++ b/ui/widgets/groupedreleases.go @@ -14,10 +14,10 @@ import ( ) type GroupedReleasesModel struct { - Albums []*GridViewItemModel - Compilations []*GridViewItemModel - EPs []*GridViewItemModel - Singles []*GridViewItemModel + Albums []GridViewItemModel + Compilations []GridViewItemModel + EPs []GridViewItemModel + Singles []GridViewItemModel } type GroupedReleases struct { @@ -79,7 +79,7 @@ func (g *GroupedReleases) CreateRenderer() fyne.WidgetRenderer { } func (g *GroupedReleases) Refresh() { - sectionItems := [4][]*GridViewItemModel{g.Model.Albums, g.Model.Compilations, g.Model.EPs, g.Model.Singles} + sectionItems := [4][]GridViewItemModel{g.Model.Albums, g.Model.Compilations, g.Model.EPs, g.Model.Singles} for i, items := range sectionItems { lenItems := len(items) objects := g.sections[i].container.Objects @@ -94,12 +94,12 @@ func (g *GroupedReleases) Refresh() { // update existing cards for x := 0; x < len(objects); x++ { - g.doUpdateItemCard(objects[x].(*GridViewItem), items[x]) + g.doUpdateItemCard(objects[x].(*GridViewItem), &items[x]) } // append new ones as needed for x := len(objects); x < lenItems; x++ { card := g.cardPool.Get().(*GridViewItem) - g.doUpdateItemCard(card, items[x]) + g.doUpdateItemCard(card, &items[x]) } g.sections[i].container.Objects = objects