start updating artist page
This commit is contained in:
+51
-11
@@ -194,6 +194,54 @@ func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel {
|
|||||||
if a.artistInfo == nil {
|
if a.artistInfo == nil {
|
||||||
return 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 {
|
sortFunc := func(x, y int) bool {
|
||||||
return a.artistInfo.Albums[y].Date.After(a.artistInfo.Albums[x].Date)
|
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)
|
for _, slice := range slices {
|
||||||
return sharedutil.MapSlice(a.artistInfo.Albums, func(al *mediaprovider.Album) widgets.GridViewItemModel {
|
sort.Slice(slice, sortFunc)
|
||||||
return widgets.GridViewItemModel{
|
}
|
||||||
Name: al.Name,
|
|
||||||
ID: al.ID,
|
|
||||||
CoverArtID: al.CoverArtID,
|
|
||||||
Secondary: []string{strconv.Itoa(al.YearOrZero())},
|
|
||||||
CanFavorite: true,
|
|
||||||
IsFavorite: al.Favorite,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be called asynchronously
|
// should be called asynchronously
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type GroupedReleasesModel struct {
|
type GroupedReleasesModel struct {
|
||||||
Albums []*GridViewItemModel
|
Albums []GridViewItemModel
|
||||||
Compilations []*GridViewItemModel
|
Compilations []GridViewItemModel
|
||||||
EPs []*GridViewItemModel
|
EPs []GridViewItemModel
|
||||||
Singles []*GridViewItemModel
|
Singles []GridViewItemModel
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupedReleases struct {
|
type GroupedReleases struct {
|
||||||
@@ -79,7 +79,7 @@ func (g *GroupedReleases) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *GroupedReleases) Refresh() {
|
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 {
|
for i, items := range sectionItems {
|
||||||
lenItems := len(items)
|
lenItems := len(items)
|
||||||
objects := g.sections[i].container.Objects
|
objects := g.sections[i].container.Objects
|
||||||
@@ -94,12 +94,12 @@ func (g *GroupedReleases) Refresh() {
|
|||||||
|
|
||||||
// update existing cards
|
// update existing cards
|
||||||
for x := 0; x < len(objects); x++ {
|
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
|
// append new ones as needed
|
||||||
for x := len(objects); x < lenItems; x++ {
|
for x := len(objects); x < lenItems; x++ {
|
||||||
card := g.cardPool.Get().(*GridViewItem)
|
card := g.cardPool.Get().(*GridViewItem)
|
||||||
g.doUpdateItemCard(card, items[x])
|
g.doUpdateItemCard(card, &items[x])
|
||||||
}
|
}
|
||||||
|
|
||||||
g.sections[i].container.Objects = objects
|
g.sections[i].container.Objects = objects
|
||||||
|
|||||||
Reference in New Issue
Block a user