Interface BottomPanel through PlaybackManager to reduce direct dependency on Player

This commit is contained in:
Michael Manganiello
2023-06-18 22:43:03 -03:00
parent 2ab19f65e1
commit 4629ede7a7
3 changed files with 18 additions and 15 deletions
+11 -13
View File
@@ -34,9 +34,17 @@ type BottomPanel struct {
var _ fyne.Widget = (*BottomPanel)(nil)
func NewBottomPanel(p *player.Player, contr *controller.Controller) *BottomPanel {
bp := &BottomPanel{}
func NewBottomPanel(p *player.Player, pm *backend.PlaybackManager, contr *controller.Controller) *BottomPanel {
bp := &BottomPanel{playbackManager: pm}
bp.ExtendBaseWidget(bp)
bp.playbackManager.OnSongChange(bp.onSongChange)
bp.playbackManager.OnPlayTimeUpdate(func(cur, total float64) {
if !bp.playbackManager.IsSeeking() {
bp.Controls.UpdatePlayTime(cur, total)
}
})
p.OnPaused(func() {
bp.Controls.SetPlaying(false)
})
@@ -91,7 +99,7 @@ func NewBottomPanel(p *player.Player, contr *controller.Controller) *BottomPanel
p.Seek(fmt.Sprintf("%d", int(f*100)), player.SeekAbsolutePercent)
})
bp.Controls.OnChangeLoopMode(func() {
p.SetNextLoopMode()
bp.playbackManager.SetNextLoopMode()
})
bp.AuxControls = widgets.NewAuxControls(p.GetVolume())
@@ -104,16 +112,6 @@ func NewBottomPanel(p *player.Player, contr *controller.Controller) *BottomPanel
return bp
}
func (bp *BottomPanel) SetPlaybackManager(pm *backend.PlaybackManager) {
bp.playbackManager = pm
pm.OnSongChange(bp.onSongChange)
pm.OnPlayTimeUpdate(func(cur, total float64) {
if !pm.IsSeeking() {
bp.Controls.UpdatePlayTime(cur, total)
}
})
}
func (bp *BottomPanel) onSongChange(song, _ *mediaprovider.Track) {
if song == nil {
bp.NowPlaying.Update("", "", false, "", nil)