more progress on radios
This commit is contained in:
@@ -140,11 +140,13 @@ func (b *BrowsingPane) AddSettingsMenuSeparator() {
|
||||
fyne.NewMenuItemSeparator())
|
||||
}
|
||||
|
||||
func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, pageName controller.PageName, action func()) {
|
||||
func (b *BrowsingPane) AddNavigationButton(icon fyne.Resource, pageName controller.PageName, action func()) *widget.Button {
|
||||
// make a copy of the icon, because it can change the color
|
||||
browsingPaneIcon := theme.NewThemedResource(icon)
|
||||
b.navBtnsContainer.Add(widget.NewButtonWithIcon("", browsingPaneIcon, action))
|
||||
btn := widget.NewButtonWithIcon("", browsingPaneIcon, action)
|
||||
b.navBtnsContainer.Add(btn)
|
||||
b.navBtnsPageMap[pageName] = browsingPaneIcon
|
||||
return btn
|
||||
}
|
||||
|
||||
func (b *BrowsingPane) DisableNavigationButtons() {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/dweymouth/supersonic/backend"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/sharedutil"
|
||||
"github.com/dweymouth/supersonic/ui/controller"
|
||||
@@ -25,6 +26,7 @@ type RadiosPage struct {
|
||||
|
||||
contr *controller.Controller
|
||||
rp mediaprovider.RadioProvider
|
||||
pm *backend.PlaybackManager
|
||||
radios []*mediaprovider.RadioStation
|
||||
list *RadioList
|
||||
|
||||
@@ -33,19 +35,24 @@ type RadiosPage struct {
|
||||
searcher *widgets.SearchEntry
|
||||
}
|
||||
|
||||
func NewRadiosPage(contr *controller.Controller, rp mediaprovider.RadioProvider) *RadiosPage {
|
||||
return newRadiosPage(contr, rp, "", 0)
|
||||
func NewRadiosPage(contr *controller.Controller, rp mediaprovider.RadioProvider, pm *backend.PlaybackManager) *RadiosPage {
|
||||
return newRadiosPage(contr, rp, pm, "", 0)
|
||||
}
|
||||
|
||||
func newRadiosPage(contr *controller.Controller, rp mediaprovider.RadioProvider, searchText string, scrollPos float32) *RadiosPage {
|
||||
func newRadiosPage(contr *controller.Controller, rp mediaprovider.RadioProvider, pm *backend.PlaybackManager, searchText string, scrollPos float32) *RadiosPage {
|
||||
a := &RadiosPage{
|
||||
contr: contr,
|
||||
rp: rp,
|
||||
pm: pm,
|
||||
titleDisp: widget.NewRichTextWithText("Internet Radio Stations"),
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style.SizeName = theme.SizeNameHeadingText
|
||||
a.list = NewRadioList()
|
||||
a.list.OnPlay = func(station *mediaprovider.RadioStation) {
|
||||
pm.LoadRadioStation(station, backend.Replace)
|
||||
pm.PlayFromBeginning()
|
||||
}
|
||||
a.searcher = widgets.NewSearchEntry()
|
||||
a.searcher.PlaceHolder = "Search page"
|
||||
a.searcher.OnSearched = a.onSearched
|
||||
@@ -105,9 +112,7 @@ func (a *RadiosPage) Scroll(amount float32) {
|
||||
}
|
||||
|
||||
func (a *RadiosPage) Route() controller.Route {
|
||||
// TODO
|
||||
//return controller.RadiosRoute()
|
||||
return controller.Route{}
|
||||
return controller.RadiosRoute()
|
||||
}
|
||||
|
||||
func (a *RadiosPage) Reload() {
|
||||
@@ -118,6 +123,7 @@ func (a *RadiosPage) Save() SavedPage {
|
||||
return &savedrRadiosPage{
|
||||
contr: a.contr,
|
||||
rp: a.rp,
|
||||
pm: a.pm,
|
||||
searchText: a.searcher.Entry.Text,
|
||||
scrollPos: a.list.list.GetScrollOffset(),
|
||||
}
|
||||
@@ -126,12 +132,13 @@ func (a *RadiosPage) Save() SavedPage {
|
||||
type savedrRadiosPage struct {
|
||||
contr *controller.Controller
|
||||
rp mediaprovider.RadioProvider
|
||||
pm *backend.PlaybackManager
|
||||
searchText string
|
||||
scrollPos float32
|
||||
}
|
||||
|
||||
func (s *savedrRadiosPage) Restore() Page {
|
||||
return newRadiosPage(s.contr, s.rp, s.searchText, s.scrollPos)
|
||||
return newRadiosPage(s.contr, s.rp, s.pm, s.searchText, s.scrollPos)
|
||||
}
|
||||
|
||||
func (a *RadiosPage) buildContainer() {
|
||||
@@ -150,7 +157,7 @@ func (a *RadiosPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
type RadioList struct {
|
||||
widget.BaseWidget
|
||||
|
||||
OnPlay func(string)
|
||||
OnPlay func(*mediaprovider.RadioStation)
|
||||
|
||||
radios []*mediaprovider.RadioStation
|
||||
|
||||
@@ -228,7 +235,7 @@ func (g *RadioList) SetRadios(radios []*mediaprovider.RadioStation) {
|
||||
|
||||
func (a *RadioList) onPlayRadio(item *mediaprovider.RadioStation) {
|
||||
if a.OnPlay != nil {
|
||||
a.OnPlay(item.ID)
|
||||
a.OnPlay(item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,10 @@ func (r Router) CreatePage(rte controller.Route) Page {
|
||||
return NewPlaylistsPage(r.Controller, r.widgetPool, &r.App.Config.PlaylistsPage, r.App.ServerManager.Server)
|
||||
case controller.Tracks:
|
||||
return NewTracksPage(r.Controller, &r.App.Config.TracksPage, r.widgetPool, r.App.ServerManager.Server, r.App.ImageManager)
|
||||
case controller.Radios:
|
||||
var rp mediaprovider.RadioProvider
|
||||
rp, _ = r.App.ServerManager.Server.(mediaprovider.RadioProvider)
|
||||
return NewRadiosPage(r.Controller, rp, r.App.PlaybackManager)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ const (
|
||||
Playlist
|
||||
Playlists
|
||||
Tracks
|
||||
Radios
|
||||
)
|
||||
|
||||
type Route struct {
|
||||
@@ -61,6 +62,10 @@ func ArtistsRoute() Route {
|
||||
return Route{Page: Artists}
|
||||
}
|
||||
|
||||
func RadiosRoute() Route {
|
||||
return Route{Page: Radios}
|
||||
}
|
||||
|
||||
func NowPlayingRoute(highlightedTrackID string) Route {
|
||||
return Route{Page: NowPlaying, Arg: highlightedTrackID}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,9 @@ type MainWindow struct {
|
||||
theme *theme.MyTheme
|
||||
haveSystemTray bool
|
||||
container *fyne.Container
|
||||
|
||||
// needs to bes shown/hidden when switching between servers based on whether they support radio
|
||||
radioBtn *widget.Button
|
||||
}
|
||||
|
||||
func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string, app *backend.App, size fyne.Size) MainWindow {
|
||||
@@ -183,6 +186,11 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
|
||||
}
|
||||
m.App.Config.Application.LastCheckedVersion = t
|
||||
}
|
||||
|
||||
_, supportsRadio := m.App.ServerManager.Server.(mediaprovider.RadioProvider)
|
||||
m.radioBtn.Hidden = !supportsRadio
|
||||
m.radioBtn.Refresh()
|
||||
|
||||
m.App.SaveConfigFile()
|
||||
}
|
||||
|
||||
@@ -265,6 +273,9 @@ func (m *MainWindow) addNavigationButtons() {
|
||||
m.BrowsingPane.AddNavigationButton(theme.TracksIcon, controller.Tracks, func() {
|
||||
m.Router.NavigateTo(controller.TracksRoute())
|
||||
})
|
||||
m.radioBtn = m.BrowsingPane.AddNavigationButton(theme.TracksIcon /*todo*/, controller.Radios, func() {
|
||||
m.Router.NavigateTo(controller.RadiosRoute())
|
||||
})
|
||||
}
|
||||
|
||||
func (m *MainWindow) addShortcuts() {
|
||||
|
||||
Reference in New Issue
Block a user