Skip to content

Commit

Permalink
add context menu items to bulk set/unset favorite
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Apr 29, 2023
1 parent c138be3 commit 5b6b6b4
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions ui/widgets/tracklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
t.OnAddToPlaylist(t.selectedTrackIDs())
}
}))
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
t.ctxMenu.Items = append(t.ctxMenu.Items,
fyne.NewMenuItem("Set favorite", func() {
t.onSetFavorites(t.selectedTracks(), true, true)
}))
t.ctxMenu.Items = append(t.ctxMenu.Items,
fyne.NewMenuItem("Unset favorite", func() {
t.onSetFavorites(t.selectedTracks(), false, true)
}))
if len(t.AuxiliaryMenuItems) > 0 {
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
t.ctxMenu.Items = append(t.ctxMenu.Items, t.AuxiliaryMenuItems...)
Expand All @@ -291,18 +300,26 @@ func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
}

func (t *Tracklist) onSetFavorite(trackID string, fav bool) {
// update our own track model
t.tracksMutex.RLock()
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
t.tracksMutex.RUnlock()
if fav {
tr.Starred = time.Now()
} else {
tr.Starred = time.Time{}
t.onSetFavorites([]*subsonic.Child{tr}, fav, false)
}

func (t *Tracklist) onSetFavorites(tracks []*subsonic.Child, fav bool, needRefresh bool) {
for _, tr := range tracks {
if fav {
tr.Starred = time.Now()
} else {
tr.Starred = time.Time{}
}
}
if needRefresh {
t.Refresh()
}
// notify listener
if t.OnSetFavorite != nil {
t.OnSetFavorite([]string{trackID}, fav)
t.OnSetFavorite(sharedutil.TracksToIDs(tracks), fav)
}
}

Expand Down

0 comments on commit 5b6b6b4

Please sign in to comment.