From 2fb885142db1742b6e27305df895b7adbdf5af5e Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Fri, 3 Nov 2023 17:11:55 -0700 Subject: [PATCH] more use of RefreshItem where appropriate --- ui/widgets/tracklist.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ui/widgets/tracklist.go b/ui/widgets/tracklist.go index ecfe6d7..1285230 100644 --- a/ui/widgets/tracklist.go +++ b/ui/widgets/tracklist.go @@ -251,15 +251,28 @@ func (t *Tracklist) SetSorting(sorting TracklistSort) { t.hdr.SetSorting(ListHeaderSort{ColNumber: ColNumber(sorting.ColumnName), Type: sorting.SortOrder}) } +// Sets the currently playing track ID and updates the list rendering func (t *Tracklist) SetNowPlaying(trackID string) { + prevNowPlaying := t.nowPlayingID + t.tracksMutex.RLock() + trPrev, idxPrev := t.findTrackByID(prevNowPlaying) + tr, idx := t.findTrackByID(trackID) + t.tracksMutex.RUnlock() t.nowPlayingID = trackID - t.list.Refresh() + if trPrev != nil { + t.list.RefreshItem(idxPrev) + } + if tr != nil { + t.list.RefreshItem(idx) + } } +// Increments the play count of the given track and updates the list rendering func (t *Tracklist) IncrementPlayCount(trackID string) { t.tracksMutex.RLock() + tr, idx := t.findTrackByID(trackID) t.tracksMutex.RUnlock() - if tr, idx := t.findTrackByID(trackID); tr != nil { + if tr != nil { tr.PlayCount += 1 t.list.RefreshItem(idx) }