ensure play count in tracklist updates after scrobble

This commit is contained in:
Drew Weymouth
2023-02-13 17:04:47 -08:00
parent ed8efdf881
commit f7f6bcd546
8 changed files with 47 additions and 23 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ func (bp *BottomPanel) SetPlaybackManager(pm *backend.PlaybackManager) {
})
}
func (bp *BottomPanel) onSongChange(song *subsonic.Child) {
func (bp *BottomPanel) onSongChange(song *subsonic.Child, _ *subsonic.Child) {
if song == nil {
bp.NowPlaying.Update("", "", "", nil)
} else {
+2 -1
View File
@@ -93,13 +93,14 @@ func (a *AlbumPage) Route() Route {
return AlbumRoute(a.albumID)
}
func (a *AlbumPage) OnSongChange(song *subsonic.Child) {
func (a *AlbumPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *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() {
+5 -4
View File
@@ -36,7 +36,7 @@ type CanSelectAll interface {
}
type CanShowNowPlaying interface {
OnSongChange(song *subsonic.Child)
OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child)
}
type BrowsingPane struct {
@@ -142,7 +142,8 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
}
b.curPage = p
if np, ok := p.(CanShowNowPlaying); ok {
np.OnSongChange(b.app.PlaybackManager.NowPlaying())
// inform page of currently playing track
np.OnSongChange(b.app.PlaybackManager.NowPlaying(), nil)
}
b.pageContainer.Remove(b.curPage)
b.pageContainer.Objects[1] = p
@@ -150,12 +151,12 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
return true
}
func (b *BrowsingPane) onSongChange(song *subsonic.Child) {
func (b *BrowsingPane) onSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
if b.curPage == nil {
return
}
if p, ok := b.curPage.(CanShowNowPlaying); ok {
p.OnSongChange(song)
p.OnSongChange(song, lastScrobbledIfAny)
}
}
+2 -1
View File
@@ -77,13 +77,14 @@ func (a *NowPlayingPage) SelectAll() {
a.tracklist.SelectAll()
}
func (a *NowPlayingPage) OnSongChange(song *subsonic.Child) {
func (a *NowPlayingPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *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() {
+2 -1
View File
@@ -84,13 +84,14 @@ func (a *PlaylistPage) Route() Route {
return PlaylistRoute(a.playlistID)
}
func (a *PlaylistPage) OnSongChange(song *subsonic.Child) {
func (a *PlaylistPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *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() {
+1 -1
View File
@@ -54,7 +54,7 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App, size fyne
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(m.container)
m.Window.Resize(size)
app.PlaybackManager.OnSongChange(func(song *subsonic.Child) {
app.PlaybackManager.OnSongChange(func(song *subsonic.Child, _ *subsonic.Child) {
if song == nil {
m.Window.SetTitle(appName)
return
+15 -1
View File
@@ -105,6 +105,19 @@ func (t *Tracklist) SetNowPlaying(trackID string) {
t.list.Refresh()
}
func (t *Tracklist) IncrementPlayCount(track *subsonic.Child) {
if track == nil {
return
}
for _, tr := range t.Tracks {
if tr.ID == track.ID {
tr.PlayCount += 1
t.Refresh()
return
}
}
}
func (t *Tracklist) SelectAll() {
t.selectionMgr.SelectAll()
t.Refresh()
@@ -229,6 +242,7 @@ type TrackRow struct {
trackIdx int
trackID string
isPlaying bool
playCount int64
tappedAt int64 // unixMillis
num *widget.RichText
@@ -275,7 +289,7 @@ func NewTrackRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *TrackRow
}
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
if tr.ID == t.trackID && isPlaying == t.isPlaying {
if tr.ID == t.trackID && isPlaying == t.isPlaying && tr.PlayCount == t.playCount {
return
}
t.isPlaying = isPlaying