/
artistspage.go
78 lines (63 loc) · 2.51 KB
/
artistspage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package browsing
import (
"slices"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/widget"
"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 "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, string) {
orders := a.mp.ArtistSortOrders()
sortOrder := a.cfg.SortOrder
if !slices.Contains(orders, sortOrder) {
sortOrder = string(orders[0])
}
return orders, sortOrder
}
func (a *artistsPageAdapter) SaveSortOrder(order string) {
a.cfg.SortOrder = order
}
func (a *artistsPageAdapter) ActionButton() *widget.Button { return nil }
func (a *artistsPageAdapter) Iter(sortOrder string, filter mediaprovider.ArtistFilter) widgets.GridViewIterator {
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) ConnectGridActions(gv *widgets.GridView) {
canShareArtists := false
if r, canShare := a.mp.(mediaprovider.SupportsSharing); canShare {
canShareArtists = r.CanShareArtists()
}
gv.DisableSharing = !canShareArtists
a.contr.ConnectArtistGridActions(gv)
}