translate sort order strings
This commit is contained in:
@@ -9,17 +9,13 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const ()
|
||||||
ArtistSortAlbumCount string = "Album Count"
|
|
||||||
ArtistSortNameAZ string = "Name (A-Z)"
|
|
||||||
ArtistSortRandom string = "Random"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (j *jellyfinMediaProvider) ArtistSortOrders() []string {
|
func (j *jellyfinMediaProvider) ArtistSortOrders() []string {
|
||||||
return []string{
|
return []string{
|
||||||
ArtistSortAlbumCount,
|
mediaprovider.ArtistSortAlbumCount,
|
||||||
ArtistSortNameAZ,
|
mediaprovider.ArtistSortNameAZ,
|
||||||
ArtistSortRandom,
|
mediaprovider.ArtistSortRandom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,10 +25,10 @@ func (j *jellyfinMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
|||||||
var sortFn func([]*jellyfin.Artist) []*jellyfin.Artist
|
var sortFn func([]*jellyfin.Artist) []*jellyfin.Artist
|
||||||
|
|
||||||
if sortOrder == "" {
|
if sortOrder == "" {
|
||||||
sortOrder = ArtistSortNameAZ // default
|
sortOrder = mediaprovider.ArtistSortNameAZ // default
|
||||||
}
|
}
|
||||||
switch sortOrder {
|
switch sortOrder {
|
||||||
case ArtistSortAlbumCount:
|
case mediaprovider.ArtistSortAlbumCount:
|
||||||
// Pagination needs to be disabled, to retrieve all results in a single request, and correctly sort them.
|
// Pagination needs to be disabled, to retrieve all results in a single request, and correctly sort them.
|
||||||
disablePagination = true
|
disablePagination = true
|
||||||
sortFn = func(artists []*jellyfin.Artist) []*jellyfin.Artist {
|
sortFn = func(artists []*jellyfin.Artist) []*jellyfin.Artist {
|
||||||
@@ -41,10 +37,10 @@ func (j *jellyfinMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
|||||||
})
|
})
|
||||||
return artists
|
return artists
|
||||||
}
|
}
|
||||||
case ArtistSortNameAZ:
|
case mediaprovider.ArtistSortNameAZ:
|
||||||
jfSort.Field = jellyfin.SortByName
|
jfSort.Field = jellyfin.SortByName
|
||||||
jfSort.Mode = jellyfin.SortAsc
|
jfSort.Mode = jellyfin.SortAsc
|
||||||
case ArtistSortRandom:
|
case mediaprovider.ArtistSortRandom:
|
||||||
jfSort.Field = jellyfin.SortByRandom
|
jfSort.Field = jellyfin.SortByRandom
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,44 +9,35 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
AlbumSortRecentlyAdded string = "Recently Added"
|
|
||||||
AlbumSortRandom string = "Random"
|
|
||||||
AlbumSortTitleAZ string = "Title (A-Z)"
|
|
||||||
AlbumSortArtistAZ string = "Artist (A-Z)"
|
|
||||||
AlbumSortYearAscending string = "Year (ascending)"
|
|
||||||
AlbumSortYearDescending string = "Year (descending)"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (j *jellyfinMediaProvider) AlbumSortOrders() []string {
|
func (j *jellyfinMediaProvider) AlbumSortOrders() []string {
|
||||||
return []string{
|
return []string{
|
||||||
AlbumSortRecentlyAdded,
|
mediaprovider.AlbumSortRecentlyAdded,
|
||||||
AlbumSortRandom,
|
mediaprovider.AlbumSortRandom,
|
||||||
AlbumSortTitleAZ,
|
mediaprovider.AlbumSortTitleAZ,
|
||||||
AlbumSortArtistAZ,
|
mediaprovider.AlbumSortArtistAZ,
|
||||||
AlbumSortYearAscending,
|
mediaprovider.AlbumSortYearAscending,
|
||||||
AlbumSortYearDescending,
|
mediaprovider.AlbumSortYearDescending,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprovider.AlbumFilter) mediaprovider.AlbumIterator {
|
||||||
var jfSort jellyfin.Sort
|
var jfSort jellyfin.Sort
|
||||||
switch sortOrder {
|
switch sortOrder {
|
||||||
case AlbumSortRecentlyAdded:
|
case mediaprovider.AlbumSortRecentlyAdded:
|
||||||
jfSort.Field = jellyfin.SortByDateCreated
|
jfSort.Field = jellyfin.SortByDateCreated
|
||||||
jfSort.Mode = jellyfin.SortDesc
|
jfSort.Mode = jellyfin.SortDesc
|
||||||
case AlbumSortRandom:
|
case mediaprovider.AlbumSortRandom:
|
||||||
jfSort.Field = jellyfin.SortByRandom
|
jfSort.Field = jellyfin.SortByRandom
|
||||||
case AlbumSortArtistAZ:
|
case mediaprovider.AlbumSortArtistAZ:
|
||||||
jfSort.Field = jellyfin.SortByArtist
|
jfSort.Field = jellyfin.SortByArtist
|
||||||
jfSort.Mode = jellyfin.SortAsc
|
jfSort.Mode = jellyfin.SortAsc
|
||||||
case AlbumSortTitleAZ:
|
case mediaprovider.AlbumSortTitleAZ:
|
||||||
jfSort.Field = jellyfin.SortByName
|
jfSort.Field = jellyfin.SortByName
|
||||||
jfSort.Mode = jellyfin.SortAsc
|
jfSort.Mode = jellyfin.SortAsc
|
||||||
case AlbumSortYearAscending:
|
case mediaprovider.AlbumSortYearAscending:
|
||||||
jfSort.Field = jellyfin.SortByYear
|
jfSort.Field = jellyfin.SortByYear
|
||||||
jfSort.Mode = jellyfin.SortAsc
|
jfSort.Mode = jellyfin.SortAsc
|
||||||
case AlbumSortYearDescending:
|
case mediaprovider.AlbumSortYearDescending:
|
||||||
jfSort.Field = jellyfin.SortByYear
|
jfSort.Field = jellyfin.SortByYear
|
||||||
jfSort.Mode = jellyfin.SortDesc
|
jfSort.Mode = jellyfin.SortDesc
|
||||||
}
|
}
|
||||||
@@ -64,7 +55,7 @@ func (j *jellyfinMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
|
|||||||
return sharedutil.MapSlice(al, toAlbum), nil
|
return sharedutil.MapSlice(al, toAlbum), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if sortOrder == AlbumSortRandom {
|
if sortOrder == mediaprovider.AlbumSortRandom {
|
||||||
determFetcher := func(offs, limit int) ([]*mediaprovider.Album, error) {
|
determFetcher := func(offs, limit int) ([]*mediaprovider.Album, error) {
|
||||||
al, err := j.client.GetAlbums(jellyfin.QueryOpts{
|
al, err := j.client.GetAlbums(jellyfin.QueryOpts{
|
||||||
Sort: jellyfin.Sort{Field: "SortName", Mode: jellyfin.SortAsc},
|
Sort: jellyfin.Sort{Field: "SortName", Mode: jellyfin.SortAsc},
|
||||||
|
|||||||
@@ -9,6 +9,25 @@ import (
|
|||||||
"github.com/deluan/sanitize"
|
"github.com/deluan/sanitize"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// set of all supported album sorts across all media providers
|
||||||
|
// these strings may be translated
|
||||||
|
AlbumSortRecentlyAdded string = "Recently Added"
|
||||||
|
AlbumSortRecentlyPlayed string = "Recently Played"
|
||||||
|
AlbumSortFrequentlyPlayed string = "Frequently Played"
|
||||||
|
AlbumSortRandom string = "Random"
|
||||||
|
AlbumSortTitleAZ string = "Title (A-Z)"
|
||||||
|
AlbumSortArtistAZ string = "Artist (A-Z)"
|
||||||
|
AlbumSortYearAscending string = "Year (ascending)"
|
||||||
|
AlbumSortYearDescending string = "Year (descending)"
|
||||||
|
|
||||||
|
// set of all supported artist sorts across all media providers
|
||||||
|
// these strings may be translated
|
||||||
|
ArtistSortAlbumCount string = "Album Count"
|
||||||
|
ArtistSortNameAZ string = "Name (A-Z)"
|
||||||
|
ArtistSortRandom string = "Random"
|
||||||
|
)
|
||||||
|
|
||||||
type MediaIterator[M any] interface {
|
type MediaIterator[M any] interface {
|
||||||
Next() *M
|
Next() *M
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,27 +11,16 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
AlbumSortRecentlyAdded string = "Recently Added"
|
|
||||||
AlbumSortRecentlyPlayed string = "Recently Played"
|
|
||||||
AlbumSortFrequentlyPlayed string = "Frequently Played"
|
|
||||||
AlbumSortRandom string = "Random"
|
|
||||||
AlbumSortTitleAZ string = "Title (A-Z)"
|
|
||||||
AlbumSortArtistAZ string = "Artist (A-Z)"
|
|
||||||
AlbumSortYearAscending string = "Year (ascending)"
|
|
||||||
AlbumSortYearDescending string = "Year (descending)"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) AlbumSortOrders() []string {
|
func (s *subsonicMediaProvider) AlbumSortOrders() []string {
|
||||||
return []string{
|
return []string{
|
||||||
AlbumSortRecentlyAdded,
|
mediaprovider.AlbumSortRecentlyAdded,
|
||||||
AlbumSortRecentlyPlayed,
|
mediaprovider.AlbumSortRecentlyPlayed,
|
||||||
AlbumSortFrequentlyPlayed,
|
mediaprovider.AlbumSortFrequentlyPlayed,
|
||||||
AlbumSortRandom,
|
mediaprovider.AlbumSortRandom,
|
||||||
AlbumSortTitleAZ,
|
mediaprovider.AlbumSortTitleAZ,
|
||||||
AlbumSortArtistAZ,
|
mediaprovider.AlbumSortArtistAZ,
|
||||||
AlbumSortYearAscending,
|
mediaprovider.AlbumSortYearAscending,
|
||||||
AlbumSortYearDescending,
|
mediaprovider.AlbumSortYearDescending,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,28 +75,28 @@ func (s *subsonicMediaProvider) IterateAlbums(sortOrder string, filter mediaprov
|
|||||||
return s.baseIterFromSimpleSortOrder("starred", modifiedFilter)
|
return s.baseIterFromSimpleSortOrder("starred", modifiedFilter)
|
||||||
}
|
}
|
||||||
if sortOrder == "" {
|
if sortOrder == "" {
|
||||||
sortOrder = AlbumSortRecentlyAdded // default
|
sortOrder = mediaprovider.AlbumSortRecentlyAdded // default
|
||||||
}
|
}
|
||||||
switch sortOrder {
|
switch sortOrder {
|
||||||
case AlbumSortRecentlyAdded:
|
case mediaprovider.AlbumSortRecentlyAdded:
|
||||||
return s.baseIterFromSimpleSortOrder("newest", filter)
|
return s.baseIterFromSimpleSortOrder("newest", filter)
|
||||||
case AlbumSortRecentlyPlayed:
|
case mediaprovider.AlbumSortRecentlyPlayed:
|
||||||
return s.baseIterFromSimpleSortOrder("recent", filter)
|
return s.baseIterFromSimpleSortOrder("recent", filter)
|
||||||
case AlbumSortFrequentlyPlayed:
|
case mediaprovider.AlbumSortFrequentlyPlayed:
|
||||||
return s.baseIterFromSimpleSortOrder("frequent", filter)
|
return s.baseIterFromSimpleSortOrder("frequent", filter)
|
||||||
case AlbumSortRandom:
|
case mediaprovider.AlbumSortRandom:
|
||||||
return s.newRandomIter(filter, s.prefetchCoverCB)
|
return s.newRandomIter(filter, s.prefetchCoverCB)
|
||||||
case AlbumSortTitleAZ:
|
case mediaprovider.AlbumSortTitleAZ:
|
||||||
return s.baseIterFromSimpleSortOrder("alphabeticalByName", filter)
|
return s.baseIterFromSimpleSortOrder("alphabeticalByName", filter)
|
||||||
case AlbumSortArtistAZ:
|
case mediaprovider.AlbumSortArtistAZ:
|
||||||
return s.baseIterFromSimpleSortOrder("alphabeticalByArtist", filter)
|
return s.baseIterFromSimpleSortOrder("alphabeticalByArtist", filter)
|
||||||
case AlbumSortYearAscending:
|
case mediaprovider.AlbumSortYearAscending:
|
||||||
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
|
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
|
||||||
return s.client.GetAlbumList2("byYear",
|
return s.client.GetAlbumList2("byYear",
|
||||||
map[string]string{"fromYear": "0", "toYear": "3000", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
|
map[string]string{"fromYear": "0", "toYear": "3000", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
|
||||||
}
|
}
|
||||||
return helpers.NewAlbumIterator(makeFetchFn(fetchFn), filter, s.prefetchCoverCB)
|
return helpers.NewAlbumIterator(makeFetchFn(fetchFn), filter, s.prefetchCoverCB)
|
||||||
case AlbumSortYearDescending:
|
case mediaprovider.AlbumSortYearDescending:
|
||||||
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
|
fetchFn := func(offset, limit int) ([]*subsonic.AlbumID3, error) {
|
||||||
return s.client.GetAlbumList2("byYear",
|
return s.client.GetAlbumList2("byYear",
|
||||||
map[string]string{"fromYear": "3000", "toYear": "0", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
|
map[string]string{"fromYear": "3000", "toYear": "0", "offset": strconv.Itoa(offset), "limit": strconv.Itoa(limit)})
|
||||||
|
|||||||
@@ -14,17 +14,11 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
ArtistSortAlbumCount string = "Album Count"
|
|
||||||
ArtistSortNameAZ string = "Name (A-Z)"
|
|
||||||
ArtistSortRandom string = "Random"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *subsonicMediaProvider) ArtistSortOrders() []string {
|
func (s *subsonicMediaProvider) ArtistSortOrders() []string {
|
||||||
return []string{
|
return []string{
|
||||||
ArtistSortAlbumCount,
|
mediaprovider.ArtistSortAlbumCount,
|
||||||
ArtistSortNameAZ,
|
mediaprovider.ArtistSortNameAZ,
|
||||||
ArtistSortRandom,
|
mediaprovider.ArtistSortRandom,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,10 +31,10 @@ func filterArtistMatches(f mediaprovider.ArtistFilter, artist *subsonic.ArtistID
|
|||||||
|
|
||||||
func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediaprovider.ArtistFilter) mediaprovider.ArtistIterator {
|
func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediaprovider.ArtistFilter) mediaprovider.ArtistIterator {
|
||||||
if sortOrder == "" {
|
if sortOrder == "" {
|
||||||
sortOrder = ArtistSortNameAZ // default
|
sortOrder = mediaprovider.ArtistSortNameAZ // default
|
||||||
}
|
}
|
||||||
switch sortOrder {
|
switch sortOrder {
|
||||||
case ArtistSortAlbumCount:
|
case mediaprovider.ArtistSortAlbumCount:
|
||||||
return s.baseArtistIterFromSimpleSortOrder(
|
return s.baseArtistIterFromSimpleSortOrder(
|
||||||
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
||||||
slices.SortStableFunc(artists, func(a, b *subsonic.ArtistID3) int {
|
slices.SortStableFunc(artists, func(a, b *subsonic.ArtistID3) int {
|
||||||
@@ -50,7 +44,7 @@ func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
|||||||
},
|
},
|
||||||
filter,
|
filter,
|
||||||
)
|
)
|
||||||
case ArtistSortNameAZ:
|
case mediaprovider.ArtistSortNameAZ:
|
||||||
return s.baseArtistIterFromSimpleSortOrder(
|
return s.baseArtistIterFromSimpleSortOrder(
|
||||||
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
||||||
c := collate.New(language.English, collate.Loose)
|
c := collate.New(language.English, collate.Loose)
|
||||||
@@ -61,7 +55,7 @@ func (s *subsonicMediaProvider) IterateArtists(sortOrder string, filter mediapro
|
|||||||
},
|
},
|
||||||
filter,
|
filter,
|
||||||
)
|
)
|
||||||
case ArtistSortRandom:
|
case mediaprovider.ArtistSortRandom:
|
||||||
return s.baseArtistIterFromSimpleSortOrder(
|
return s.baseArtistIterFromSimpleSortOrder(
|
||||||
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
func(artists []*subsonic.ArtistID3) []*subsonic.ArtistID3 {
|
||||||
newArtists := make([]*subsonic.ArtistID3, len(artists))
|
newArtists := make([]*subsonic.ArtistID3, len(artists))
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func (s *subsonicMediaProvider) IterateTracks(searchQuery string) mediaprovider.
|
|||||||
return &allTracksIterator{
|
return &allTracksIterator{
|
||||||
s: s,
|
s: s,
|
||||||
albumIter: s.IterateAlbums(
|
albumIter: s.IterateAlbums(
|
||||||
AlbumSortArtistAZ,
|
mediaprovider.AlbumSortArtistAZ,
|
||||||
mediaprovider.NewAlbumFilter(mediaprovider.AlbumFilterOptions{}),
|
mediaprovider.NewAlbumFilter(mediaprovider.AlbumFilterOptions{}),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"Album": "Album",
|
"Album": "Album",
|
||||||
"album": "album",
|
"album": "album",
|
||||||
"Album count": "Album count",
|
"Album count": "Album count",
|
||||||
|
"Album Count": "Album Count",
|
||||||
"Album filters": "Album filters",
|
"Album filters": "Album filters",
|
||||||
"Album gain": "Album gain",
|
"Album gain": "Album gain",
|
||||||
"Album info not available": "Album info not available",
|
"Album info not available": "Album info not available",
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
"Alt. URL": "Alt. URL",
|
"Alt. URL": "Alt. URL",
|
||||||
"Are you sure you want to delete the server": "Are you sure you want to delete the server",
|
"Are you sure you want to delete the server": "Are you sure you want to delete the server",
|
||||||
"Artist": "Artist",
|
"Artist": "Artist",
|
||||||
|
"Artist (A-Z)": "Artist (A-Z)",
|
||||||
"Artists": "Artists",
|
"Artists": "Artists",
|
||||||
"Artist biography not available.": "Artist biography not available.",
|
"Artist biography not available.": "Artist biography not available.",
|
||||||
"Audio device": "Audio device",
|
"Audio device": "Audio device",
|
||||||
@@ -69,6 +71,7 @@
|
|||||||
"File path": "File path",
|
"File path": "File path",
|
||||||
"File size": "File size",
|
"File size": "File size",
|
||||||
"Filter genres": "Filter genres",
|
"Filter genres": "Filter genres",
|
||||||
|
"Frequently Played": "Frequently Played",
|
||||||
"General": "General",
|
"General": "General",
|
||||||
"Genre": "Genre",
|
"Genre": "Genre",
|
||||||
"Genres": "Genres",
|
"Genres": "Genres",
|
||||||
@@ -91,6 +94,7 @@
|
|||||||
"Mixtape": "Mixtape",
|
"Mixtape": "Mixtape",
|
||||||
"My Server": "My Server",
|
"My Server": "My Server",
|
||||||
"Name": "Name",
|
"Name": "Name",
|
||||||
|
"Name (A-Z)": "Name (A-Z)",
|
||||||
"Nickname": "Nickname",
|
"Nickname": "Nickname",
|
||||||
"No radio stations available": "No radio stations available",
|
"No radio stations available": "No radio stations available",
|
||||||
"None": "None",
|
"None": "None",
|
||||||
@@ -119,8 +123,11 @@
|
|||||||
"Prevent clipping": "Prevent clipping",
|
"Prevent clipping": "Prevent clipping",
|
||||||
"Private": "Private",
|
"Private": "Private",
|
||||||
"Public": "Public",
|
"Public": "Public",
|
||||||
|
"Random": "Random",
|
||||||
"Rating": "Rating",
|
"Rating": "Rating",
|
||||||
"reissued": "reissued",
|
"reissued": "reissued",
|
||||||
|
"Recently Added": "Recently Added",
|
||||||
|
"Recently Played": "Recently Played",
|
||||||
"Related": "Related",
|
"Related": "Related",
|
||||||
"Remix": "Remix",
|
"Remix": "Remix",
|
||||||
"Remove from playlist": "Remove from playlist",
|
"Remove from playlist": "Remove from playlist",
|
||||||
@@ -159,6 +166,7 @@
|
|||||||
"Testing connection": "Testing connection",
|
"Testing connection": "Testing connection",
|
||||||
"Theme": "Theme",
|
"Theme": "Theme",
|
||||||
"Title": "Title",
|
"Title": "Title",
|
||||||
|
"Title (A-Z)": "Title (A-Z)",
|
||||||
"Top Tracks": "Top Tracks",
|
"Top Tracks": "Top Tracks",
|
||||||
"Total time": "Total time",
|
"Total time": "Total time",
|
||||||
"Track": "Track",
|
"Track": "Track",
|
||||||
@@ -177,5 +185,7 @@
|
|||||||
"wrong URL": "wrong URL",
|
"wrong URL": "wrong URL",
|
||||||
"wrong username/password": "wrong username/password",
|
"wrong username/password": "wrong username/password",
|
||||||
"Year": "Year",
|
"Year": "Year",
|
||||||
|
"Year (ascending)": "Year (ascending)",
|
||||||
|
"Year (descending)": "Year (descending)",
|
||||||
"Year from": "Year from"
|
"Year from": "Year from"
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
"github.com/dweymouth/supersonic/ui/util"
|
"github.com/dweymouth/supersonic/ui/util"
|
||||||
@@ -50,22 +51,25 @@ func (a *albumsPageAdapter) PlaceholderResource() fyne.Resource { return myTheme
|
|||||||
|
|
||||||
func (a *albumsPageAdapter) Route() controller.Route { return controller.AlbumsRoute() }
|
func (a *albumsPageAdapter) Route() controller.Route { return controller.AlbumsRoute() }
|
||||||
|
|
||||||
func (a *albumsPageAdapter) SortOrders() ([]string, string) {
|
func (a *albumsPageAdapter) SortOrders() ([]string, int) {
|
||||||
orders := a.mp.AlbumSortOrders()
|
orders := a.mp.AlbumSortOrders()
|
||||||
sortOrder := a.cfg.SortOrder
|
sortOrder := slices.Index(orders, a.cfg.SortOrder)
|
||||||
if !slices.Contains(orders, sortOrder) {
|
if sortOrder < 0 {
|
||||||
sortOrder = string(orders[0])
|
sortOrder = 0
|
||||||
}
|
|
||||||
return orders, sortOrder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *albumsPageAdapter) SaveSortOrder(order string) {
|
translatedOrders := sharedutil.MapSlice(orders, func(s string) string { return lang.L(s) })
|
||||||
a.cfg.SortOrder = order
|
return translatedOrders, sortOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *albumsPageAdapter) SaveSortOrder(orderIdx int) {
|
||||||
|
a.cfg.SortOrder = a.mp.AlbumSortOrders()[orderIdx]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *albumsPageAdapter) ActionButton() *widget.Button { return nil }
|
func (a *albumsPageAdapter) ActionButton() *widget.Button { return nil }
|
||||||
|
|
||||||
func (a *albumsPageAdapter) Iter(sortOrder string, filter mediaprovider.AlbumFilter) widgets.GridViewIterator {
|
func (a *albumsPageAdapter) Iter(sortOrderIdx int, filter mediaprovider.AlbumFilter) widgets.GridViewIterator {
|
||||||
|
sortOrder := a.mp.AlbumSortOrders()[sortOrderIdx]
|
||||||
return widgets.NewGridViewAlbumIterator(a.mp.IterateAlbums(sortOrder, filter))
|
return widgets.NewGridViewAlbumIterator(a.mp.IterateAlbums(sortOrder, filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/supersonic/backend"
|
"github.com/dweymouth/supersonic/backend"
|
||||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
"github.com/dweymouth/supersonic/ui/util"
|
"github.com/dweymouth/supersonic/ui/util"
|
||||||
@@ -46,22 +47,25 @@ func (a *artistsPageAdapter) PlaceholderResource() fyne.Resource { return myThem
|
|||||||
|
|
||||||
func (a *artistsPageAdapter) Route() controller.Route { return controller.ArtistsRoute() }
|
func (a *artistsPageAdapter) Route() controller.Route { return controller.ArtistsRoute() }
|
||||||
|
|
||||||
func (a *artistsPageAdapter) SortOrders() ([]string, string) {
|
func (a *artistsPageAdapter) SortOrders() ([]string, int) {
|
||||||
orders := a.mp.ArtistSortOrders()
|
orders := a.mp.ArtistSortOrders()
|
||||||
sortOrder := a.cfg.SortOrder
|
sortOrder := slices.Index(orders, a.cfg.SortOrder)
|
||||||
if !slices.Contains(orders, sortOrder) {
|
if sortOrder < 0 {
|
||||||
sortOrder = string(orders[0])
|
sortOrder = 0
|
||||||
}
|
|
||||||
return orders, sortOrder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *artistsPageAdapter) SaveSortOrder(order string) {
|
translatedOrders := sharedutil.MapSlice(orders, func(s string) string { return lang.L(s) })
|
||||||
a.cfg.SortOrder = order
|
return translatedOrders, sortOrder
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *artistsPageAdapter) SaveSortOrder(orderIdx int) {
|
||||||
|
a.cfg.SortOrder = a.mp.ArtistSortOrders()[orderIdx]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *artistsPageAdapter) ActionButton() *widget.Button { return nil }
|
func (a *artistsPageAdapter) ActionButton() *widget.Button { return nil }
|
||||||
|
|
||||||
func (a *artistsPageAdapter) Iter(sortOrder string, filter mediaprovider.ArtistFilter) widgets.GridViewIterator {
|
func (a *artistsPageAdapter) Iter(sortOrderIdx int, filter mediaprovider.ArtistFilter) widgets.GridViewIterator {
|
||||||
|
sortOrder := a.mp.ArtistSortOrders()[sortOrderIdx]
|
||||||
return widgets.NewGridViewArtistIterator(a.mp.IterateArtists(sortOrder, filter))
|
return widgets.NewGridViewArtistIterator(a.mp.IterateArtists(sortOrder, filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,8 +62,8 @@ func (g *genrePageAdapter) ActionButton() *widget.Button {
|
|||||||
return widget.NewButtonWithIcon(lang.L("Play random"), myTheme.ShuffleIcon, fn)
|
return widget.NewButtonWithIcon(lang.L("Play random"), myTheme.ShuffleIcon, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *genrePageAdapter) Iter(sortOrder string, filter mediaprovider.AlbumFilter) widgets.GridViewIterator {
|
func (a *genrePageAdapter) Iter(sortOrderIdx int, filter mediaprovider.AlbumFilter) widgets.GridViewIterator {
|
||||||
return widgets.NewGridViewAlbumIterator(a.mp.IterateAlbums(sortOrder, filter))
|
return widgets.NewGridViewAlbumIterator(a.mp.IterateAlbums("", filter))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *genrePageAdapter) SearchIter(query string, filter mediaprovider.AlbumFilter) widgets.GridViewIterator {
|
func (a *genrePageAdapter) SearchIter(query string, filter mediaprovider.AlbumFilter) widgets.GridViewIterator {
|
||||||
|
|||||||
+21
-16
@@ -62,7 +62,7 @@ type GridViewPageAdapter[M, F any] interface {
|
|||||||
|
|
||||||
// Returns the iterator for the given sortOrder and filter.
|
// Returns the iterator for the given sortOrder and filter.
|
||||||
// (Non-media pages can ignore the filter argument)
|
// (Non-media pages can ignore the filter argument)
|
||||||
Iter(sortOrder string, filter mediaprovider.MediaFilter[M, F]) widgets.GridViewIterator
|
Iter(sortOrderIdx int, filter mediaprovider.MediaFilter[M, F]) widgets.GridViewIterator
|
||||||
|
|
||||||
// Returns the iterator for the given search query and filter.
|
// Returns the iterator for the given search query and filter.
|
||||||
SearchIter(query string, filter mediaprovider.MediaFilter[M, F]) widgets.GridViewIterator
|
SearchIter(query string, filter mediaprovider.MediaFilter[M, F]) widgets.GridViewIterator
|
||||||
@@ -77,11 +77,12 @@ type GridViewPageAdapter[M, F any] interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SortableGridViewPageAdapter interface {
|
type SortableGridViewPageAdapter interface {
|
||||||
// Returns the list of sort orders and the initially selected sort order
|
// Returns the list of sort orders
|
||||||
SortOrders() ([]string, string)
|
// and the index of the initially selected sort order
|
||||||
|
SortOrders() ([]string, int)
|
||||||
|
|
||||||
// Saves the given sort order setting.
|
// Saves the given sort order setting, the selected index is passed.
|
||||||
SaveSortOrder(string)
|
SaveSortOrder(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
type sortOrderSelect struct {
|
type sortOrderSelect struct {
|
||||||
@@ -121,7 +122,7 @@ func NewGridViewPage[M, F any](
|
|||||||
gp.createTitleAndSort()
|
gp.createTitleAndSort()
|
||||||
|
|
||||||
_, canShare := mp.(mediaprovider.SupportsSharing)
|
_, canShare := mp.(mediaprovider.SupportsSharing)
|
||||||
iter := adapter.Iter(gp.getSortOrder(), gp.getFilter())
|
iter := adapter.Iter(gp.getSortOrderIdx(), gp.getFilter())
|
||||||
if g := pool.Obtain(util.WidgetTypeGridView); g != nil {
|
if g := pool.Obtain(util.WidgetTypeGridView); g != nil {
|
||||||
gp.grid = g.(*widgets.GridView)
|
gp.grid = g.(*widgets.GridView)
|
||||||
gp.grid.Placeholder = adapter.PlaceholderResource()
|
gp.grid.Placeholder = adapter.PlaceholderResource()
|
||||||
@@ -144,7 +145,7 @@ func (g *GridViewPage[M, F]) createTitleAndSort() {
|
|||||||
if s, ok := g.adapter.(SortableGridViewPageAdapter); ok {
|
if s, ok := g.adapter.(SortableGridViewPageAdapter); ok {
|
||||||
sorts, selected := s.SortOrders()
|
sorts, selected := s.SortOrders()
|
||||||
g.sortOrder = NewSortOrderSelect(sorts, g.onSortOrderChanged)
|
g.sortOrder = NewSortOrderSelect(sorts, g.onSortOrderChanged)
|
||||||
g.sortOrder.Selected = selected
|
g.sortOrder.SetSelectedIndex(selected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +181,7 @@ func (g *GridViewPage[M, F]) Reload() {
|
|||||||
if g.searchText != "" {
|
if g.searchText != "" {
|
||||||
g.doSearch(g.searchText)
|
g.doSearch(g.searchText)
|
||||||
} else {
|
} else {
|
||||||
g.grid.Reset(g.adapter.Iter(g.getSortOrder(), g.getFilter()))
|
g.grid.Reset(g.adapter.Iter(g.getSortOrderIdx(), g.getFilter()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,20 +224,24 @@ func (g *GridViewPage[M, F]) doSearch(query string) {
|
|||||||
g.grid.Reset(g.adapter.SearchIter(query, g.getFilter()))
|
g.grid.Reset(g.adapter.SearchIter(query, g.getFilter()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewPage[M, F]) onSortOrderChanged(order string) {
|
func (g *GridViewPage[M, F]) onSortOrderChanged(_ string) {
|
||||||
g.adapter.(SortableGridViewPageAdapter).SaveSortOrder(g.getSortOrder())
|
if g.grid == nil {
|
||||||
g.grid.Reset(g.adapter.Iter(g.getSortOrder(), g.getFilter()))
|
return // callback from initializing
|
||||||
|
}
|
||||||
|
|
||||||
|
g.adapter.(SortableGridViewPageAdapter).SaveSortOrder(g.getSortOrderIdx())
|
||||||
|
g.grid.Reset(g.adapter.Iter(g.getSortOrderIdx(), g.getFilter()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewPage[M, F]) getFilter() mediaprovider.MediaFilter[M, F] {
|
func (g *GridViewPage[M, F]) getFilter() mediaprovider.MediaFilter[M, F] {
|
||||||
return g.filter
|
return g.filter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewPage[M, F]) getSortOrder() string {
|
func (g *GridViewPage[M, F]) getSortOrderIdx() int {
|
||||||
if g.sortOrder != nil {
|
if g.sortOrder != nil {
|
||||||
return g.sortOrder.Selected
|
return g.sortOrder.SelectedIndex()
|
||||||
}
|
}
|
||||||
return ""
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *GridViewPage[M, F]) CreateRenderer() fyne.WidgetRenderer {
|
func (g *GridViewPage[M, F]) CreateRenderer() fyne.WidgetRenderer {
|
||||||
@@ -250,7 +255,7 @@ type savedGridViewPage[M, F any] struct {
|
|||||||
searchText string
|
searchText string
|
||||||
filter mediaprovider.MediaFilter[M, F]
|
filter mediaprovider.MediaFilter[M, F]
|
||||||
pool *util.WidgetPool
|
pool *util.WidgetPool
|
||||||
sortOrder string
|
sortOrderIdx int
|
||||||
gridState *widgets.GridViewState
|
gridState *widgets.GridViewState
|
||||||
searchGridState *widgets.GridViewState
|
searchGridState *widgets.GridViewState
|
||||||
}
|
}
|
||||||
@@ -263,7 +268,7 @@ func (g *GridViewPage[M, F]) Save() SavedPage {
|
|||||||
im: g.im,
|
im: g.im,
|
||||||
searchText: g.searchText,
|
searchText: g.searchText,
|
||||||
filter: g.filter,
|
filter: g.filter,
|
||||||
sortOrder: g.getSortOrder(),
|
sortOrderIdx: g.getSortOrderIdx(),
|
||||||
gridState: g.gridState,
|
gridState: g.gridState,
|
||||||
searchGridState: g.searchGridState,
|
searchGridState: g.searchGridState,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user