another big refactor to make code more manageable
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ type AlbumGrid struct {
|
||||
fetching bool
|
||||
done bool
|
||||
|
||||
imageFetcher func(string) (image.Image, error)
|
||||
imageFetcher ImageFetcher
|
||||
OnPlayAlbum func(string)
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -59,8 +59,8 @@ type BottomPanel struct {
|
||||
|
||||
playbackManager *backend.PlaybackManager
|
||||
|
||||
nowPlaying *widgets.NowPlayingCard
|
||||
controls *widgets.PlayerControls
|
||||
NowPlaying *widgets.NowPlayingCard
|
||||
Controls *widgets.PlayerControls
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
@@ -70,31 +70,31 @@ func NewBottomPanel(p *player.Player) *BottomPanel {
|
||||
bp := &BottomPanel{}
|
||||
bp.ExtendBaseWidget(bp)
|
||||
p.OnPaused(func() {
|
||||
bp.controls.SetPlaying(false)
|
||||
bp.Controls.SetPlaying(false)
|
||||
})
|
||||
p.OnPlaying(func() {
|
||||
bp.controls.SetPlaying(true)
|
||||
bp.Controls.SetPlaying(true)
|
||||
})
|
||||
p.OnStopped(func() {
|
||||
bp.controls.SetPlaying(false)
|
||||
bp.Controls.SetPlaying(false)
|
||||
})
|
||||
|
||||
bp.nowPlaying = widgets.NewNowPlayingCard()
|
||||
bp.controls = widgets.NewPlayerControls()
|
||||
bp.controls.OnPlayPause(func() {
|
||||
bp.NowPlaying = widgets.NewNowPlayingCard()
|
||||
bp.Controls = widgets.NewPlayerControls()
|
||||
bp.Controls.OnPlayPause(func() {
|
||||
p.PlayPause()
|
||||
})
|
||||
bp.controls.OnSeekNext(func() {
|
||||
bp.Controls.OnSeekNext(func() {
|
||||
p.SeekNext()
|
||||
})
|
||||
bp.controls.OnSeekPrevious(func() {
|
||||
bp.Controls.OnSeekPrevious(func() {
|
||||
p.SeekBackOrPrevious()
|
||||
})
|
||||
bp.controls.OnSeek(func(f float64) {
|
||||
bp.Controls.OnSeek(func(f float64) {
|
||||
p.Seek(fmt.Sprintf("%d", int(f*100)), player.SeekAbsolutePercent)
|
||||
})
|
||||
|
||||
bp.container = container.New(newBottomPanelLayout(500, bp.nowPlaying, bp.controls, nil), bp.nowPlaying, bp.controls)
|
||||
bp.container = container.New(newBottomPanelLayout(500, bp.NowPlaying, bp.Controls, nil), bp.NowPlaying, bp.Controls)
|
||||
return bp
|
||||
}
|
||||
|
||||
@@ -103,20 +103,20 @@ func (bp *BottomPanel) SetPlaybackManager(pm *backend.PlaybackManager) {
|
||||
pm.OnSongChange(bp.onSongChange)
|
||||
pm.OnPlayTimeUpdate(func(cur, total float64) {
|
||||
if !pm.IsSeeking() {
|
||||
bp.controls.UpdatePlayTime(cur, total)
|
||||
bp.Controls.UpdatePlayTime(cur, total)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (bp *BottomPanel) onSongChange(song *subsonic.Child) {
|
||||
if song == nil {
|
||||
bp.nowPlaying.Update("", "", "", nil)
|
||||
bp.NowPlaying.Update("", "", "", nil)
|
||||
} else {
|
||||
var im image.Image
|
||||
if bp.ImageManager != nil {
|
||||
im, _ = bp.ImageManager.GetAlbumThumbnail(song.AlbumID)
|
||||
}
|
||||
bp.nowPlaying.Update(song.Title, song.Artist, song.Album, im)
|
||||
bp.NowPlaying.Update(song.Title, song.Artist, song.Album, im)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+33
-4
@@ -1,11 +1,14 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"supersonic/player"
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
)
|
||||
|
||||
type MainWindow struct {
|
||||
@@ -14,17 +17,43 @@ type MainWindow struct {
|
||||
BottomPanel *BottomPanel
|
||||
}
|
||||
|
||||
func NewMainWindow(app fyne.App, appName string, p *player.Player) MainWindow {
|
||||
func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App) MainWindow {
|
||||
m := MainWindow{
|
||||
Window: app.NewWindow(appName),
|
||||
BottomPanel: NewBottomPanel(p),
|
||||
Window: fyneApp.NewWindow(appName),
|
||||
BottomPanel: NewBottomPanel(app.Player),
|
||||
}
|
||||
m.BottomPanel.SetPlaybackManager(app.PlaybackManager)
|
||||
m.BottomPanel.ImageManager = app.ImageManager
|
||||
c := container.NewBorder(nil, m.BottomPanel, nil, nil, &layout.Spacer{})
|
||||
m.Window.SetContent(c)
|
||||
m.Window.Resize(fyne.NewSize(1000, 800))
|
||||
app.PlaybackManager.OnSongChange(func(song *subsonic.Child) {
|
||||
if song == nil {
|
||||
m.Window.SetTitle(appName)
|
||||
return
|
||||
}
|
||||
m.Window.SetTitle(song.Title)
|
||||
})
|
||||
app.ServerManager.OnServerConnected(func() {
|
||||
ag := NewAlbumGrid(app.LibraryManager.RecentlyAddedIter(), app.ImageManager.GetAlbumThumbnail)
|
||||
ag.OnPlayAlbum = func(albumID string) {
|
||||
_ = app.PlaybackManager.PlayAlbum(albumID)
|
||||
}
|
||||
m.Window.SetContent(container.NewBorder(nil, m.BottomPanel, nil, nil, ag))
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MainWindow) PromptForFirstServer(cb func(string, string, string, string)) {
|
||||
d := widgets.NewAddServerForm("Connect to Server")
|
||||
pop := widget.NewModalPopUp(d, m.Canvas())
|
||||
d.OnSubmit = func() {
|
||||
pop.Hide()
|
||||
cb(d.Nickname, d.Host, d.Username, d.Password)
|
||||
}
|
||||
pop.Show()
|
||||
}
|
||||
|
||||
func (m *MainWindow) Show() {
|
||||
m.Window.Show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user