refactor play count update to be cleaner, code-wise

This commit is contained in:
Drew Weymouth
2023-02-20 19:24:47 -08:00
parent 2f4c9ccf34
commit cd52a893d4
8 changed files with 28 additions and 36 deletions
+3 -2
View File
@@ -100,14 +100,15 @@ func (a *AlbumPage) Route() Route {
return AlbumRoute(a.albumID)
}
func (a *AlbumPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
var _ CanShowNowPlaying = (*AlbumPage)(nil)
func (a *AlbumPage) OnSongChange(song *subsonic.Child) {
if song == nil {
a.nowPlayingID = ""
} else {
a.nowPlayingID = song.ID
}
a.tracklist.SetNowPlaying(a.nowPlayingID)
a.tracklist.IncrementPlayCount(lastScrobbledIfAny)
}
func (a *AlbumPage) Reload() {
+4 -4
View File
@@ -36,7 +36,7 @@ type CanSelectAll interface {
}
type CanShowNowPlaying interface {
OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child)
OnSongChange(song *subsonic.Child)
}
type BrowsingPane struct {
@@ -150,7 +150,7 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
b.curPage = p
if np, ok := p.(CanShowNowPlaying); ok {
// inform page of currently playing track
np.OnSongChange(b.app.PlaybackManager.NowPlaying(), nil)
np.OnSongChange(b.app.PlaybackManager.NowPlaying())
}
b.pageContainer.Remove(b.curPage)
b.pageContainer.Objects[1] = p
@@ -158,12 +158,12 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
return true
}
func (b *BrowsingPane) onSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
func (b *BrowsingPane) onSongChange(song *subsonic.Child) {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowNowPlaying); ok {
p.OnSongChange(song, lastScrobbledIfAny)
p.OnSongChange(song)
}
}
+3 -2
View File
@@ -79,14 +79,15 @@ func (a *NowPlayingPage) SelectAll() {
a.tracklist.SelectAll()
}
func (a *NowPlayingPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
var _ CanShowNowPlaying = (*NowPlayingPage)(nil)
func (a *NowPlayingPage) OnSongChange(song *subsonic.Child) {
if song == nil {
a.nowPlayingID = ""
} else {
a.nowPlayingID = song.ID
}
a.tracklist.SetNowPlaying(a.nowPlayingID)
a.tracklist.IncrementPlayCount(lastScrobbledIfAny)
}
func (a *NowPlayingPage) Reload() {
+3 -2
View File
@@ -86,14 +86,15 @@ func (a *PlaylistPage) Route() Route {
return PlaylistRoute(a.playlistID)
}
func (a *PlaylistPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
var _ CanShowNowPlaying = (*PlaylistPage)(nil)
func (a *PlaylistPage) OnSongChange(song *subsonic.Child) {
if song == nil {
a.nowPlayingID = ""
} else {
a.nowPlayingID = song.ID
}
a.tracklist.SetNowPlaying(a.nowPlayingID)
a.tracklist.IncrementPlayCount(lastScrobbledIfAny)
}
func (a *PlaylistPage) Reload() {