add context menu to radio list for enqueuing next or later
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/dweymouth/supersonic/sharedutil"
|
"github.com/dweymouth/supersonic/sharedutil"
|
||||||
"github.com/dweymouth/supersonic/ui/controller"
|
"github.com/dweymouth/supersonic/ui/controller"
|
||||||
"github.com/dweymouth/supersonic/ui/layouts"
|
"github.com/dweymouth/supersonic/ui/layouts"
|
||||||
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
"github.com/dweymouth/supersonic/ui/widgets"
|
"github.com/dweymouth/supersonic/ui/widgets"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
@@ -52,10 +53,8 @@ func newRadiosPage(contr *controller.Controller, rp mediaprovider.RadioProvider,
|
|||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style.SizeName = theme.SizeNameHeadingText
|
a.titleDisp.Segments[0].(*widget.TextSegment).Style.SizeName = theme.SizeNameHeadingText
|
||||||
a.list = NewRadioList(&a.nowPlayingID)
|
a.list = NewRadioList(&a.nowPlayingID)
|
||||||
a.list.OnPlay = func(station *mediaprovider.RadioStation) {
|
a.list.OnPlay = a.onPlay
|
||||||
pm.LoadRadioStation(station, backend.Replace)
|
a.list.OnQueue = a.onQueue
|
||||||
pm.PlayFromBeginning()
|
|
||||||
}
|
|
||||||
a.searcher = widgets.NewSearchEntry()
|
a.searcher = widgets.NewSearchEntry()
|
||||||
a.searcher.PlaceHolder = "Search page"
|
a.searcher.PlaceHolder = "Search page"
|
||||||
a.searcher.OnSearched = a.onSearched
|
a.searcher.OnSearched = a.onSearched
|
||||||
@@ -107,6 +106,19 @@ func (a *RadiosPage) load(searchOnLoad bool, scrollPos float32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *RadiosPage) onPlay(station *mediaprovider.RadioStation) {
|
||||||
|
a.pm.LoadRadioStation(station, backend.Replace)
|
||||||
|
a.pm.PlayFromBeginning()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *RadiosPage) onQueue(station *mediaprovider.RadioStation, next bool) {
|
||||||
|
queueMode := backend.Append
|
||||||
|
if next {
|
||||||
|
queueMode = backend.InsertNext
|
||||||
|
}
|
||||||
|
a.pm.LoadRadioStation(station, queueMode)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *RadiosPage) onSearched(query string) {
|
func (a *RadiosPage) onSearched(query string) {
|
||||||
// since the radios list is returned in full non-paginated, we will do our own
|
// since the radios list is returned in full non-paginated, we will do our own
|
||||||
// simple search based on the radio name, rather than calling a server API
|
// simple search based on the radio name, rather than calling a server API
|
||||||
@@ -193,22 +205,26 @@ func (a *RadiosPage) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
type RadioList struct {
|
type RadioList struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
OnPlay func(*mediaprovider.RadioStation)
|
OnPlay func(*mediaprovider.RadioStation)
|
||||||
|
OnQueue func(r *mediaprovider.RadioStation, next bool)
|
||||||
|
|
||||||
radios []*mediaprovider.RadioStation
|
radios []*mediaprovider.RadioStation
|
||||||
|
selected *RadioListRow
|
||||||
|
|
||||||
columnsLayout *layouts.ColumnsLayout
|
columnsLayout *layouts.ColumnsLayout
|
||||||
hdr *widgets.ListHeader
|
hdr *widgets.ListHeader
|
||||||
list *widgets.FocusList
|
list *widgets.FocusList
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
playingIcon fyne.CanvasObject
|
playingIcon fyne.CanvasObject
|
||||||
|
menu *widget.PopUpMenu
|
||||||
}
|
}
|
||||||
|
|
||||||
type RadioListRow struct {
|
type RadioListRow struct {
|
||||||
widgets.FocusListRowBase
|
widgets.FocusListRowBase
|
||||||
|
|
||||||
Item *mediaprovider.RadioStation
|
Item *mediaprovider.RadioStation
|
||||||
IsPlaying bool
|
IsPlaying bool
|
||||||
|
OnTappedSecondary func(*fyne.PointEvent)
|
||||||
|
|
||||||
nameLabel *widget.RichText
|
nameLabel *widget.RichText
|
||||||
homePageLink *widget.Hyperlink
|
homePageLink *widget.Hyperlink
|
||||||
@@ -226,6 +242,12 @@ func NewRadioListRow(layout *layouts.ColumnsLayout) *RadioListRow {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *RadioListRow) TappedSecondary(e *fyne.PointEvent) {
|
||||||
|
if a.OnTappedSecondary != nil {
|
||||||
|
a.OnTappedSecondary(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewRadioList(nowPlayingIDPtr *string) *RadioList {
|
func NewRadioList(nowPlayingIDPtr *string) *RadioList {
|
||||||
a := &RadioList{
|
a := &RadioList{
|
||||||
columnsLayout: layouts.NewColumnsLayout([]float32{-1, -1}),
|
columnsLayout: layouts.NewColumnsLayout([]float32{-1, -1}),
|
||||||
@@ -243,7 +265,21 @@ func NewRadioList(nowPlayingIDPtr *string) *RadioList {
|
|||||||
func() int { return len(a.radios) },
|
func() int { return len(a.radios) },
|
||||||
func() fyne.CanvasObject {
|
func() fyne.CanvasObject {
|
||||||
r := NewRadioListRow(a.columnsLayout)
|
r := NewRadioListRow(a.columnsLayout)
|
||||||
|
r.OnTapped = func() {
|
||||||
|
r.Selected = true
|
||||||
|
if a.selected != nil {
|
||||||
|
// unselect old row
|
||||||
|
a.selected.Selected = false
|
||||||
|
a.selected.Refresh()
|
||||||
|
}
|
||||||
|
a.selected = r
|
||||||
|
r.Refresh()
|
||||||
|
}
|
||||||
r.OnDoubleTapped = func() { a.onPlayRadio(r.Item) }
|
r.OnDoubleTapped = func() { a.onPlayRadio(r.Item) }
|
||||||
|
r.OnTappedSecondary = func(e *fyne.PointEvent) {
|
||||||
|
r.OnTapped() // handle selection
|
||||||
|
a.showMenu(e.AbsolutePosition)
|
||||||
|
}
|
||||||
r.OnFocusNeighbor = func(up bool) {
|
r.OnFocusNeighbor = func(up bool) {
|
||||||
a.list.FocusNeighbor(r.ItemID(), up)
|
a.list.FocusNeighbor(r.ItemID(), up)
|
||||||
}
|
}
|
||||||
@@ -286,6 +322,40 @@ func NewRadioList(nowPlayingIDPtr *string) *RadioList {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *RadioList) showMenu(pos fyne.Position) {
|
||||||
|
if a.menu == nil {
|
||||||
|
play := fyne.NewMenuItem("Play", func() {
|
||||||
|
if a.OnPlay != nil {
|
||||||
|
a.OnPlay(a.selected.Item)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
play.Icon = theme.MediaPlayIcon()
|
||||||
|
|
||||||
|
playNext := fyne.NewMenuItem("Play next", func() {
|
||||||
|
if a.OnQueue != nil {
|
||||||
|
a.OnQueue(a.selected.Item, true)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
playNext.Icon = myTheme.PlayNextIcon
|
||||||
|
|
||||||
|
append := fyne.NewMenuItem("Add to queue", func() {
|
||||||
|
if a.OnQueue != nil {
|
||||||
|
a.OnQueue(a.selected.Item, false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
append.Icon = theme.ContentAddIcon()
|
||||||
|
|
||||||
|
a.menu = widget.NewPopUpMenu(fyne.NewMenu("",
|
||||||
|
play,
|
||||||
|
playNext,
|
||||||
|
append,
|
||||||
|
),
|
||||||
|
fyne.CurrentApp().Driver().CanvasForObject(a),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
a.menu.ShowAtPosition(pos)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *RadioList) SetRadios(radios []*mediaprovider.RadioStation) {
|
func (g *RadioList) SetRadios(radios []*mediaprovider.RadioStation) {
|
||||||
g.radios = radios
|
g.radios = radios
|
||||||
g.Refresh()
|
g.Refresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user