Fixes #222: ensure pooled PageHeaders don't hold onto old state in closures
This commit is contained in:
@@ -189,6 +189,8 @@ type AlbumPageHeader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
||||||
|
// due to widget reuse a.page can change so page MUST NOT
|
||||||
|
// be directly captured in a closure throughout this function!
|
||||||
a := &AlbumPageHeader{page: page}
|
a := &AlbumPageHeader{page: page}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.cover = widgets.NewTappableImage(func(*fyne.PointEvent) { go a.showPopUpCover() })
|
a.cover = widgets.NewTappableImage(func(*fyne.PointEvent) { go a.showPopUpCover() })
|
||||||
@@ -202,19 +204,19 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
|
|||||||
}
|
}
|
||||||
a.artistLabel = widgets.NewCustomHyperlink()
|
a.artistLabel = widgets.NewCustomHyperlink()
|
||||||
a.artistLabel.OnTapped = func() {
|
a.artistLabel.OnTapped = func() {
|
||||||
page.contr.NavigateTo(controller.ArtistRoute(a.artistID))
|
a.page.contr.NavigateTo(controller.ArtistRoute(a.artistID))
|
||||||
}
|
}
|
||||||
a.genreLabel = widgets.NewCustomHyperlink()
|
a.genreLabel = widgets.NewCustomHyperlink()
|
||||||
a.genreLabel.OnTapped = func() {
|
a.genreLabel.OnTapped = func() {
|
||||||
page.contr.NavigateTo(controller.GenreRoute(a.genre))
|
a.page.contr.NavigateTo(controller.GenreRoute(a.genre))
|
||||||
}
|
}
|
||||||
a.miscLabel = widget.NewLabel("")
|
a.miscLabel = widget.NewLabel("")
|
||||||
playButton := widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
|
playButton := widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
|
||||||
go page.pm.PlayAlbum(page.albumID, 0, false)
|
go a.page.pm.PlayAlbum(a.page.albumID, 0, false)
|
||||||
})
|
})
|
||||||
shuffleBtn := widget.NewButtonWithIcon(" Shuffle", myTheme.ShuffleIcon, func() {
|
shuffleBtn := widget.NewButtonWithIcon(" Shuffle", myTheme.ShuffleIcon, func() {
|
||||||
page.pm.LoadTracks(page.tracklist.GetTracks(), false, true)
|
a.page.pm.LoadTracks(a.page.tracklist.GetTracks(), false, true)
|
||||||
page.pm.PlayFromBeginning()
|
a.page.pm.PlayFromBeginning()
|
||||||
})
|
})
|
||||||
var pop *widget.PopUpMenu
|
var pop *widget.PopUpMenu
|
||||||
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
|
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
|
||||||
|
|||||||
@@ -287,6 +287,8 @@ type ArtistPageHeader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
||||||
|
// due to widget reuse a.artistPage can change so page MUST NOT
|
||||||
|
// be directly captured in a closure throughout this function!
|
||||||
a := &ArtistPageHeader{
|
a := &ArtistPageHeader{
|
||||||
artistPage: page,
|
artistPage: page,
|
||||||
titleDisp: widget.NewRichTextWithText(""),
|
titleDisp: widget.NewRichTextWithText(""),
|
||||||
@@ -306,7 +308,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
|||||||
a.playBtn = widget.NewButtonWithIcon("Play Discography", theme.MediaPlayIcon(), func() {
|
a.playBtn = widget.NewButtonWithIcon("Play Discography", theme.MediaPlayIcon(), func() {
|
||||||
go a.artistPage.contr.PlayArtistDiscography(a.artistID, false /*shuffle*/)
|
go a.artistPage.contr.PlayArtistDiscography(a.artistID, false /*shuffle*/)
|
||||||
})
|
})
|
||||||
a.playRadioBtn = widget.NewButtonWithIcon(" Play Artist Radio", myTheme.ShuffleIcon, page.playArtistRadio)
|
a.playRadioBtn = widget.NewButtonWithIcon(" Play Artist Radio", myTheme.ShuffleIcon, a.artistPage.playArtistRadio)
|
||||||
a.biographyDisp.Wrapping = fyne.TextWrapWord
|
a.biographyDisp.Wrapping = fyne.TextWrapWord
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.createContainer()
|
a.createContainer()
|
||||||
|
|||||||
@@ -246,6 +246,8 @@ type PlaylistPageHeader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
||||||
|
// due to widget reuse a.page can change so page MUST NOT
|
||||||
|
// be directly captured in a closure throughout this function!
|
||||||
a := &PlaylistPageHeader{page: page}
|
a := &PlaylistPageHeader{page: page}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
|
|
||||||
@@ -261,18 +263,18 @@ func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
|
|||||||
a.trackTimeLabel = widget.NewLabel("")
|
a.trackTimeLabel = widget.NewLabel("")
|
||||||
a.editButton = widget.NewButtonWithIcon("Edit", theme.DocumentCreateIcon(), func() {
|
a.editButton = widget.NewButtonWithIcon("Edit", theme.DocumentCreateIcon(), func() {
|
||||||
if a.playlistInfo != nil {
|
if a.playlistInfo != nil {
|
||||||
page.contr.DoEditPlaylistWorkflow(&a.playlistInfo.Playlist)
|
a.page.contr.DoEditPlaylistWorkflow(&a.playlistInfo.Playlist)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
a.editButton.Hidden = true
|
a.editButton.Hidden = true
|
||||||
playButton := widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
|
playButton := widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
|
||||||
page.pm.LoadTracks(page.tracks, false, false)
|
a.page.pm.LoadTracks(a.page.tracks, false, false)
|
||||||
page.pm.PlayFromBeginning()
|
a.page.pm.PlayFromBeginning()
|
||||||
})
|
})
|
||||||
// TODO: find way to pad shuffle svg rather than using a space in the label string
|
// TODO: find way to pad shuffle svg rather than using a space in the label string
|
||||||
shuffleBtn := widget.NewButtonWithIcon(" Shuffle", myTheme.ShuffleIcon, func() {
|
shuffleBtn := widget.NewButtonWithIcon(" Shuffle", myTheme.ShuffleIcon, func() {
|
||||||
page.pm.LoadTracks(page.tracks, false /*append*/, true /*shuffle*/)
|
a.page.pm.LoadTracks(a.page.tracks, false /*append*/, true /*shuffle*/)
|
||||||
page.pm.PlayFromBeginning()
|
a.page.pm.PlayFromBeginning()
|
||||||
})
|
})
|
||||||
var pop *widget.PopUpMenu
|
var pop *widget.PopUpMenu
|
||||||
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
|
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
|
||||||
|
|||||||
Reference in New Issue
Block a user