more work on artist list page
This commit is contained in:
@@ -37,6 +37,7 @@ func NewArtistsPage(sm *backend.ServerManager, nav func(Route)) *ArtistsPage {
|
||||
a.list.ShowAlbumCount = true
|
||||
a.list.ShowTrackCount = false
|
||||
a.buildContainer()
|
||||
go a.loadAsync()
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -46,7 +47,31 @@ func (a *ArtistsPage) loadAsync() {
|
||||
log.Printf("error loading artists: %v", err.Error())
|
||||
}
|
||||
a.list.Items = a.buildListModel(artists)
|
||||
a.list.Refresh()
|
||||
a.Refresh()
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) Route() Route {
|
||||
return ArtistsRoute()
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) Reload() {
|
||||
go a.loadAsync()
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) Save() SavedPage {
|
||||
return &savedArtistsPage{
|
||||
sm: a.sm,
|
||||
nav: a.nav,
|
||||
}
|
||||
}
|
||||
|
||||
type savedArtistsPage struct {
|
||||
sm *backend.ServerManager
|
||||
nav func(Route)
|
||||
}
|
||||
|
||||
func (s *savedArtistsPage) Restore() Page {
|
||||
return NewArtistsPage(s.sm, s.nav)
|
||||
}
|
||||
|
||||
func (a *ArtistsPage) buildListModel(artists *subsonic.ArtistsID3) []widgets.ArtistGenrePlaylistItemModel {
|
||||
|
||||
@@ -38,26 +38,22 @@ type BrowsingPane struct {
|
||||
|
||||
app *backend.App
|
||||
|
||||
// Invoked when the home button is clicked
|
||||
OnGoHome func()
|
||||
|
||||
curPage Page
|
||||
|
||||
home *widget.Button
|
||||
forward *widget.Button
|
||||
back *widget.Button
|
||||
reload *widget.Button
|
||||
history []SavedPage
|
||||
historyIdx int
|
||||
|
||||
pageContainer *fyne.Container
|
||||
container *fyne.Container
|
||||
navBtnsContainer *fyne.Container
|
||||
pageContainer *fyne.Container
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewBrowsingPane(app *backend.App) *BrowsingPane {
|
||||
b := &BrowsingPane{app: app}
|
||||
b.ExtendBaseWidget(b)
|
||||
b.home = widget.NewButtonWithIcon("", theme.HomeIcon(), b.goHome)
|
||||
b.back = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), b.GoBack)
|
||||
b.forward = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), b.GoForward)
|
||||
b.reload = widget.NewButtonWithIcon("", theme.ViewRefreshIcon(), b.Reload)
|
||||
@@ -65,8 +61,9 @@ func NewBrowsingPane(app *backend.App) *BrowsingPane {
|
||||
b.pageContainer = container.NewMax(
|
||||
canvas.NewRectangle(color.RGBA{R: 24, G: 24, B: 24, A: 255}),
|
||||
layout.NewSpacer())
|
||||
b.navBtnsContainer = container.NewHBox()
|
||||
b.container = container.NewBorder(
|
||||
container.NewHBox(b.home, b.back, b.forward, b.reload),
|
||||
container.NewHBox(b.back, b.forward, b.reload, layout.NewSpacer(), b.navBtnsContainer, layout.NewSpacer()),
|
||||
nil, nil, nil, b.pageContainer)
|
||||
return b
|
||||
}
|
||||
@@ -78,6 +75,10 @@ func (b *BrowsingPane) SetPage(p Page) {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BrowsingPane) AddNavigationButton(iconRes fyne.Resource, action func()) {
|
||||
b.navBtnsContainer.Add(widget.NewButtonWithIcon("", iconRes, action))
|
||||
}
|
||||
|
||||
func (b *BrowsingPane) doSetPage(p Page) bool {
|
||||
if b.curPage != nil && b.curPage.Route() == p.Route() {
|
||||
return false
|
||||
@@ -121,12 +122,6 @@ func (b *BrowsingPane) addPageToHistory(p Page, truncate bool) {
|
||||
b.historyIdx++
|
||||
}
|
||||
|
||||
func (b *BrowsingPane) goHome() {
|
||||
if b.OnGoHome != nil {
|
||||
b.OnGoHome()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BrowsingPane) GoBack() {
|
||||
if b.historyIdx > 0 {
|
||||
b.addPageToHistory(b.curPage, false)
|
||||
|
||||
@@ -39,6 +39,10 @@ func GenreRoute(genre string) Route {
|
||||
return Route{Page: Genre, Arg: genre}
|
||||
}
|
||||
|
||||
func ArtistsRoute() Route {
|
||||
return Route{Page: Artists}
|
||||
}
|
||||
|
||||
type NavigationHandler interface {
|
||||
SetPage(Page)
|
||||
}
|
||||
@@ -63,6 +67,8 @@ func (r Router) CreatePage(rte Route) Page {
|
||||
return NewAlbumsPage("Albums", rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
|
||||
case Artist:
|
||||
return NewArtistPage(rte.Arg, r.App.ServerManager, r.App.ImageManager, r.OpenRoute)
|
||||
case Artists:
|
||||
return NewArtistsPage(r.App.ServerManager, r.OpenRoute)
|
||||
case Genre:
|
||||
return NewGenrePage(rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
|
||||
}
|
||||
|
||||
+11
-3
@@ -2,6 +2,7 @@ package ui
|
||||
|
||||
import (
|
||||
"supersonic/backend"
|
||||
"supersonic/res"
|
||||
"supersonic/ui/browsing"
|
||||
"supersonic/ui/widgets"
|
||||
|
||||
@@ -32,9 +33,6 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App) MainWindo
|
||||
}
|
||||
|
||||
m.Router = browsing.NewRouter(app, m.BrowsingPane)
|
||||
m.BrowsingPane.OnGoHome = func() {
|
||||
m.Router.OpenRoute(HomePage)
|
||||
}
|
||||
m.BottomPanel = NewBottomPanel(app.Player, m.Router.OpenRoute)
|
||||
m.BottomPanel.SetPlaybackManager(app.PlaybackManager)
|
||||
m.BottomPanel.ImageManager = app.ImageManager
|
||||
@@ -51,6 +49,7 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App) MainWindo
|
||||
app.ServerManager.OnServerConnected(func() {
|
||||
m.Router.OpenRoute(HomePage)
|
||||
})
|
||||
m.addNavigationButtons()
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -64,6 +63,15 @@ func (m *MainWindow) PromptForFirstServer(cb func(string, string, string, string
|
||||
pop.Show()
|
||||
}
|
||||
|
||||
func (m *MainWindow) addNavigationButtons() {
|
||||
m.BrowsingPane.AddNavigationButton(res.ResDiscInvertPng, func() {
|
||||
m.Router.OpenRoute(browsing.AlbumsRoute(backend.AlbumSortRecentlyAdded))
|
||||
})
|
||||
m.BrowsingPane.AddNavigationButton(res.ResPeopleInvertPng, func() {
|
||||
m.Router.OpenRoute(browsing.ArtistsRoute())
|
||||
})
|
||||
}
|
||||
|
||||
func (m *MainWindow) Show() {
|
||||
m.Window.Show()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
@@ -28,12 +32,22 @@ type ArtistGenrePlaylistRow struct {
|
||||
|
||||
Item ArtistGenrePlaylistItemModel
|
||||
|
||||
nameLabel *widget.Label
|
||||
albumCountLabel *widget.Label
|
||||
trackCountLabel *widget.Label
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewArtistGenrePlaylistRow() *ArtistGenrePlaylistRow {
|
||||
a := &ArtistGenrePlaylistRow{}
|
||||
a := &ArtistGenrePlaylistRow{
|
||||
nameLabel: widget.NewLabel(""),
|
||||
albumCountLabel: widget.NewLabel("alCount"),
|
||||
trackCountLabel: widget.NewLabel(""),
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
// layouts.NewColumnsLayout([]float32{-1, 50, 50})
|
||||
a.container = container.New(layout.NewHBoxLayout(), a.nameLabel, a.albumCountLabel, a.trackCountLabel)
|
||||
return a
|
||||
}
|
||||
|
||||
@@ -48,6 +62,12 @@ func NewArtistGenrePlaylist(items []ArtistGenrePlaylistItemModel) *ArtistGenrePl
|
||||
func(id widget.ListItemID, item fyne.CanvasObject) {
|
||||
row := item.(*ArtistGenrePlaylistRow)
|
||||
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()
|
||||
},
|
||||
)
|
||||
return a
|
||||
|
||||
Reference in New Issue
Block a user