save active artist page view in history
This commit is contained in:
+25
-12
@@ -24,11 +24,13 @@ import (
|
|||||||
var _ fyne.Widget = (*ArtistPage)(nil)
|
var _ fyne.Widget = (*ArtistPage)(nil)
|
||||||
|
|
||||||
type artistPageState struct {
|
type artistPageState struct {
|
||||||
artistID string
|
artistID string
|
||||||
pm *backend.PlaybackManager
|
activeView int
|
||||||
sm *backend.ServerManager
|
|
||||||
im *backend.ImageManager
|
pm *backend.PlaybackManager
|
||||||
contr *controller.Controller
|
sm *backend.ServerManager
|
||||||
|
im *backend.ImageManager
|
||||||
|
contr *controller.Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistPage struct {
|
type ArtistPage struct {
|
||||||
@@ -46,16 +48,22 @@ type ArtistPage struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistPage(artistID string, pm *backend.PlaybackManager, sm *backend.ServerManager, im *backend.ImageManager, contr *controller.Controller) *ArtistPage {
|
func NewArtistPage(artistID string, pm *backend.PlaybackManager, sm *backend.ServerManager, im *backend.ImageManager, contr *controller.Controller) *ArtistPage {
|
||||||
|
return newArtistPage(artistID, pm, sm, im, contr, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newArtistPage(artistID string, pm *backend.PlaybackManager, sm *backend.ServerManager, im *backend.ImageManager, contr *controller.Controller, activeView int) *ArtistPage {
|
||||||
a := &ArtistPage{artistPageState: artistPageState{
|
a := &ArtistPage{artistPageState: artistPageState{
|
||||||
artistID: artistID,
|
artistID: artistID,
|
||||||
pm: pm,
|
pm: pm,
|
||||||
sm: sm,
|
sm: sm,
|
||||||
im: im,
|
im: im,
|
||||||
contr: contr,
|
contr: contr,
|
||||||
|
activeView: activeView,
|
||||||
}}
|
}}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.header = NewArtistPageHeader(a)
|
a.header = NewArtistPageHeader(a)
|
||||||
viewToggle := widgets.NewToggleText(0, []string{"Discography", "Top Tracks"})
|
viewToggle := widgets.NewToggleText(0, []string{"Discography", "Top Tracks"})
|
||||||
|
viewToggle.SetActivatedLabel(a.activeView)
|
||||||
viewToggle.OnChanged = a.onViewChange
|
viewToggle.OnChanged = a.onViewChange
|
||||||
//line := canvas.NewLine(theme.TextColor())
|
//line := canvas.NewLine(theme.TextColor())
|
||||||
viewToggleRow := container.NewBorder(nil, nil,
|
viewToggleRow := container.NewBorder(nil, nil,
|
||||||
@@ -120,7 +128,11 @@ func (a *ArtistPage) load() {
|
|||||||
}
|
}
|
||||||
a.artistInfo = artist
|
a.artistInfo = artist
|
||||||
a.header.Update(artist)
|
a.header.Update(artist)
|
||||||
a.showAlbumGrid()
|
if a.activeView == 0 {
|
||||||
|
a.showAlbumGrid()
|
||||||
|
} else {
|
||||||
|
a.showTopTracks()
|
||||||
|
}
|
||||||
info, err := a.sm.Server.GetArtistInfo2(a.artistID, nil)
|
info, err := a.sm.Server.GetArtistInfo2(a.artistID, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to get artist info: %s", err.Error())
|
log.Printf("Failed to get artist info: %s", err.Error())
|
||||||
@@ -166,6 +178,7 @@ func (a *ArtistPage) onViewChange(num int) {
|
|||||||
// so call it asynchronously
|
// so call it asynchronously
|
||||||
go a.showTopTracks()
|
go a.showTopTracks()
|
||||||
}
|
}
|
||||||
|
a.activeView = num
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistPage) CreateRenderer() fyne.WidgetRenderer {
|
func (a *ArtistPage) CreateRenderer() fyne.WidgetRenderer {
|
||||||
@@ -174,7 +187,7 @@ func (a *ArtistPage) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *artistPageState) Restore() Page {
|
func (s *artistPageState) Restore() Page {
|
||||||
return NewArtistPage(s.artistID, s.pm, s.sm, s.im, s.contr)
|
return newArtistPage(s.artistID, s.pm, s.sm, s.im, s.contr, s.activeView)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistPageHeader struct {
|
type ArtistPageHeader struct {
|
||||||
|
|||||||
+17
-12
@@ -32,6 +32,20 @@ func NewToggleText(activeLblIdx int, labels []string) *ToggleText {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *ToggleText) SetActivatedLabel(idx int) {
|
||||||
|
changed := t.activeLabelIdx != idx
|
||||||
|
// update old label to hyperlink
|
||||||
|
hl := widget.NewHyperlink(t.labels[t.activeLabelIdx], nil)
|
||||||
|
hl.OnTapped = t.buildOnTapped(t.activeLabelIdx)
|
||||||
|
t.container.Objects[t.activeLabelIdx] = hl
|
||||||
|
// update activated label to bold text
|
||||||
|
t.container.Objects[idx] = t.newBoldRichText(t.labels[idx])
|
||||||
|
t.activeLabelIdx = idx
|
||||||
|
if changed {
|
||||||
|
t.Refresh()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (t *ToggleText) buildOnTapped(i int) func() {
|
func (t *ToggleText) buildOnTapped(i int) func() {
|
||||||
return func() {
|
return func() {
|
||||||
t.onActivated(i)
|
t.onActivated(i)
|
||||||
@@ -46,18 +60,9 @@ func (t *ToggleText) newBoldRichText(text string) *widget.RichText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *ToggleText) onActivated(idx int) {
|
func (t *ToggleText) onActivated(idx int) {
|
||||||
if idx == t.activeLabelIdx {
|
changed := t.activeLabelIdx != idx
|
||||||
return
|
t.SetActivatedLabel(idx)
|
||||||
}
|
if changed && t.OnChanged != nil {
|
||||||
// update old label to hyperlink
|
|
||||||
hl := widget.NewHyperlink(t.labels[t.activeLabelIdx], nil)
|
|
||||||
hl.OnTapped = t.buildOnTapped(t.activeLabelIdx)
|
|
||||||
t.container.Objects[t.activeLabelIdx] = hl
|
|
||||||
// update activated label to bold text
|
|
||||||
t.container.Objects[idx] = t.newBoldRichText(t.labels[idx])
|
|
||||||
t.activeLabelIdx = idx
|
|
||||||
t.Refresh()
|
|
||||||
if t.OnChanged != nil {
|
|
||||||
t.OnChanged(t.activeLabelIdx)
|
t.OnChanged(t.activeLabelIdx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user