Fix #646: Sort artist discography by full date
This commit is contained in:
@@ -38,6 +38,26 @@ type ItemDate struct {
|
|||||||
Day *int
|
Day *int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (i ItemDate) After(other ItemDate) bool {
|
||||||
|
a := []*int{i.Year, i.Month, i.Day}
|
||||||
|
b := []*int{other.Year, other.Month, other.Day}
|
||||||
|
for i := range a {
|
||||||
|
if a[i] == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if b[i] == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if *a[i] < *b[i] {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if *a[i] > *b[i] {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type Album struct {
|
type Album struct {
|
||||||
ID string
|
ID string
|
||||||
CoverArtID string
|
CoverArtID string
|
||||||
|
|||||||
@@ -195,12 +195,12 @@ func (a *ArtistPage) getGridViewAlbumsModel() []widgets.GridViewItemModel {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
sortFunc := func(x, y int) bool {
|
sortFunc := func(x, y int) bool {
|
||||||
return a.artistInfo.Albums[x].YearOrZero() < a.artistInfo.Albums[y].YearOrZero()
|
return a.artistInfo.Albums[y].Date.After(a.artistInfo.Albums[x].Date)
|
||||||
}
|
}
|
||||||
switch a.cfg.DiscographySort {
|
switch a.cfg.DiscographySort {
|
||||||
case discographySorts[1]: /*year descending*/
|
case discographySorts[1]: /*year descending*/
|
||||||
sortFunc = func(x, y int) bool {
|
sortFunc = func(x, y int) bool {
|
||||||
return a.artistInfo.Albums[x].YearOrZero() > a.artistInfo.Albums[y].YearOrZero()
|
return a.artistInfo.Albums[x].Date.After(a.artistInfo.Albums[y].Date)
|
||||||
}
|
}
|
||||||
case discographySorts[2]: /*name*/
|
case discographySorts[2]: /*name*/
|
||||||
sortFunc = func(x, y int) bool {
|
sortFunc = func(x, y int) bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user