Files
supersonic/ui/browsing/artistspage.go
T
Jacalz 534a7bfaaf Run modernise on the project
This will be available in "go fix" within Go 1.26 but in the meantime:

go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
2025-09-17 22:28:16 +02:00

82 lines
2.6 KiB
Go

package browsing
import (
"slices"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/lang"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/controller"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
"github.com/dweymouth/supersonic/ui/widgets"
)
type artistsPageAdapter struct {
cfg *backend.ArtistsPageConfig
contr *controller.Controller
mp mediaprovider.MediaProvider
pm *backend.PlaybackManager
filter mediaprovider.ArtistFilter
}
func NewArtistsPage(cfg *backend.ArtistsPageConfig, pool *util.WidgetPool, contr *controller.Controller, pm *backend.PlaybackManager, mp mediaprovider.MediaProvider, im *backend.ImageManager) Page {
adapter := &artistsPageAdapter{cfg: cfg, contr: contr, mp: mp, pm: pm}
return NewGridViewPage(adapter, pool, mp, im)
}
func (a *artistsPageAdapter) Title() string { return lang.L("Artists") }
func (a *artistsPageAdapter) Filter() mediaprovider.ArtistFilter {
if a.filter == nil {
a.filter = mediaprovider.NewArtistFilter(
mediaprovider.ArtistFilterOptions{},
)
}
return a.filter
}
func (a *artistsPageAdapter) FilterButton() widgets.FilterButton[mediaprovider.Artist, mediaprovider.ArtistFilterOptions] {
return nil
}
func (a *artistsPageAdapter) PlaceholderResource() fyne.Resource { return myTheme.ArtistIcon }
func (a *artistsPageAdapter) Route() controller.Route { return controller.ArtistsRoute() }
func (a *artistsPageAdapter) SortOrders() ([]string, int) {
orders := a.mp.ArtistSortOrders()
sortOrder := max(slices.Index(orders, a.cfg.SortOrder), 0)
return util.LocalizeSlice(orders), sortOrder
}
func (a *artistsPageAdapter) SaveSortOrder(orderIdx int) {
a.cfg.SortOrder = a.mp.ArtistSortOrders()[orderIdx]
}
func (a *artistsPageAdapter) ActionButton() fyne.CanvasObject { return nil }
func (a *artistsPageAdapter) Iter(sortOrderIdx int, filter mediaprovider.ArtistFilter) widgets.GridViewIterator {
sortOrder := a.mp.ArtistSortOrders()[sortOrderIdx]
return widgets.NewGridViewArtistIterator(a.mp.IterateArtists(sortOrder, filter))
}
func (a *artistsPageAdapter) SearchIter(query string, filter mediaprovider.ArtistFilter) widgets.GridViewIterator {
return widgets.NewGridViewArtistIterator(a.mp.SearchArtists(query, filter))
}
func (a *artistsPageAdapter) InitGrid(gv *widgets.GridView) {
canShareArtists := false
if r, canShare := a.mp.(mediaprovider.SupportsSharing); canShare {
canShareArtists = r.CanShareArtists()
}
gv.DisableSharing = !canShareArtists
a.contr.ConnectArtistGridActions(gv)
}
func (a *artistsPageAdapter) RefreshGrid(gv *widgets.GridView) {
gv.Refresh()
}