album page now highlights currently playing track (with bold/italic font for now)

This commit is contained in:
Drew Weymouth
2023-01-04 17:11:15 -08:00
parent 395f8953e3
commit 9ac497e25b
3 changed files with 70 additions and 24 deletions
+18
View File
@@ -13,6 +13,7 @@ import (
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic"
)
type Page interface {
@@ -29,6 +30,10 @@ type CanPlayAlbum interface {
SetPlayAlbumCallback(func(albumID string, startingTrack int))
}
type CanShowNowPlaying interface {
OnSongChange(song *subsonic.Child)
}
type BrowsingPane struct {
widget.BaseWidget
@@ -57,6 +62,7 @@ func NewBrowsingPane(app *backend.App) *BrowsingPane {
b.searchBar.OnTextChanged = b.onSearchTextChanged
b.back = widget.NewButtonWithIcon("", theme.NavigateBackIcon(), b.GoBack)
b.forward = widget.NewButtonWithIcon("", theme.NavigateNextIcon(), b.GoForward)
b.app.PlaybackManager.OnSongChange(b.onSongChange)
b.pageContainer = container.NewMax(
canvas.NewRectangle(color.RGBA{R: 24, G: 24, B: 24, A: 255}),
layout.NewSpacer())
@@ -82,6 +88,9 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
_ = b.app.PlaybackManager.PlayAlbum(albumID, firstTrack)
})
}
if np, ok := p.(CanShowNowPlaying); ok {
np.OnSongChange(b.app.PlaybackManager.NowPlaying())
}
_, s := p.(Searchable)
b.searchBar.Hidden = !s
b.pageContainer.Objects[1] = p
@@ -89,6 +98,15 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
return true
}
func (b *BrowsingPane) onSongChange(song *subsonic.Child) {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowNowPlaying); ok {
p.OnSongChange(song)
}
}
func (b *BrowsingPane) addPageToHistory(p Page) {
b.history = b.history[:b.historyIdx]
b.history = append(b.history, p)