add 'New Playlist' button to Playlists page
This commit is contained in:
@@ -36,6 +36,7 @@ type PlaylistsPage struct {
|
||||
searchedPlaylists []*mediaprovider.Playlist
|
||||
|
||||
viewToggle *widgets.ToggleButtonGroup
|
||||
newBtn *widget.Button
|
||||
searcher *widgets.SearchEntry
|
||||
titleDisp *widget.RichText
|
||||
container *fyne.Container
|
||||
@@ -86,6 +87,9 @@ func newPlaylistsPage(
|
||||
widget.NewButtonWithIcon("", theme.NewThemedResource(res.ResListSvg), a.showListView),
|
||||
widget.NewButtonWithIcon("", theme.NewThemedResource(res.ResGridSvg), a.showGridView))
|
||||
a.viewToggle.SetActivatedButton(activeView)
|
||||
a.newBtn = widget.NewButtonWithIcon(lang.L("New Playlist"), theme.ContentAddIcon(), func() {
|
||||
a.contr.DoCreatePlaylistWorkflow()
|
||||
})
|
||||
if activeView == 0 {
|
||||
a.createListView()
|
||||
a.buildContainer(a.listView)
|
||||
@@ -98,6 +102,21 @@ func newPlaylistsPage(
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *PlaylistsPage) buildContainer(initialView fyne.CanvasObject) {
|
||||
searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
|
||||
a.container = container.New(&layout.CustomPaddedLayout{LeftPadding: 15, RightPadding: 15, TopPadding: 5, BottomPadding: 15},
|
||||
container.NewBorder(
|
||||
container.NewHBox(
|
||||
a.titleDisp,
|
||||
container.NewCenter(a.viewToggle),
|
||||
util.NewHSpace(2),
|
||||
container.NewCenter(a.newBtn),
|
||||
layout.NewSpacer(),
|
||||
searchVbox,
|
||||
),
|
||||
nil, nil, nil, initialView))
|
||||
}
|
||||
|
||||
var _ Scrollable = (*PlaylistsPage)(nil)
|
||||
|
||||
func (p *PlaylistsPage) Scroll(scrollAmt float32) {
|
||||
@@ -317,14 +336,6 @@ func (s *savedPlaylistsPage) Restore() Page {
|
||||
return newPlaylistsPage(s.contr, s.pool, s.cfg, s.mp, s.searchText, s.activeView, s.listSort, s.listScrollPos, s.gridScrollPos)
|
||||
}
|
||||
|
||||
func (a *PlaylistsPage) buildContainer(initialView fyne.CanvasObject) {
|
||||
searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
|
||||
a.container = container.New(&layout.CustomPaddedLayout{LeftPadding: 15, RightPadding: 15, TopPadding: 5, BottomPadding: 15},
|
||||
container.NewBorder(
|
||||
container.NewHBox(a.titleDisp, container.NewCenter(a.viewToggle), layout.NewSpacer(), searchVbox),
|
||||
nil, nil, nil, initialView))
|
||||
}
|
||||
|
||||
func (a *PlaylistsPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
m.App.Config.Application.AddToPlaylistSkipDuplicates = sp.SkipDuplicates
|
||||
if id == "" /* creating new playlist */ {
|
||||
go func() {
|
||||
err := m.App.ServerManager.Server.CreatePlaylist(sp.SearchDialog.SearchQuery(), trackIDs)
|
||||
err := m.App.ServerManager.Server.CreatePlaylistWithTracks(sp.SearchDialog.SearchQuery(), trackIDs)
|
||||
if err == nil {
|
||||
notifySuccess(len(trackIDs))
|
||||
} else {
|
||||
@@ -132,8 +132,13 @@ func (m *Controller) DoEditPlaylistWorkflow(playlist *mediaprovider.Playlist) {
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
go func() {
|
||||
err := m.App.ServerManager.Server.EditPlaylist(playlist.ID, dlg.Name, dlg.Description, dlg.IsPublic)
|
||||
s := m.App.ServerManager.GetServer()
|
||||
if s == nil {
|
||||
return // logged out
|
||||
}
|
||||
err := s.EditPlaylist(playlist.ID, dlg.Name, dlg.Description, dlg.IsPublic)
|
||||
if err != nil {
|
||||
fyne.Do(func() { m.ToastProvider.ShowErrorToast(lang.L("Error updating playlist")) })
|
||||
log.Printf("error updating playlist: %s", err.Error())
|
||||
} else if rte := m.CurPageFunc(); rte.Page == Playlist && rte.Arg == playlist.ID {
|
||||
// if user is on playlist page, reload to get the updates
|
||||
@@ -144,3 +149,33 @@ func (m *Controller) DoEditPlaylistWorkflow(playlist *mediaprovider.Playlist) {
|
||||
m.haveModal = true
|
||||
pop.Show()
|
||||
}
|
||||
|
||||
func (m *Controller) DoCreatePlaylistWorkflow() {
|
||||
canMakePublic := m.App.ServerManager.Server.CanMakePublicPlaylist()
|
||||
dlg := dialogs.NewCreatePlaylistDialog(canMakePublic)
|
||||
pop := widget.NewModalPopUp(dlg, m.MainWindow.Canvas())
|
||||
m.ClosePopUpOnEscape(pop)
|
||||
dlg.OnCanceled = func() {
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
}
|
||||
dlg.OnUpdateMetadata = func() {
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
go func() {
|
||||
s := m.App.ServerManager.GetServer()
|
||||
if s == nil {
|
||||
return // logged out
|
||||
}
|
||||
err := s.CreatePlaylist(dlg.Name, dlg.Description, dlg.IsPublic)
|
||||
if err != nil {
|
||||
fyne.Do(func() { m.ToastProvider.ShowErrorToast(lang.L("Error creating playlist")) })
|
||||
log.Printf("error creating playlist: %s", err.Error())
|
||||
} else {
|
||||
fyne.Do(func() { m.ToastProvider.ShowSuccessToast(lang.L("Successfully created playlist")) })
|
||||
}
|
||||
}()
|
||||
}
|
||||
m.haveModal = true
|
||||
pop.Show()
|
||||
}
|
||||
|
||||
@@ -26,10 +26,19 @@ type EditPlaylistDialog struct {
|
||||
}
|
||||
|
||||
func NewEditPlaylistDialog(playlist *mediaprovider.Playlist, showPublicCheck bool) *EditPlaylistDialog {
|
||||
e := &EditPlaylistDialog{
|
||||
IsPublic: playlist.Public,
|
||||
Name: playlist.Name,
|
||||
Description: playlist.Description,
|
||||
return newEditPlaylistDialog(playlist, showPublicCheck)
|
||||
}
|
||||
|
||||
func NewCreatePlaylistDialog(showPublicCheck bool) *EditPlaylistDialog {
|
||||
return newEditPlaylistDialog(nil, showPublicCheck)
|
||||
}
|
||||
|
||||
func newEditPlaylistDialog(playlist *mediaprovider.Playlist, showPublicCheck bool) *EditPlaylistDialog {
|
||||
e := &EditPlaylistDialog{}
|
||||
if playlist != nil {
|
||||
e.IsPublic = playlist.Public
|
||||
e.Name = playlist.Name
|
||||
e.Description = playlist.Description
|
||||
}
|
||||
e.ExtendBaseWidget(e)
|
||||
|
||||
@@ -42,6 +51,7 @@ func NewEditPlaylistDialog(playlist *mediaprovider.Playlist, showPublicCheck boo
|
||||
e.OnDeletePlaylist()
|
||||
}
|
||||
})
|
||||
deleteBtn.Hidden = playlist == nil
|
||||
submitBtn := widget.NewButtonWithIcon(lang.L("OK"), theme.ConfirmIcon(), func() {
|
||||
if e.OnUpdateMetadata != nil {
|
||||
e.OnUpdateMetadata()
|
||||
|
||||
Reference in New Issue
Block a user