Fixes #222: ensure pooled PageHeaders don't hold onto old state in closures

This commit is contained in:
Drew Weymouth
2023-07-17 17:07:13 -07:00
parent 5a5f551613
commit 5bb65ee6aa
3 changed files with 17 additions and 11 deletions
+7 -5
View File
@@ -189,6 +189,8 @@ type AlbumPageHeader struct {
}
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.ExtendBaseWidget(a)
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.OnTapped = func() {
page.contr.NavigateTo(controller.ArtistRoute(a.artistID))
a.page.contr.NavigateTo(controller.ArtistRoute(a.artistID))
}
a.genreLabel = widgets.NewCustomHyperlink()
a.genreLabel.OnTapped = func() {
page.contr.NavigateTo(controller.GenreRoute(a.genre))
a.page.contr.NavigateTo(controller.GenreRoute(a.genre))
}
a.miscLabel = widget.NewLabel("")
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() {
page.pm.LoadTracks(page.tracklist.GetTracks(), false, true)
page.pm.PlayFromBeginning()
a.page.pm.LoadTracks(a.page.tracklist.GetTracks(), false, true)
a.page.pm.PlayFromBeginning()
})
var pop *widget.PopUpMenu
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
+3 -1
View File
@@ -287,6 +287,8 @@ type ArtistPageHeader struct {
}
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{
artistPage: page,
titleDisp: widget.NewRichTextWithText(""),
@@ -306,7 +308,7 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
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.playRadioBtn = widget.NewButtonWithIcon(" Play Artist Radio", myTheme.ShuffleIcon, a.artistPage.playArtistRadio)
a.biographyDisp.Wrapping = fyne.TextWrapWord
a.ExtendBaseWidget(a)
a.createContainer()
+7 -5
View File
@@ -246,6 +246,8 @@ type PlaylistPageHeader struct {
}
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.ExtendBaseWidget(a)
@@ -261,18 +263,18 @@ func NewPlaylistPageHeader(page *PlaylistPage) *PlaylistPageHeader {
a.trackTimeLabel = widget.NewLabel("")
a.editButton = widget.NewButtonWithIcon("Edit", theme.DocumentCreateIcon(), func() {
if a.playlistInfo != nil {
page.contr.DoEditPlaylistWorkflow(&a.playlistInfo.Playlist)
a.page.contr.DoEditPlaylistWorkflow(&a.playlistInfo.Playlist)
}
})
a.editButton.Hidden = true
playButton := widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
page.pm.LoadTracks(page.tracks, false, false)
page.pm.PlayFromBeginning()
a.page.pm.LoadTracks(a.page.tracks, false, false)
a.page.pm.PlayFromBeginning()
})
// TODO: find way to pad shuffle svg rather than using a space in the label string
shuffleBtn := widget.NewButtonWithIcon(" Shuffle", myTheme.ShuffleIcon, func() {
page.pm.LoadTracks(page.tracks, false /*append*/, true /*shuffle*/)
page.pm.PlayFromBeginning()
a.page.pm.LoadTracks(a.page.tracks, false /*append*/, true /*shuffle*/)
a.page.pm.PlayFromBeginning()
})
var pop *widget.PopUpMenu
menuBtn := widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)