better debouncing of track row updates on fast scrolling

This commit is contained in:
Drew Weymouth
2025-02-21 07:33:10 -08:00
parent 6ae61d3bad
commit 2d209a29f5
2 changed files with 22 additions and 13 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ func NewTracklist(tracks []*mediaprovider.Track, im *backend.ImageManager, useCo
if t.Options.AutoNumber { if t.Options.AutoNumber {
i = itemID + 1 i = itemID + 1
} }
tr.Update(model, i) tr.Update(model, i, func() {})
if t.OnTrackShown != nil { if t.OnTrackShown != nil {
t.OnTrackShown(itemID) t.OnTrackShown(itemID)
} }
+21 -12
View File
@@ -169,6 +169,7 @@ type tracklistRowBase struct {
tracklist *Tracklist tracklist *Tracklist
trackNum int trackNum int
trackID string trackID string
coverID string
isPlaying bool isPlaying bool
isFavorite bool isFavorite bool
playCount int playCount int
@@ -202,7 +203,7 @@ type TracklistRow interface {
SetOnTappedSecondary(func(_ *fyne.PointEvent, trackNum int)) SetOnTappedSecondary(func(_ *fyne.PointEvent, trackNum int))
TrackID() string TrackID() string
Update(model *util.TrackListModel, rowNum int) Update(model *util.TrackListModel, rowNum int, onDone func())
} }
type ExpandedTracklistRow struct { type ExpandedTracklistRow struct {
@@ -254,11 +255,13 @@ func NewExpandedTracklistRow(tracklist *Tracklist, im *backend.ImageManager, pla
return t return t
} }
func (t *ExpandedTracklistRow) Update(tm *util.TrackListModel, rowNum int) { func (t *ExpandedTracklistRow) Update(tm *util.TrackListModel, rowNum int, _ func()) {
if t.trackID != tm.Track().ID { if t.trackID != tm.Track().ID && t.img.HaveImage() {
t.imageLoader.Load(tm.Track().CoverArtID) t.img.SetImage(nil, false)
} }
t.tracklistRowBase.Update(tm, rowNum) t.tracklistRowBase.Update(tm, rowNum, func() {
t.imageLoader.Load(t.coverID)
})
} }
func NewCompactTracklistRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *CompactTracklistRow { func NewCompactTracklistRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *CompactTracklistRow {
@@ -342,23 +345,28 @@ func (t *tracklistRowBase) TrackID() string {
return t.trackID return t.trackID
} }
func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int) { func (t *tracklistRowBase) Update(tm *util.TrackListModel, rowNum int, onUpdate func()) {
if tracklistUpdateCounter.NumEventsSince(time.Now().Add(-150*time.Millisecond)) > 20 { if tracklistUpdateCounter.NumEventsSince(time.Now().Add(-150*time.Millisecond)) > 20 {
t.doUpdate(&emptyTrack, 1) t.doUpdate(&emptyTrack, 1)
if t.nextUpdateModel == nil { if t.nextUpdateModel == nil {
// queue to run later // queue to run later
fyne.Do(func() { go func() {
if t.nextUpdateModel != nil { <-time.After(10 * time.Millisecond)
t.doUpdate(t.nextUpdateModel, t.nextUpdateRowNum) fyne.Do(func() {
} if t.nextUpdateModel != nil {
t.nextUpdateModel = nil t.doUpdate(t.nextUpdateModel, t.nextUpdateRowNum)
}) onUpdate()
}
t.nextUpdateModel = nil
})
}()
} }
t.nextUpdateModel = tm t.nextUpdateModel = tm
t.nextUpdateRowNum = rowNum t.nextUpdateRowNum = rowNum
} else { } else {
t.nextUpdateModel = nil t.nextUpdateModel = nil
t.doUpdate(tm, rowNum) t.doUpdate(tm, rowNum)
onUpdate()
} }
} }
@@ -375,6 +383,7 @@ func (t *tracklistRowBase) doUpdate(tm *util.TrackListModel, rowNum int) {
if id := tr.ID; id != t.trackID { if id := tr.ID; id != t.trackID {
t.EnsureUnfocused() t.EnsureUnfocused()
t.trackID = id t.trackID = id
t.coverID = tr.CoverArtID
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
t.name.SetToolTip(tr.Title) t.name.SetToolTip(tr.Title)