ui refactoring (create controller pkg) + beginning of add to playlist
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"image"
|
||||
"log"
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/dialogs"
|
||||
"supersonic/ui/util"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
)
|
||||
|
||||
type Controller struct {
|
||||
MainWindow fyne.Window
|
||||
App *backend.App
|
||||
}
|
||||
|
||||
func (m *Controller) ShowPopUpImage(img image.Image) {
|
||||
im := canvas.NewImageFromImage(img)
|
||||
im.FillMode = canvas.ImageFillContain
|
||||
pop := widget.NewPopUp(im, m.MainWindow.Canvas())
|
||||
s := m.MainWindow.Canvas().Size()
|
||||
var popS fyne.Size
|
||||
if asp := util.ImageAspect(img); s.Width/s.Height > asp {
|
||||
// window height is limiting factor
|
||||
h := s.Height * 0.8
|
||||
popS = fyne.NewSize(h*asp, h)
|
||||
} else {
|
||||
w := s.Width * 0.8
|
||||
popS = fyne.NewSize(w, w*(1/asp))
|
||||
}
|
||||
pop.Resize(popS)
|
||||
pop.ShowAtPosition(fyne.NewPos(
|
||||
(s.Width-popS.Width)/2,
|
||||
(s.Height-popS.Height)/2,
|
||||
))
|
||||
}
|
||||
|
||||
// Show dialog to prompt for playlist.
|
||||
// Depending on the results of that dialog, potentially create a new playlist
|
||||
// Add tracks to the user-specified playlist
|
||||
func (m *Controller) DoAddTracksToPlaylistWorkflow(tracks []*subsonic.Child) {
|
||||
pls, err := m.App.LibraryManager.GetUserOwnedPlaylists()
|
||||
if err != nil {
|
||||
// TODO: surface this error to user
|
||||
log.Printf("error getting user-owned playlists: %s", err.Error())
|
||||
return
|
||||
}
|
||||
plNames := make([]string, 0, len(pls))
|
||||
for _, pl := range pls {
|
||||
plNames = append(plNames, pl.Name)
|
||||
}
|
||||
|
||||
dlg := dialogs.NewAddToPlaylistDialog("Add to Playlist", plNames)
|
||||
pop := widget.NewModalPopUp(dlg, m.MainWindow.Canvas())
|
||||
dlg.OnCanceled = pop.Hide
|
||||
dlg.OnSubmit = func(playlistChoice int, newPlaylistName string) {
|
||||
pop.Hide()
|
||||
// call server to add tracks to playlist
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user