Merge branch 'main' into feature/sort-tracklist-cols
This commit is contained in:
@@ -164,7 +164,7 @@ type AlbumPageHeader struct {
|
||||
func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
||||
a := &AlbumPageHeader{page: page}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.cover = widgets.NewTappableImage(func() { go a.showPopUpCover() })
|
||||
a.cover = widgets.NewTappableImage(func(*fyne.PointEvent) { go a.showPopUpCover() })
|
||||
a.cover.FillMode = canvas.ImageFillContain
|
||||
a.cover.SetMinSize(fyne.NewSize(225, 225))
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"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"
|
||||
|
||||
@@ -75,7 +76,7 @@ func NewAlbumsPage(cfg *backend.AlbumsPageConfig, contr *controller.Controller,
|
||||
}
|
||||
a.sortOrder.Selected = cfg.SortOrder
|
||||
iter := mp.IterateAlbums(a.sortOrder.Selected, a.filter)
|
||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), im)
|
||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), im, myTheme.AlbumIcon)
|
||||
contr.ConnectAlbumGridActions(a.grid)
|
||||
a.createSearchAndFilter()
|
||||
a.createContainer(false)
|
||||
@@ -190,7 +191,7 @@ func (a *AlbumsPage) Save() SavedPage {
|
||||
func (a *AlbumsPage) doSearch(query string) {
|
||||
iter := widgets.NewGridViewAlbumIterator(a.mp.SearchAlbums(query, a.filter))
|
||||
if a.searchGrid == nil {
|
||||
a.searchGrid = widgets.NewGridView(iter, a.im)
|
||||
a.searchGrid = widgets.NewGridView(iter, a.im, myTheme.AlbumIcon)
|
||||
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
||||
} else {
|
||||
a.searchGrid.Reset(iter)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
"github.com/dweymouth/supersonic/backend"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/res"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
@@ -131,15 +130,6 @@ func (a *ArtistPage) OnSongChange(track, lastScrobbledIfAny *mediaprovider.Track
|
||||
}
|
||||
}
|
||||
|
||||
func (a *ArtistPage) playAllTracks() {
|
||||
if a.artistInfo != nil { // page loaded
|
||||
for i, album := range a.artistInfo.Albums {
|
||||
a.pm.LoadAlbum(album.ID, i > 0 /*append*/, false /*shuffle*/)
|
||||
}
|
||||
a.pm.PlayFromBeginning()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *ArtistPage) playArtistRadio() {
|
||||
go a.pm.PlaySimilarSongs(a.artistID)
|
||||
}
|
||||
@@ -180,7 +170,7 @@ func (a *ArtistPage) showAlbumGrid() {
|
||||
Secondary: strconv.Itoa(al.Year),
|
||||
}
|
||||
})
|
||||
a.albumGrid = widgets.NewFixedGridView(model, a.im)
|
||||
a.albumGrid = widgets.NewFixedGridView(model, a.im, myTheme.AlbumIcon)
|
||||
a.contr.ConnectAlbumGridActions(a.albumGrid)
|
||||
}
|
||||
a.container.Objects[0].(*fyne.Container).Objects[0] = a.albumGrid
|
||||
@@ -266,14 +256,16 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||
SizeName: theme.SizeNameHeadingText,
|
||||
}
|
||||
a.artistImage = widgets.NewImagePlaceholder(res.ResPeopleInvertPng, 225)
|
||||
a.artistImage.OnTapped = func() {
|
||||
a.artistImage = widgets.NewImagePlaceholder(myTheme.ArtistIcon, 225)
|
||||
a.artistImage.OnTapped = func(*fyne.PointEvent) {
|
||||
if im := a.artistImage.Image(); im != nil {
|
||||
a.artistPage.contr.ShowPopUpImage(im)
|
||||
}
|
||||
}
|
||||
a.favoriteBtn = widgets.NewFavoriteButton(func() { go a.toggleFavorited() })
|
||||
a.playBtn = widget.NewButtonWithIcon("Play Discography", theme.MediaPlayIcon(), page.playAllTracks)
|
||||
a.playBtn = widget.NewButtonWithIcon("Play Discography", theme.MediaPlayIcon(), func() {
|
||||
go a.artistPage.contr.PlayArtistDiscography(a.artistID, false /*shuffle*/)
|
||||
})
|
||||
a.playRadioBtn = widget.NewButtonWithIcon(" Play Artist Radio", myTheme.ShuffleIcon, page.playArtistRadio)
|
||||
a.biographyDisp.Wrapping = fyne.TextWrapWord
|
||||
a.ExtendBaseWidget(a)
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
package browsing
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
var _ fyne.Widget = (*ArtistPage)(nil)
|
||||
|
||||
type ArtistsGenresPage struct {
|
||||
widget.BaseWidget
|
||||
|
||||
isGenresPage bool
|
||||
contr *controller.Controller
|
||||
mp mediaprovider.MediaProvider
|
||||
model []widgets.ArtistGenreListItemModel
|
||||
list *widgets.ArtistGenreList
|
||||
|
||||
titleDisp *widget.RichText
|
||||
container *fyne.Container
|
||||
searcher *widgets.SearchEntry
|
||||
}
|
||||
|
||||
func NewArtistsGenresPage(isGenresPage bool, contr *controller.Controller, mp mediaprovider.MediaProvider) *ArtistsGenresPage {
|
||||
return newArtistsGenresPage(isGenresPage, contr, mp, "")
|
||||
}
|
||||
|
||||
func newArtistsGenresPage(isGenresPage bool, contr *controller.Controller, mp mediaprovider.MediaProvider, searchText string) *ArtistsGenresPage {
|
||||
title := "Artists"
|
||||
if isGenresPage {
|
||||
title = "Genres"
|
||||
}
|
||||
a := &ArtistsGenresPage{
|
||||
isGenresPage: isGenresPage,
|
||||
contr: contr,
|
||||
mp: mp,
|
||||
titleDisp: widget.NewRichTextWithText(title),
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style.SizeName = theme.SizeNameHeadingText
|
||||
a.list = widgets.NewArtistGenreList(nil)
|
||||
a.list.ShowAlbumCount = true
|
||||
a.list.ShowTrackCount = isGenresPage
|
||||
a.list.OnNavTo = func(id string) {
|
||||
if a.isGenresPage {
|
||||
a.contr.NavigateTo(controller.GenreRoute(id))
|
||||
} else {
|
||||
a.contr.NavigateTo(controller.ArtistRoute(id))
|
||||
}
|
||||
}
|
||||
a.searcher = widgets.NewSearchEntry()
|
||||
a.searcher.OnSearched = a.onSearched
|
||||
a.searcher.Entry.Text = searchText
|
||||
a.buildContainer()
|
||||
go a.load(searchText != "")
|
||||
return a
|
||||
}
|
||||
|
||||
// should be called asynchronously
|
||||
func (a *ArtistsGenresPage) load(searchOnLoad bool) {
|
||||
if a.isGenresPage {
|
||||
genres, err := a.mp.GetGenres()
|
||||
if err != nil {
|
||||
log.Printf("error loading genres: %v", err.Error())
|
||||
}
|
||||
a.model = a.buildGenresListModel(genres)
|
||||
} else {
|
||||
artists, err := a.mp.GetArtists()
|
||||
if err != nil {
|
||||
log.Printf("error loading artists: %v", err.Error())
|
||||
}
|
||||
a.model = a.buildArtistListModel(artists)
|
||||
}
|
||||
if searchOnLoad {
|
||||
a.onSearched(a.searcher.Entry.Text)
|
||||
} else {
|
||||
a.list.Items = a.model
|
||||
a.list.Refresh()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) onSearched(query string) {
|
||||
// since the artists and genres lists are returned in full non-paginated, we will do our own
|
||||
// simple search based on the artist/genre name, rather than calling a server API
|
||||
if query == "" {
|
||||
a.list.Items = a.model
|
||||
} else {
|
||||
result := sharedutil.FilterSlice(a.model, func(x widgets.ArtistGenreListItemModel) bool {
|
||||
return strings.Contains(strings.ToLower(x.Name), strings.ToLower(query))
|
||||
})
|
||||
a.list.Items = result
|
||||
}
|
||||
a.list.Refresh()
|
||||
}
|
||||
|
||||
var _ Searchable = (*ArtistsGenresPage)(nil)
|
||||
|
||||
func (a *ArtistsGenresPage) SearchWidget() fyne.Focusable {
|
||||
return a.searcher
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) Route() controller.Route {
|
||||
if a.isGenresPage {
|
||||
return controller.GenresRoute()
|
||||
}
|
||||
return controller.ArtistsRoute()
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) Reload() {
|
||||
go a.load(false)
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) Save() SavedPage {
|
||||
return &savedArtistsGenresPage{
|
||||
isGenresPage: a.isGenresPage,
|
||||
contr: a.contr,
|
||||
mp: a.mp,
|
||||
searchText: a.searcher.Entry.Text,
|
||||
}
|
||||
}
|
||||
|
||||
type savedArtistsGenresPage struct {
|
||||
isGenresPage bool
|
||||
contr *controller.Controller
|
||||
mp mediaprovider.MediaProvider
|
||||
searchText string
|
||||
}
|
||||
|
||||
func (s *savedArtistsGenresPage) Restore() Page {
|
||||
return newArtistsGenresPage(s.isGenresPage, s.contr, s.mp, s.searchText)
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) buildArtistListModel(artists []*mediaprovider.Artist) []widgets.ArtistGenreListItemModel {
|
||||
model := make([]widgets.ArtistGenreListItemModel, 0)
|
||||
for _, artist := range artists {
|
||||
model = append(model, widgets.ArtistGenreListItemModel{
|
||||
ID: artist.ID,
|
||||
Name: artist.Name,
|
||||
AlbumCount: artist.AlbumCount,
|
||||
Favorite: artist.Favorite,
|
||||
})
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) buildGenresListModel(genres []*mediaprovider.Genre) []widgets.ArtistGenreListItemModel {
|
||||
model := make([]widgets.ArtistGenreListItemModel, 0)
|
||||
for _, genre := range genres {
|
||||
model = append(model, widgets.ArtistGenreListItemModel{
|
||||
ID: genre.Name,
|
||||
Name: genre.Name,
|
||||
AlbumCount: genre.AlbumCount,
|
||||
TrackCount: genre.TrackCount,
|
||||
Favorite: false,
|
||||
})
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) buildContainer() {
|
||||
searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
|
||||
a.container = container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 5, PadBottom: 15},
|
||||
container.NewBorder(
|
||||
container.New(&layouts.MaxPadLayout{PadLeft: -5},
|
||||
container.NewHBox(a.titleDisp, layout.NewSpacer(), searchVbox)),
|
||||
nil, nil, nil, a.list))
|
||||
}
|
||||
|
||||
func (a *ArtistsGenresPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
package browsing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/supersonic/backend"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"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 ArtistsPage struct {
|
||||
widget.BaseWidget
|
||||
|
||||
contr *controller.Controller
|
||||
im *backend.ImageManager
|
||||
pm *backend.PlaybackManager
|
||||
mp mediaprovider.MediaProvider
|
||||
artists []*mediaprovider.Artist
|
||||
searchedArtists []*mediaprovider.Artist
|
||||
grid *widgets.GridView
|
||||
fullGridScrollPos float32
|
||||
searchGridScrollPos float32
|
||||
searcher *widgets.SearchEntry
|
||||
searchText string
|
||||
titleDisp *widget.RichText
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewArtistsPage(
|
||||
contr *controller.Controller,
|
||||
pm *backend.PlaybackManager,
|
||||
mp mediaprovider.MediaProvider,
|
||||
im *backend.ImageManager,
|
||||
) *ArtistsPage {
|
||||
return newArtistsPage(contr, pm, mp, im, "", 0, 0)
|
||||
}
|
||||
|
||||
func newArtistsPage(
|
||||
contr *controller.Controller,
|
||||
pm *backend.PlaybackManager,
|
||||
mp mediaprovider.MediaProvider,
|
||||
im *backend.ImageManager,
|
||||
searchText string,
|
||||
fullGridScrollPos float32,
|
||||
searchGridScrollPos float32,
|
||||
) *ArtistsPage {
|
||||
a := &ArtistsPage{
|
||||
contr: contr,
|
||||
pm: pm,
|
||||
mp: mp,
|
||||
im: im,
|
||||
searchText: searchText,
|
||||
fullGridScrollPos: fullGridScrollPos,
|
||||
searchGridScrollPos: searchGridScrollPos,
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
|
||||
a.titleDisp = widget.NewRichTextWithText("Artists")
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||
SizeName: theme.SizeNameHeadingText,
|
||||
}
|
||||
a.searcher = widgets.NewSearchEntry()
|
||||
a.searcher.OnSearched = func(query string) { a.onSearched(query, false /*firstLoad*/) }
|
||||
a.searcher.Entry.Text = searchText
|
||||
a.grid = widgets.NewFixedGridView(nil, a.im, myTheme.ArtistIcon)
|
||||
a.contr.ConnectArtistGridActions(a.grid)
|
||||
|
||||
searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
|
||||
a.container = container.NewBorder(
|
||||
container.NewHBox(util.NewHSpace(6),
|
||||
a.titleDisp, layout.NewSpacer(), searchVbox, util.NewHSpace(15)),
|
||||
nil, nil, nil, a.grid,
|
||||
)
|
||||
|
||||
go a.load()
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) Reload() {
|
||||
a.searchGridScrollPos = 0
|
||||
a.fullGridScrollPos = 0
|
||||
go a.load()
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) load() {
|
||||
artists, err := a.mp.GetArtists()
|
||||
if err != nil {
|
||||
log.Printf("error loading artists: %v", err.Error())
|
||||
}
|
||||
a.artists = artists
|
||||
a.onSearched(a.searcher.Entry.Text, true)
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) onSearched(query string, firstLoad bool) {
|
||||
// since the playlist list is returned in full non-paginated, we will do our own
|
||||
// simple search based on the name, description, and owner, rather than calling a server API
|
||||
var artists []*mediaprovider.Artist
|
||||
scrollPos := float32(0)
|
||||
if query == "" {
|
||||
a.searchedArtists = nil
|
||||
artists = a.artists
|
||||
scrollPos = a.fullGridScrollPos
|
||||
} else {
|
||||
if firstLoad { // if reloading with a saved search state, set scroll position
|
||||
scrollPos = a.searchGridScrollPos
|
||||
}
|
||||
if a.searchText == "" {
|
||||
// if first search, capture scroll position of full, unsearched grid
|
||||
a.fullGridScrollPos = a.grid.GetScrollOffset()
|
||||
}
|
||||
qLower := strings.ToLower(query)
|
||||
a.searchedArtists = sharedutil.FilterSlice(a.artists, func(p *mediaprovider.Artist) bool {
|
||||
return strings.Contains(strings.ToLower(p.Name), qLower)
|
||||
})
|
||||
artists = a.searchedArtists
|
||||
}
|
||||
a.searchText = query
|
||||
a.grid.ResetFixed(createArtistsGridViewModel(artists))
|
||||
a.grid.Refresh()
|
||||
a.grid.ScrollToOffset(scrollPos)
|
||||
}
|
||||
|
||||
func createArtistsGridViewModel(artists []*mediaprovider.Artist) []widgets.GridViewItemModel {
|
||||
return sharedutil.MapSlice(artists, func(ar *mediaprovider.Artist) widgets.GridViewItemModel {
|
||||
albums := "albums"
|
||||
if ar.AlbumCount == 1 {
|
||||
albums = "album"
|
||||
}
|
||||
return widgets.GridViewItemModel{
|
||||
Name: ar.Name,
|
||||
ID: ar.ID,
|
||||
CoverArtID: ar.CoverArtID,
|
||||
Secondary: fmt.Sprintf("%d %s", ar.AlbumCount, albums),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) Route() controller.Route {
|
||||
return controller.ArtistsRoute()
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) Save() SavedPage {
|
||||
s := &savedArtistsPage{
|
||||
contr: a.contr,
|
||||
im: a.im,
|
||||
pm: a.pm,
|
||||
mp: a.mp,
|
||||
searchText: a.searchText,
|
||||
fullGridScrollPos: a.fullGridScrollPos,
|
||||
}
|
||||
if a.searchText == "" {
|
||||
s.fullGridScrollPos = a.grid.GetScrollOffset()
|
||||
} else {
|
||||
s.searchGridScrollPos = a.grid.GetScrollOffset()
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
type savedArtistsPage struct {
|
||||
contr *controller.Controller
|
||||
im *backend.ImageManager
|
||||
pm *backend.PlaybackManager
|
||||
mp mediaprovider.MediaProvider
|
||||
searchText string
|
||||
fullGridScrollPos float32
|
||||
searchGridScrollPos float32
|
||||
}
|
||||
|
||||
func (s *savedArtistsPage) Restore() Page {
|
||||
return newArtistsPage(s.contr, s.pm, s.mp, s.im, s.searchText, s.fullGridScrollPos, s.searchGridScrollPos)
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package browsing
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend"
|
||||
@@ -33,15 +34,15 @@ type FavoritesPage struct {
|
||||
nowPlayingID string
|
||||
pendingViewSwitch bool
|
||||
|
||||
grid *widgets.GridView
|
||||
searchGrid *widgets.GridView
|
||||
artistListCtr *fyne.Container
|
||||
tracklistCtr *fyne.Container
|
||||
searcher *widgets.SearchEntry
|
||||
filterBtn *widgets.AlbumFilterButton
|
||||
titleDisp *widget.RichText
|
||||
toggleBtns *widgets.ToggleButtonGroup
|
||||
container *fyne.Container
|
||||
grid *widgets.GridView
|
||||
searchGrid *widgets.GridView
|
||||
artistGrid *widgets.GridView
|
||||
tracklistCtr *fyne.Container
|
||||
searcher *widgets.SearchEntry
|
||||
filterBtn *widgets.AlbumFilterButton
|
||||
titleDisp *widget.RichText
|
||||
toggleBtns *widgets.ToggleButtonGroup
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewFavoritesPage(cfg *backend.FavoritesPageConfig, contr *controller.Controller, mp mediaprovider.MediaProvider, pm *backend.PlaybackManager, im *backend.ImageManager) *FavoritesPage {
|
||||
@@ -56,7 +57,7 @@ func NewFavoritesPage(cfg *backend.FavoritesPageConfig, contr *controller.Contro
|
||||
a.ExtendBaseWidget(a)
|
||||
a.createHeader(0)
|
||||
iter := mp.IterateAlbums("", a.filter)
|
||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im)
|
||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im, myTheme.AlbumIcon)
|
||||
a.contr.ConnectAlbumGridActions(a.grid)
|
||||
if cfg.InitialView == "Artists" {
|
||||
a.toggleBtns.SetActivatedButton(1)
|
||||
@@ -145,7 +146,7 @@ func (a *FavoritesPage) Reload() {
|
||||
iter := a.mp.IterateAlbums("", a.filter)
|
||||
a.grid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
||||
}
|
||||
if a.tracklistCtr != nil || a.artistListCtr != nil {
|
||||
if a.tracklistCtr != nil || a.artistGrid != nil {
|
||||
go func() {
|
||||
// re-fetch starred info from server
|
||||
starred, err := a.mp.GetFavorites()
|
||||
@@ -162,13 +163,12 @@ func (a *FavoritesPage) Reload() {
|
||||
tr.Refresh()
|
||||
}
|
||||
}
|
||||
if a.artistListCtr != nil {
|
||||
if a.artistGrid != nil {
|
||||
// refresh favorite artists view
|
||||
al := a.artistListCtr.Objects[0].(*widgets.ArtistGenreList)
|
||||
al.Items = buildArtistListModel(starred.Artists)
|
||||
a.artistGrid.ResetFixed(buildArtistGridViewModel(starred.Artists))
|
||||
if a.toggleBtns.ActivatedButtonIndex() == 1 {
|
||||
// favorite artists view is visible
|
||||
al.Refresh()
|
||||
a.artistGrid.Refresh()
|
||||
}
|
||||
}
|
||||
}()
|
||||
@@ -238,7 +238,7 @@ func (a *FavoritesPage) SelectAll() {
|
||||
func (a *FavoritesPage) doSearchAlbums(query string) {
|
||||
iter := a.mp.SearchAlbums(query, a.filter)
|
||||
if a.searchGrid == nil {
|
||||
a.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im)
|
||||
a.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im, myTheme.AlbumIcon)
|
||||
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
||||
} else {
|
||||
a.searchGrid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
||||
@@ -263,7 +263,7 @@ func (a *FavoritesPage) onShowFavoriteArtists() {
|
||||
a.cfg.InitialView = "Artists" // save setting
|
||||
a.searcher.Entry.Hide() // disable search on artists for now
|
||||
a.filterBtn.Hide()
|
||||
if a.artistListCtr == nil {
|
||||
if a.artistGrid == nil {
|
||||
if a.pendingViewSwitch {
|
||||
return
|
||||
}
|
||||
@@ -277,32 +277,31 @@ func (a *FavoritesPage) onShowFavoriteArtists() {
|
||||
log.Printf("error getting starred items: %s", err.Error())
|
||||
return
|
||||
}
|
||||
model := buildArtistListModel(fav.Artists)
|
||||
artistList := widgets.NewArtistGenreList(model)
|
||||
artistList.ShowAlbumCount = true
|
||||
artistList.OnNavTo = func(artistID string) {
|
||||
a.contr.NavigateTo(controller.ArtistRoute(artistID))
|
||||
}
|
||||
a.artistListCtr = container.New(
|
||||
&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 5, PadBottom: 15},
|
||||
artistList)
|
||||
a.container.Objects[0] = a.artistListCtr
|
||||
model := buildArtistGridViewModel(fav.Artists)
|
||||
a.artistGrid = widgets.NewFixedGridView(model, a.im, myTheme.ArtistIcon)
|
||||
a.contr.ConnectArtistGridActions(a.artistGrid)
|
||||
a.container.Objects[0] = a.artistGrid
|
||||
a.Refresh()
|
||||
a.pendingViewSwitch = false
|
||||
}()
|
||||
} else {
|
||||
a.container.Objects[0] = a.artistListCtr
|
||||
a.container.Objects[0] = a.artistGrid
|
||||
a.Refresh()
|
||||
}
|
||||
}
|
||||
|
||||
func buildArtistListModel(artists []*mediaprovider.Artist) []widgets.ArtistGenreListItemModel {
|
||||
model := make([]widgets.ArtistGenreListItemModel, 0)
|
||||
func buildArtistGridViewModel(artists []*mediaprovider.Artist) []widgets.GridViewItemModel {
|
||||
model := make([]widgets.GridViewItemModel, 0)
|
||||
for _, ar := range artists {
|
||||
model = append(model, widgets.ArtistGenreListItemModel{
|
||||
albums := "albums"
|
||||
if ar.AlbumCount == 1 {
|
||||
albums = "album"
|
||||
}
|
||||
model = append(model, widgets.GridViewItemModel{
|
||||
ID: ar.ID,
|
||||
CoverArtID: ar.CoverArtID,
|
||||
Name: ar.Name,
|
||||
AlbumCount: ar.AlbumCount,
|
||||
Secondary: fmt.Sprintf("%d %s", ar.AlbumCount, albums),
|
||||
})
|
||||
}
|
||||
return model
|
||||
|
||||
@@ -33,8 +33,6 @@ type GenrePage struct {
|
||||
titleDisp *widget.RichText
|
||||
playRandom *widget.Button
|
||||
|
||||
OnPlayAlbum func(string, int)
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
@@ -55,7 +53,7 @@ func NewGenrePage(genre string, contr *controller.Controller, pm *backend.Playba
|
||||
}
|
||||
g.playRandom = widget.NewButtonWithIcon(" Play random", myTheme.ShuffleIcon, g.playRandomSongs)
|
||||
iter := g.mp.IterateAlbums("", g.filter)
|
||||
g.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im)
|
||||
g.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im, myTheme.AlbumIcon)
|
||||
g.contr.ConnectAlbumGridActions(g.grid)
|
||||
g.createSearchAndFilter()
|
||||
g.createContainer(false)
|
||||
@@ -171,7 +169,7 @@ func (g *GenrePage) OnSearched(query string) {
|
||||
func (g *GenrePage) doSearch(query string) {
|
||||
iter := g.mp.SearchAlbums(query, g.filter)
|
||||
if g.searchGrid == nil {
|
||||
g.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im)
|
||||
g.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), g.im, myTheme.AlbumIcon)
|
||||
g.contr.ConnectAlbumGridActions(g.searchGrid)
|
||||
} else {
|
||||
g.searchGrid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package browsing
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
var _ fyne.Widget = (*ArtistPage)(nil)
|
||||
|
||||
type GenresPage struct {
|
||||
widget.BaseWidget
|
||||
|
||||
contr *controller.Controller
|
||||
mp mediaprovider.MediaProvider
|
||||
genres []*mediaprovider.Genre
|
||||
list *GenreList
|
||||
|
||||
titleDisp *widget.RichText
|
||||
container *fyne.Container
|
||||
searcher *widgets.SearchEntry
|
||||
}
|
||||
|
||||
func NewGenresPage(contr *controller.Controller, mp mediaprovider.MediaProvider) *GenresPage {
|
||||
return newGenresPage(contr, mp, "")
|
||||
}
|
||||
|
||||
func newGenresPage(contr *controller.Controller, mp mediaprovider.MediaProvider, searchText string) *GenresPage {
|
||||
a := &GenresPage{
|
||||
contr: contr,
|
||||
mp: mp,
|
||||
titleDisp: widget.NewRichTextWithText("Genres"),
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style.SizeName = theme.SizeNameHeadingText
|
||||
a.list = NewGenreList(nil)
|
||||
a.list.ShowAlbumCount = true
|
||||
a.list.ShowTrackCount = true
|
||||
a.list.OnNavTo = func(id string) { a.contr.NavigateTo(controller.GenreRoute(id)) }
|
||||
a.searcher = widgets.NewSearchEntry()
|
||||
a.searcher.OnSearched = a.onSearched
|
||||
a.searcher.Entry.Text = searchText
|
||||
a.buildContainer()
|
||||
go a.load(searchText != "")
|
||||
return a
|
||||
}
|
||||
|
||||
// should be called asynchronously
|
||||
func (a *GenresPage) load(searchOnLoad bool) {
|
||||
genres, err := a.mp.GetGenres()
|
||||
if err != nil {
|
||||
log.Printf("error loading genres: %v", err.Error())
|
||||
}
|
||||
if searchOnLoad {
|
||||
a.onSearched(a.searcher.Entry.Text)
|
||||
} else {
|
||||
a.list.Items = genres
|
||||
a.list.Refresh()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *GenresPage) onSearched(query string) {
|
||||
// since the artists and genres lists are returned in full non-paginated, we will do our own
|
||||
// simple search based on the artist/genre name, rather than calling a server API
|
||||
if query == "" {
|
||||
a.list.Items = a.genres
|
||||
} else {
|
||||
result := sharedutil.FilterSlice(a.genres, func(x *mediaprovider.Genre) bool {
|
||||
return strings.Contains(strings.ToLower(x.Name), strings.ToLower(query))
|
||||
})
|
||||
a.list.Items = result
|
||||
}
|
||||
a.list.Refresh()
|
||||
}
|
||||
|
||||
var _ Searchable = (*GenresPage)(nil)
|
||||
|
||||
func (a *GenresPage) SearchWidget() fyne.Focusable {
|
||||
return a.searcher
|
||||
}
|
||||
|
||||
func (a *GenresPage) Route() controller.Route {
|
||||
return controller.GenresRoute()
|
||||
}
|
||||
|
||||
func (a *GenresPage) Reload() {
|
||||
go a.load(false)
|
||||
}
|
||||
|
||||
func (a *GenresPage) Save() SavedPage {
|
||||
return &savedArtistsGenresPage{
|
||||
contr: a.contr,
|
||||
mp: a.mp,
|
||||
searchText: a.searcher.Entry.Text,
|
||||
}
|
||||
}
|
||||
|
||||
type savedArtistsGenresPage struct {
|
||||
isGenresPage bool
|
||||
contr *controller.Controller
|
||||
mp mediaprovider.MediaProvider
|
||||
searchText string
|
||||
}
|
||||
|
||||
func (s *savedArtistsGenresPage) Restore() Page {
|
||||
return newGenresPage(s.contr, s.mp, s.searchText)
|
||||
}
|
||||
|
||||
func (a *GenresPage) buildContainer() {
|
||||
searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
|
||||
a.container = container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 5, PadBottom: 15},
|
||||
container.NewBorder(
|
||||
container.New(&layouts.MaxPadLayout{PadLeft: -5},
|
||||
container.NewHBox(a.titleDisp, layout.NewSpacer(), searchVbox)),
|
||||
nil, nil, nil, a.list))
|
||||
}
|
||||
|
||||
func (a *GenresPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
|
||||
type GenreList struct {
|
||||
widget.BaseWidget
|
||||
|
||||
Items []*mediaprovider.Genre
|
||||
ShowAlbumCount bool
|
||||
ShowTrackCount bool
|
||||
OnNavTo func(string)
|
||||
|
||||
columnsLayout *layouts.ColumnsLayout
|
||||
hdr *widgets.ListHeader
|
||||
list *widget.List
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
type GenreListRow struct {
|
||||
widget.BaseWidget
|
||||
|
||||
Item *mediaprovider.Genre
|
||||
OnTapped func()
|
||||
|
||||
nameLabel *widget.Label
|
||||
albumCountLabel *widget.Label
|
||||
trackCountLabel *widget.Label
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewGenreListRow(layout *layouts.ColumnsLayout) *GenreListRow {
|
||||
a := &GenreListRow{
|
||||
nameLabel: widget.NewLabel(""),
|
||||
albumCountLabel: widget.NewLabel(""),
|
||||
trackCountLabel: widget.NewLabel(""),
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.albumCountLabel.Alignment = fyne.TextAlignTrailing
|
||||
a.trackCountLabel.Alignment = fyne.TextAlignTrailing
|
||||
a.container = container.New(layout, a.nameLabel, a.albumCountLabel, a.trackCountLabel)
|
||||
return a
|
||||
}
|
||||
|
||||
func NewGenreList(items []*mediaprovider.Genre) *GenreList {
|
||||
a := &GenreList{
|
||||
Items: items,
|
||||
columnsLayout: layouts.NewColumnsLayout([]float32{-1, 125, 125}),
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.hdr = widgets.NewListHeader([]widgets.ListColumn{
|
||||
{"Name", false, false}, {"Album Count", true, false}, {"Track Count", true, false}}, a.columnsLayout)
|
||||
a.list = widget.NewList(
|
||||
func() int { return len(a.Items) },
|
||||
func() fyne.CanvasObject {
|
||||
r := NewGenreListRow(a.columnsLayout)
|
||||
r.OnTapped = func() { a.onRowDoubleTapped(r.Item) }
|
||||
return r
|
||||
},
|
||||
func(id widget.ListItemID, item fyne.CanvasObject) {
|
||||
row := item.(*GenreListRow)
|
||||
row.Item = a.Items[id]
|
||||
row.albumCountLabel.Hidden = !a.ShowAlbumCount
|
||||
row.trackCountLabel.Hidden = !a.ShowTrackCount
|
||||
row.nameLabel.Text = row.Item.Name
|
||||
row.albumCountLabel.Text = strconv.Itoa(row.Item.AlbumCount)
|
||||
row.trackCountLabel.Text = strconv.Itoa(row.Item.TrackCount)
|
||||
row.Refresh()
|
||||
},
|
||||
)
|
||||
a.container = container.NewBorder(a.hdr, nil, nil, nil, a.list)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *GenreList) Refresh() {
|
||||
a.hdr.SetColumnVisible(1, a.ShowAlbumCount)
|
||||
a.hdr.SetColumnVisible(2, a.ShowTrackCount)
|
||||
a.BaseWidget.Refresh()
|
||||
}
|
||||
|
||||
func (a *GenreList) onRowDoubleTapped(item *mediaprovider.Genre) {
|
||||
if a.OnNavTo != nil {
|
||||
a.OnNavTo(item.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *GenreListRow) Tapped(*fyne.PointEvent) {
|
||||
if a.OnTapped != nil {
|
||||
a.OnTapped()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *GenreList) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
|
||||
func (a *GenreListRow) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"github.com/dweymouth/supersonic/backend"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/res"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
@@ -208,7 +207,7 @@ func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
||||
a := &PlaylistPageHeader{page: page}
|
||||
a.ExtendBaseWidget(a)
|
||||
|
||||
a.image = widgets.NewImagePlaceholder(res.ResPlaylistInvertPng, 225)
|
||||
a.image = widgets.NewImagePlaceholder(myTheme.PlaylistIcon, 225)
|
||||
a.titleLabel = widget.NewRichTextWithText("")
|
||||
a.titleLabel.Wrapping = fyne.TextTruncate
|
||||
a.titleLabel.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
"github.com/dweymouth/supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
@@ -94,7 +95,7 @@ func (a *PlaylistsPage) createListView() {
|
||||
|
||||
func (a *PlaylistsPage) createGridView(playlists []*mediaprovider.Playlist) {
|
||||
model := createPlaylistGridViewModel(playlists)
|
||||
a.gridView = widgets.NewFixedGridView(model, a.contr.App.ImageManager)
|
||||
a.gridView = widgets.NewFixedGridView(model, a.contr.App.ImageManager, myTheme.PlaylistIcon)
|
||||
a.gridView.OnPlay = func(id string, shuffle bool) {
|
||||
go a.contr.App.PlaybackManager.PlayPlaylist(id, 0, shuffle)
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ func (r Router) CreatePage(rte controller.Route) Page {
|
||||
case controller.Artist:
|
||||
return NewArtistPage(rte.Arg, &r.App.Config.ArtistPage, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager, r.Controller)
|
||||
case controller.Artists:
|
||||
return NewArtistsGenresPage(false, r.Controller, r.App.ServerManager.Server)
|
||||
return NewArtistsPage(r.Controller, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager)
|
||||
case controller.Favorites:
|
||||
return NewFavoritesPage(&r.App.Config.FavoritesPage, r.Controller, r.App.ServerManager.Server, r.App.PlaybackManager, r.App.ImageManager)
|
||||
case controller.Genre:
|
||||
return NewGenrePage(rte.Arg, r.Controller, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager)
|
||||
case controller.Genres:
|
||||
return NewArtistsGenresPage(true, r.Controller, r.App.ServerManager.Server)
|
||||
return NewGenresPage(r.Controller, r.App.ServerManager.Server)
|
||||
case controller.NowPlaying:
|
||||
return NewNowPlayingPage(rte.Arg, r.Controller, &r.App.Config.NowPlayingPage, r.App.PlaybackManager)
|
||||
case controller.Playlist:
|
||||
|
||||
Reference in New Issue
Block a user