Merge pull request #35 from dweymouth/develop
Add support for adding/removing tracks from playlists, creating new playlists
This commit is contained in:
@@ -4,25 +4,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
subsonic "github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AlbumIterator interface {
|
|
||||||
Next() *subsonic.AlbumID3
|
|
||||||
}
|
|
||||||
|
|
||||||
type LibraryManager struct {
|
|
||||||
PreCacheCoverFn func(string)
|
|
||||||
|
|
||||||
s *ServerManager
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewLibraryManager(s *ServerManager) *LibraryManager {
|
|
||||||
return &LibraryManager{
|
|
||||||
s: s,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type AlbumSortOrder string
|
type AlbumSortOrder string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package backend
|
||||||
|
|
||||||
|
import (
|
||||||
|
subsonic "github.com/dweymouth/go-subsonic/subsonic"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AlbumIterator interface {
|
||||||
|
Next() *subsonic.AlbumID3
|
||||||
|
}
|
||||||
|
|
||||||
|
type LibraryManager struct {
|
||||||
|
PreCacheCoverFn func(string)
|
||||||
|
|
||||||
|
s *ServerManager
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLibraryManager(s *ServerManager) *LibraryManager {
|
||||||
|
return &LibraryManager{
|
||||||
|
s: s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *LibraryManager) GetUserOwnedPlaylists() ([]*subsonic.Playlist, error) {
|
||||||
|
pl, err := l.s.Server.GetPlaylists(nil)
|
||||||
|
userPl := make([]*subsonic.Playlist, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, p := range pl {
|
||||||
|
if p.Owner == l.s.Server.User {
|
||||||
|
userPl = append(userPl, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return userPl, nil
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"supersonic/player"
|
"supersonic/player"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
subsonic "github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -157,6 +157,10 @@ func (p *PlaybackManager) PlayPlaylist(playlistID string, firstTrack int) error
|
|||||||
return p.player.PlayTrackAt(firstTrack)
|
return p.player.PlayTrackAt(firstTrack)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *PlaybackManager) PlayFromBeginning() error {
|
||||||
|
return p.player.PlayFromBeginning()
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PlaybackManager) checkScrobble(playDur time.Duration) {
|
func (p *PlaybackManager) checkScrobble(playDur time.Duration) {
|
||||||
if playDur.Seconds() < 0.1 || p.curTrackTime < 0.1 {
|
if playDur.Seconds() < 0.1 || p.curTrackTime < 0.1 {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package backend
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
subsonic "github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ go 1.19
|
|||||||
require (
|
require (
|
||||||
fyne.io/fyne/v2 v2.2.4
|
fyne.io/fyne/v2 v2.2.4
|
||||||
github.com/20after4/configdir v0.1.1
|
github.com/20after4/configdir v0.1.1
|
||||||
github.com/dweymouth/go-subsonic v0.0.0-20221214005741-bd8048fa1863
|
github.com/dweymouth/go-subsonic v0.0.0-20230210044542-537b9238299b
|
||||||
github.com/google/uuid v1.3.0
|
github.com/google/uuid v1.3.0
|
||||||
github.com/pelletier/go-toml v1.9.3
|
github.com/pelletier/go-toml v1.9.3
|
||||||
github.com/wildeyedskies/go-mpv v0.0.0-20221204042335-e8961dc66756
|
github.com/wildeyedskies/go-mpv v0.0.0-20221204042335-e8961dc66756
|
||||||
@@ -43,4 +43,4 @@ require (
|
|||||||
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
|
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
replace fyne.io/fyne/v2 v2.2.4 => github.com/dweymouth/fyne/v2 v2.2.5-0.20230119024415-238e09217d09
|
replace fyne.io/fyne/v2 v2.2.4 => github.com/dweymouth/fyne/v2 v2.2.5-0.20230207011038-d2ef06e09a93
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7h
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230119024415-238e09217d09 h1:huJvmT36/E7MsuAVILCK7VPFd0UiPQDpphn215e1rCo=
|
github.com/dweymouth/fyne/v2 v2.2.5-0.20230207011038-d2ef06e09a93 h1:4GGNszUwZhcneapbaBO+rbHtmCjKjZXHKPCqFXQPg4E=
|
||||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230119024415-238e09217d09/go.mod h1:MBoGuHzLLSXdQOWFAwWhIhYTEMp33zqtGCReSWhaQTA=
|
github.com/dweymouth/fyne/v2 v2.2.5-0.20230207011038-d2ef06e09a93/go.mod h1:MBoGuHzLLSXdQOWFAwWhIhYTEMp33zqtGCReSWhaQTA=
|
||||||
github.com/dweymouth/go-subsonic v0.0.0-20221214005741-bd8048fa1863 h1:bOWMpFJ9zY839T1EngQ5nxVCiMlatPtpGkg/yHK6szg=
|
github.com/dweymouth/go-subsonic v0.0.0-20230210044542-537b9238299b h1:8JbTKYDdQg6JKu7ZDbEaVbXxutc3pRF58yNvTVMBHec=
|
||||||
github.com/dweymouth/go-subsonic v0.0.0-20221214005741-bd8048fa1863/go.mod h1:fUez6NFiEJiQTZizZ1BThZr5GJXAbigzGYjEPNm4tdI=
|
github.com/dweymouth/go-subsonic v0.0.0-20230210044542-537b9238299b/go.mod h1:fUez6NFiEJiQTZizZ1BThZr5GJXAbigzGYjEPNm4tdI=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
|||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BottomPanel struct {
|
type BottomPanel struct {
|
||||||
|
|||||||
+45
-28
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
|
"supersonic/ui/controller"
|
||||||
"supersonic/ui/layouts"
|
"supersonic/ui/layouts"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
@@ -13,42 +14,68 @@ import (
|
|||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AlbumPage struct {
|
type AlbumPage struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
albumID string
|
albumPageState
|
||||||
sm *backend.ServerManager
|
|
||||||
im *backend.ImageManager
|
|
||||||
lm *backend.LibraryManager
|
|
||||||
nav func(Route)
|
|
||||||
header *AlbumPageHeader
|
header *AlbumPageHeader
|
||||||
tracklist *widgets.Tracklist
|
tracklist *widgets.Tracklist
|
||||||
nowPlayingID string
|
nowPlayingID string
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
popUpProvider util.PopUpProvider
|
|
||||||
|
|
||||||
OnPlayAlbum func(string, int)
|
OnPlayAlbum func(string, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type albumPageState struct {
|
||||||
|
albumID string
|
||||||
|
lm *backend.LibraryManager
|
||||||
|
pm *backend.PlaybackManager
|
||||||
|
im *backend.ImageManager
|
||||||
|
sm *backend.ServerManager
|
||||||
|
contr *controller.Controller
|
||||||
|
nav func(Route)
|
||||||
|
}
|
||||||
|
|
||||||
func NewAlbumPage(
|
func NewAlbumPage(
|
||||||
albumID string,
|
albumID string,
|
||||||
sm *backend.ServerManager,
|
sm *backend.ServerManager,
|
||||||
|
pm *backend.PlaybackManager,
|
||||||
lm *backend.LibraryManager,
|
lm *backend.LibraryManager,
|
||||||
im *backend.ImageManager,
|
im *backend.ImageManager,
|
||||||
popUpProvider util.PopUpProvider,
|
contr *controller.Controller,
|
||||||
nav func(Route),
|
nav func(Route),
|
||||||
) *AlbumPage {
|
) *AlbumPage {
|
||||||
a := &AlbumPage{albumID: albumID, sm: sm, lm: lm, im: im, nav: nav, popUpProvider: popUpProvider}
|
a := &AlbumPage{
|
||||||
|
albumPageState: albumPageState{
|
||||||
|
albumID: albumID,
|
||||||
|
sm: sm,
|
||||||
|
pm: pm,
|
||||||
|
lm: lm,
|
||||||
|
im: im,
|
||||||
|
nav: nav,
|
||||||
|
contr: contr,
|
||||||
|
},
|
||||||
|
}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.header = NewAlbumPageHeader(a)
|
a.header = NewAlbumPageHeader(a)
|
||||||
a.tracklist = widgets.NewTracklist(nil)
|
a.tracklist = widgets.NewTracklist(nil)
|
||||||
|
// connect tracklist actions
|
||||||
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
|
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
|
||||||
|
a.tracklist.OnAddToQueue = func(tracks []*subsonic.Child) { a.pm.LoadTracks(tracks, true) }
|
||||||
|
a.tracklist.OnPlaySelection = func(tracks []*subsonic.Child) {
|
||||||
|
a.pm.LoadTracks(tracks, false)
|
||||||
|
a.pm.PlayFromBeginning()
|
||||||
|
}
|
||||||
|
a.tracklist.OnAddToPlaylist = a.contr.DoAddTracksToPlaylistWorkflow
|
||||||
|
|
||||||
a.container = container.NewBorder(
|
a.container = container.NewBorder(
|
||||||
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
||||||
nil, nil, nil, container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadBottom: 15}, a.tracklist))
|
nil, nil, nil, container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadBottom: 15}, a.tracklist))
|
||||||
|
|
||||||
a.loadAsync()
|
a.loadAsync()
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
@@ -62,13 +89,8 @@ func (a *AlbumPage) SetPlayAlbumCallback(cb func(string, int)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AlbumPage) Save() SavedPage {
|
func (a *AlbumPage) Save() SavedPage {
|
||||||
return &savedAlbumPage{
|
s := a.albumPageState
|
||||||
albumID: a.albumID,
|
return &s
|
||||||
lm: a.lm,
|
|
||||||
im: a.im,
|
|
||||||
nav: a.nav,
|
|
||||||
popUpProvider: a.popUpProvider,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AlbumPage) Route() Route {
|
func (a *AlbumPage) Route() Route {
|
||||||
@@ -88,6 +110,10 @@ func (a *AlbumPage) Reload() {
|
|||||||
a.loadAsync()
|
a.loadAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AlbumPage) Tapped(*fyne.PointEvent) {
|
||||||
|
a.tracklist.UnselectAll()
|
||||||
|
}
|
||||||
|
|
||||||
func (a *AlbumPage) onPlayTrackAt(tracknum int) {
|
func (a *AlbumPage) onPlayTrackAt(tracknum int) {
|
||||||
if a.OnPlayAlbum != nil {
|
if a.OnPlayAlbum != nil {
|
||||||
a.OnPlayAlbum(a.albumID, tracknum)
|
a.OnPlayAlbum(a.albumID, tracknum)
|
||||||
@@ -217,22 +243,13 @@ func (a *AlbumPageHeader) showPopUpCover() {
|
|||||||
log.Printf("error getting full size album cover: %s", err.Error())
|
log.Printf("error getting full size album cover: %s", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
util.ShowPopUpImage(cover, a.page.popUpProvider)
|
a.page.contr.ShowPopUpImage(cover)
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatMiscLabelStr(a *subsonic.AlbumID3) string {
|
func formatMiscLabelStr(a *subsonic.AlbumID3) string {
|
||||||
return fmt.Sprintf("%d · %d tracks · %s", a.Year, a.SongCount, util.SecondsToTimeString(float64(a.Duration)))
|
return fmt.Sprintf("%d · %d tracks · %s", a.Year, a.SongCount, util.SecondsToTimeString(float64(a.Duration)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type savedAlbumPage struct {
|
func (s *albumPageState) Restore() Page {
|
||||||
albumID string
|
return NewAlbumPage(s.albumID, s.sm, s.pm, s.lm, s.im, s.contr, s.nav)
|
||||||
lm *backend.LibraryManager
|
|
||||||
im *backend.ImageManager
|
|
||||||
sm *backend.ServerManager
|
|
||||||
popUpProvider util.PopUpProvider
|
|
||||||
nav func(Route)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *savedAlbumPage) Restore() Page {
|
|
||||||
return NewAlbumPage(s.albumID, s.sm, s.lm, s.im, s.popUpProvider, s.nav)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+20
-29
@@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
"supersonic/res"
|
"supersonic/res"
|
||||||
|
"supersonic/ui/controller"
|
||||||
"supersonic/ui/layouts"
|
"supersonic/ui/layouts"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
@@ -16,35 +17,38 @@ import (
|
|||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ fyne.Widget = (*ArtistPage)(nil)
|
var _ fyne.Widget = (*ArtistPage)(nil)
|
||||||
|
|
||||||
|
type artistPageState struct {
|
||||||
|
artistID string
|
||||||
|
sm *backend.ServerManager
|
||||||
|
im *backend.ImageManager
|
||||||
|
nav func(Route)
|
||||||
|
contr *controller.Controller
|
||||||
|
}
|
||||||
|
|
||||||
type ArtistPage struct {
|
type ArtistPage struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
artistID string
|
artistPageState
|
||||||
im *backend.ImageManager
|
|
||||||
sm *backend.ServerManager
|
|
||||||
nav func(Route)
|
|
||||||
popUpProvider util.PopUpProvider
|
|
||||||
|
|
||||||
grid *widgets.AlbumGrid
|
|
||||||
header *ArtistPageHeader
|
header *ArtistPageHeader
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
|
|
||||||
OnPlayAlbum func(string, int)
|
OnPlayAlbum func(string, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewArtistPage(artistID string, sm *backend.ServerManager, im *backend.ImageManager, popUp util.PopUpProvider, nav func(Route)) *ArtistPage {
|
func NewArtistPage(artistID string, sm *backend.ServerManager, im *backend.ImageManager, contr *controller.Controller, nav func(Route)) *ArtistPage {
|
||||||
a := &ArtistPage{
|
a := &ArtistPage{artistPageState: artistPageState{
|
||||||
artistID: artistID,
|
artistID: artistID,
|
||||||
sm: sm,
|
sm: sm,
|
||||||
im: im,
|
im: im,
|
||||||
nav: nav,
|
nav: nav,
|
||||||
popUpProvider: popUp,
|
contr: contr,
|
||||||
}
|
}}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.header = NewArtistPageHeader(a, nav)
|
a.header = NewArtistPageHeader(a, nav)
|
||||||
a.container = container.NewBorder(
|
a.container = container.NewBorder(
|
||||||
@@ -67,13 +71,8 @@ func (a *ArtistPage) Reload() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistPage) Save() SavedPage {
|
func (a *ArtistPage) Save() SavedPage {
|
||||||
return &savedArtistPage{
|
s := a.artistPageState
|
||||||
artistID: a.artistID,
|
return &s
|
||||||
sm: a.sm,
|
|
||||||
im: a.im,
|
|
||||||
nav: a.nav,
|
|
||||||
popUpProvider: a.popUpProvider,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistPage) onPlayAlbum(albumID string) {
|
func (a *ArtistPage) onPlayAlbum(albumID string) {
|
||||||
@@ -112,16 +111,8 @@ func (a *ArtistPage) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
return widget.NewSimpleRenderer(a.container)
|
return widget.NewSimpleRenderer(a.container)
|
||||||
}
|
}
|
||||||
|
|
||||||
type savedArtistPage struct {
|
func (s *artistPageState) Restore() Page {
|
||||||
artistID string
|
return NewArtistPage(s.artistID, s.sm, s.im, s.contr, s.nav)
|
||||||
sm *backend.ServerManager
|
|
||||||
im *backend.ImageManager
|
|
||||||
nav func(Route)
|
|
||||||
popUpProvider util.PopUpProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *savedArtistPage) Restore() Page {
|
|
||||||
return NewArtistPage(s.artistID, s.sm, s.im, s.popUpProvider, s.nav)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ArtistPageHeader struct {
|
type ArtistPageHeader struct {
|
||||||
@@ -200,7 +191,7 @@ func (a *ArtistPageHeader) UpdateInfo(info *subsonic.ArtistInfo2) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
a.artistImage.OnTapped = func() {
|
a.artistImage.OnTapped = func() {
|
||||||
util.ShowPopUpImage(im, a.artistPage.popUpProvider)
|
a.artistPage.contr.ShowPopUpImage(im)
|
||||||
}
|
}
|
||||||
a.artistImage.SetImage(im, true /*tappable*/)
|
a.artistImage.SetImage(im, true /*tappable*/)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ fyne.Widget = (*ArtistPage)(nil)
|
var _ fyne.Widget = (*ArtistPage)(nil)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Page interface {
|
type Page interface {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FavoritesPage struct {
|
type FavoritesPage struct {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: there is a lot of code duplication between this and albumspage. Refactor?
|
// TODO: there is a lot of code duplication between this and albumspage. Refactor?
|
||||||
|
|||||||
+39
-24
@@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
"supersonic/res"
|
"supersonic/res"
|
||||||
|
"supersonic/ui/controller"
|
||||||
"supersonic/ui/layouts"
|
"supersonic/ui/layouts"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
@@ -13,36 +14,54 @@ import (
|
|||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlaylistPage struct {
|
type PlaylistPage struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
playlistID string
|
playlistPageState
|
||||||
sm *backend.ServerManager
|
|
||||||
pm *backend.PlaybackManager
|
|
||||||
im *backend.ImageManager
|
|
||||||
nav func(Route)
|
|
||||||
header *PlaylistPageHeader
|
header *PlaylistPageHeader
|
||||||
tracklist *widgets.Tracklist
|
tracklist *widgets.Tracklist
|
||||||
nowPlayingID string
|
nowPlayingID string
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type playlistPageState struct {
|
||||||
|
playlistID string
|
||||||
|
contr *controller.Controller
|
||||||
|
sm *backend.ServerManager
|
||||||
|
pm *backend.PlaybackManager
|
||||||
|
im *backend.ImageManager
|
||||||
|
nav func(Route)
|
||||||
|
}
|
||||||
|
|
||||||
func NewPlaylistPage(
|
func NewPlaylistPage(
|
||||||
playlistID string,
|
playlistID string,
|
||||||
|
contr *controller.Controller,
|
||||||
sm *backend.ServerManager,
|
sm *backend.ServerManager,
|
||||||
pm *backend.PlaybackManager,
|
pm *backend.PlaybackManager,
|
||||||
im *backend.ImageManager,
|
im *backend.ImageManager,
|
||||||
nav func(Route),
|
nav func(Route),
|
||||||
) *PlaylistPage {
|
) *PlaylistPage {
|
||||||
a := &PlaylistPage{playlistID: playlistID, sm: sm, pm: pm, im: im}
|
a := &PlaylistPage{playlistPageState: playlistPageState{playlistID: playlistID, contr: contr, sm: sm, pm: pm, im: im}}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.header = NewPlaylistPageHeader(a)
|
a.header = NewPlaylistPageHeader(a)
|
||||||
a.tracklist = widgets.NewTracklist(nil)
|
a.tracklist = widgets.NewTracklist(nil)
|
||||||
a.tracklist.AutoNumber = true
|
a.tracklist.AutoNumber = true
|
||||||
|
a.tracklist.AuxiliaryMenuItems = []*fyne.MenuItem{
|
||||||
|
fyne.NewMenuItem("Remove from playlist", a.onRemoveSelectedFromPlaylist),
|
||||||
|
}
|
||||||
|
// connect tracklist actions
|
||||||
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
|
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
|
||||||
|
a.tracklist.OnAddToQueue = func(tracks []*subsonic.Child) { a.pm.LoadTracks(tracks, true) }
|
||||||
|
a.tracklist.OnPlaySelection = func(tracks []*subsonic.Child) {
|
||||||
|
a.pm.LoadTracks(tracks, false)
|
||||||
|
a.pm.PlayFromBeginning()
|
||||||
|
}
|
||||||
|
a.tracklist.OnAddToPlaylist = a.contr.DoAddTracksToPlaylistWorkflow
|
||||||
|
|
||||||
a.container = container.NewBorder(
|
a.container = container.NewBorder(
|
||||||
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
||||||
nil, nil, nil, container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadBottom: 15}, a.tracklist))
|
nil, nil, nil, container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadBottom: 15}, a.tracklist))
|
||||||
@@ -55,13 +74,8 @@ func (a *PlaylistPage) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *PlaylistPage) Save() SavedPage {
|
func (a *PlaylistPage) Save() SavedPage {
|
||||||
return &savedPlaylistPage{
|
p := a.playlistPageState
|
||||||
playlistID: a.playlistID,
|
return &p
|
||||||
sm: a.sm,
|
|
||||||
pm: a.pm,
|
|
||||||
im: a.im,
|
|
||||||
nav: a.nav,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *PlaylistPage) Route() Route {
|
func (a *PlaylistPage) Route() Route {
|
||||||
@@ -81,6 +95,10 @@ func (a *PlaylistPage) Reload() {
|
|||||||
a.loadAsync()
|
a.loadAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *PlaylistPage) Tapped(*fyne.PointEvent) {
|
||||||
|
a.tracklist.UnselectAll()
|
||||||
|
}
|
||||||
|
|
||||||
func (a *PlaylistPage) onPlayTrackAt(tracknum int) {
|
func (a *PlaylistPage) onPlayTrackAt(tracknum int) {
|
||||||
a.pm.PlayPlaylist(a.playlistID, tracknum)
|
a.pm.PlayPlaylist(a.playlistID, tracknum)
|
||||||
}
|
}
|
||||||
@@ -99,6 +117,11 @@ func (a *PlaylistPage) loadAsync() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *PlaylistPage) onRemoveSelectedFromPlaylist() {
|
||||||
|
a.sm.Server.UpdatePlaylistTracks(a.playlistID, nil, a.tracklist.SelectedTrackIndexes())
|
||||||
|
go a.Reload()
|
||||||
|
}
|
||||||
|
|
||||||
type PlaylistPageHeader struct {
|
type PlaylistPageHeader struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
@@ -183,14 +206,6 @@ func (a *PlaylistPageHeader) formatPlaylistTrackTimeStr(p *subsonic.Playlist) st
|
|||||||
return fmt.Sprintf("%d tracks, %s", p.SongCount, util.SecondsToTimeString(float64(p.Duration)))
|
return fmt.Sprintf("%d tracks, %s", p.SongCount, util.SecondsToTimeString(float64(p.Duration)))
|
||||||
}
|
}
|
||||||
|
|
||||||
type savedPlaylistPage struct {
|
func (s *playlistPageState) Restore() Page {
|
||||||
playlistID string
|
return NewPlaylistPage(s.playlistID, s.contr, s.sm, s.pm, s.im, s.nav)
|
||||||
sm *backend.ServerManager
|
|
||||||
pm *backend.PlaybackManager
|
|
||||||
im *backend.ImageManager
|
|
||||||
nav func(Route)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *savedPlaylistPage) Restore() Page {
|
|
||||||
return NewPlaylistPage(s.playlistID, s.sm, s.pm, s.im, s.nav)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PlaylistsPage struct {
|
type PlaylistsPage struct {
|
||||||
|
|||||||
+7
-22
@@ -2,10 +2,8 @@ package browsing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
|
"supersonic/ui/controller"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
|
||||||
"fyne.io/fyne/v2/widget"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PageName int
|
type PageName int
|
||||||
@@ -69,42 +67,29 @@ type NavigationHandler interface {
|
|||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
App *backend.App
|
App *backend.App
|
||||||
MainWindow fyne.Window
|
Controller *controller.Controller
|
||||||
Nav NavigationHandler
|
Nav NavigationHandler
|
||||||
|
|
||||||
pop util.PopUpProvider
|
pop util.PopUpProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(app *backend.App, mainWindow fyne.Window, nav NavigationHandler) Router {
|
func NewRouter(app *backend.App, controller *controller.Controller, nav NavigationHandler) Router {
|
||||||
r := Router{
|
r := Router{
|
||||||
App: app,
|
App: app,
|
||||||
MainWindow: mainWindow,
|
Controller: controller,
|
||||||
Nav: nav,
|
Nav: nav,
|
||||||
}
|
}
|
||||||
r.pop = &popUpProvider{window: r.MainWindow}
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
type popUpProvider struct {
|
|
||||||
window fyne.Window
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *popUpProvider) CreatePopUp(obj fyne.CanvasObject) *widget.PopUp {
|
|
||||||
return widget.NewPopUp(obj, p.window.Canvas())
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *popUpProvider) WindowSize() fyne.Size {
|
|
||||||
return p.window.Canvas().Size()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r Router) CreatePage(rte Route) Page {
|
func (r Router) CreatePage(rte Route) Page {
|
||||||
switch rte.Page {
|
switch rte.Page {
|
||||||
case Album:
|
case Album:
|
||||||
return NewAlbumPage(rte.Arg, r.App.ServerManager, r.App.LibraryManager, r.App.ImageManager, r.pop, r.OpenRoute)
|
return NewAlbumPage(rte.Arg, r.App.ServerManager, r.App.PlaybackManager, r.App.LibraryManager, r.App.ImageManager, r.Controller, r.OpenRoute)
|
||||||
case Albums:
|
case Albums:
|
||||||
return NewAlbumsPage("Albums", rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
|
return NewAlbumsPage("Albums", rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
|
||||||
case Artist:
|
case Artist:
|
||||||
return NewArtistPage(rte.Arg, r.App.ServerManager, r.App.ImageManager, r.pop, r.OpenRoute)
|
return NewArtistPage(rte.Arg, r.App.ServerManager, r.App.ImageManager, r.Controller, r.OpenRoute)
|
||||||
case Artists:
|
case Artists:
|
||||||
return NewArtistsGenresPage(false, r.App.ServerManager, r.OpenRoute)
|
return NewArtistsGenresPage(false, r.App.ServerManager, r.OpenRoute)
|
||||||
case Favorites:
|
case Favorites:
|
||||||
@@ -114,7 +99,7 @@ func (r Router) CreatePage(rte Route) Page {
|
|||||||
case Genres:
|
case Genres:
|
||||||
return NewArtistsGenresPage(true, r.App.ServerManager, r.OpenRoute)
|
return NewArtistsGenresPage(true, r.App.ServerManager, r.OpenRoute)
|
||||||
case Playlist:
|
case Playlist:
|
||||||
return NewPlaylistPage(rte.Arg, r.App.ServerManager, r.App.PlaybackManager, r.App.ImageManager, r.OpenRoute)
|
return NewPlaylistPage(rte.Arg, r.Controller, r.App.ServerManager, r.App.PlaybackManager, r.App.ImageManager, r.OpenRoute)
|
||||||
case Playlists:
|
case Playlists:
|
||||||
return NewPlaylistsPage(r.App.ServerManager, r.OpenRoute)
|
return NewPlaylistsPage(r.App.ServerManager, r.OpenRoute)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
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(trackIDs []string) {
|
||||||
|
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()
|
||||||
|
if playlistChoice < 0 {
|
||||||
|
m.App.ServerManager.Server.CreatePlaylistWithTracks(
|
||||||
|
trackIDs, map[string]string{"name": newPlaylistName})
|
||||||
|
} else {
|
||||||
|
m.App.ServerManager.Server.UpdatePlaylistTracks(
|
||||||
|
pls[playlistChoice].ID, trackIDs, nil /*tracksToRemove*/)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pop.Show()
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package dialogs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/layout"
|
||||||
|
"fyne.io/fyne/v2/widget"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AddToPlaylistDialog struct {
|
||||||
|
widget.BaseWidget
|
||||||
|
|
||||||
|
OnCanceled func()
|
||||||
|
OnSubmit func(playlistChoice int, newPlaylistName string)
|
||||||
|
|
||||||
|
playlistSelect *widget.Select
|
||||||
|
newPlaylistLabel *widget.Label
|
||||||
|
newPlaylistName *widget.Entry
|
||||||
|
okBtn *widget.Button
|
||||||
|
|
||||||
|
container *fyne.Container
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ fyne.Widget = (*AddToPlaylistDialog)(nil)
|
||||||
|
|
||||||
|
func NewAddToPlaylistDialog(title string, existingPlaylistNames []string) *AddToPlaylistDialog {
|
||||||
|
a := &AddToPlaylistDialog{}
|
||||||
|
a.ExtendBaseWidget(a)
|
||||||
|
|
||||||
|
titleLabel := widget.NewLabel(title)
|
||||||
|
titleLabel.TextStyle.Bold = true
|
||||||
|
options := []string{"New playlist..."}
|
||||||
|
options = append(options, existingPlaylistNames...)
|
||||||
|
a.playlistSelect = widget.NewSelect(options, func(_ string) {
|
||||||
|
a.onSelectionChanged()
|
||||||
|
})
|
||||||
|
a.playlistSelect.PlaceHolder = "(Choose playlist)"
|
||||||
|
a.newPlaylistName = widget.NewEntry()
|
||||||
|
a.newPlaylistName.Hidden = true
|
||||||
|
a.newPlaylistName.OnChanged = func(text string) {
|
||||||
|
if len(text) > 0 {
|
||||||
|
a.okBtn.Enable()
|
||||||
|
} else {
|
||||||
|
a.okBtn.Disable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
a.newPlaylistLabel = widget.NewLabel("Name")
|
||||||
|
a.newPlaylistLabel.Hidden = true
|
||||||
|
|
||||||
|
a.okBtn = widget.NewButton("OK", a.onOK)
|
||||||
|
a.okBtn.Disable()
|
||||||
|
cancelBtn := widget.NewButton("Cancel", a.onCancel)
|
||||||
|
|
||||||
|
a.container = container.NewVBox(
|
||||||
|
container.NewHBox(layout.NewSpacer(), titleLabel, layout.NewSpacer()),
|
||||||
|
container.New(layout.NewFormLayout(),
|
||||||
|
widget.NewLabel("Playlist"),
|
||||||
|
a.playlistSelect,
|
||||||
|
a.newPlaylistLabel,
|
||||||
|
a.newPlaylistName),
|
||||||
|
widget.NewSeparator(),
|
||||||
|
container.NewHBox(layout.NewSpacer(), a.okBtn, cancelBtn))
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AddToPlaylistDialog) onOK() {
|
||||||
|
var newPlaylistName string
|
||||||
|
playlistChoice := -1
|
||||||
|
if sel := a.playlistSelect.SelectedIndex(); sel == 0 {
|
||||||
|
newPlaylistName = a.newPlaylistName.Text
|
||||||
|
} else {
|
||||||
|
playlistChoice = sel - 1
|
||||||
|
}
|
||||||
|
if a.OnSubmit != nil {
|
||||||
|
a.OnSubmit(playlistChoice, newPlaylistName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AddToPlaylistDialog) onSelectionChanged() {
|
||||||
|
if a.playlistSelect.SelectedIndex() == 0 {
|
||||||
|
a.newPlaylistName.Show()
|
||||||
|
a.newPlaylistLabel.Show()
|
||||||
|
if len(a.newPlaylistName.Text) == 0 {
|
||||||
|
a.okBtn.Disable()
|
||||||
|
} else {
|
||||||
|
a.okBtn.Enable()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
a.newPlaylistName.Hide()
|
||||||
|
a.newPlaylistLabel.Hide()
|
||||||
|
a.okBtn.Enable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AddToPlaylistDialog) onCancel() {
|
||||||
|
if a.OnCanceled != nil {
|
||||||
|
a.OnCanceled()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AddToPlaylistDialog) MinSize() fyne.Size {
|
||||||
|
a.ExtendBaseWidget(a)
|
||||||
|
return fyne.NewSize(300, a.container.MinSize().Height)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AddToPlaylistDialog) CreateRenderer() fyne.WidgetRenderer {
|
||||||
|
return widget.NewSimpleRenderer(a.container)
|
||||||
|
}
|
||||||
+13
-6
@@ -4,20 +4,22 @@ import (
|
|||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
"supersonic/res"
|
"supersonic/res"
|
||||||
"supersonic/ui/browsing"
|
"supersonic/ui/browsing"
|
||||||
|
"supersonic/ui/controller"
|
||||||
|
"supersonic/ui/os"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/driver/desktop"
|
"fyne.io/fyne/v2/driver/desktop"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ShortcutBack = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: AltModifier}
|
ShortcutBack = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: os.AltModifier}
|
||||||
ShortcutForward = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: AltModifier}
|
ShortcutForward = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: os.AltModifier}
|
||||||
ShortcutReload = desktop.CustomShortcut{KeyName: fyne.KeyR, Modifier: ControlModifier}
|
ShortcutReload = desktop.CustomShortcut{KeyName: fyne.KeyR, Modifier: os.ControlModifier}
|
||||||
ShortcutSearch = desktop.CustomShortcut{KeyName: fyne.KeyF, Modifier: ControlModifier}
|
ShortcutSearch = desktop.CustomShortcut{KeyName: fyne.KeyF, Modifier: os.ControlModifier}
|
||||||
)
|
)
|
||||||
|
|
||||||
type MainWindow struct {
|
type MainWindow struct {
|
||||||
@@ -25,6 +27,7 @@ type MainWindow struct {
|
|||||||
|
|
||||||
App *backend.App
|
App *backend.App
|
||||||
Router browsing.Router
|
Router browsing.Router
|
||||||
|
Controller *controller.Controller
|
||||||
BrowsingPane *browsing.BrowsingPane
|
BrowsingPane *browsing.BrowsingPane
|
||||||
BottomPanel *BottomPanel
|
BottomPanel *BottomPanel
|
||||||
|
|
||||||
@@ -42,7 +45,11 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App, size fyne
|
|||||||
BrowsingPane: browsing.NewBrowsingPane(app),
|
BrowsingPane: browsing.NewBrowsingPane(app),
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Router = browsing.NewRouter(app, m.Window, m.BrowsingPane)
|
m.Controller = &controller.Controller{
|
||||||
|
MainWindow: m.Window,
|
||||||
|
App: app,
|
||||||
|
}
|
||||||
|
m.Router = browsing.NewRouter(app, m.Controller, m.BrowsingPane)
|
||||||
m.BottomPanel = NewBottomPanel(app.Player, m.Router.OpenRoute)
|
m.BottomPanel = NewBottomPanel(app.Player, m.Router.OpenRoute)
|
||||||
m.BottomPanel.SetPlaybackManager(app.PlaybackManager)
|
m.BottomPanel.SetPlaybackManager(app.PlaybackManager)
|
||||||
m.BottomPanel.ImageManager = app.ImageManager
|
m.BottomPanel.ImageManager = app.ImageManager
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
//go:build darwin
|
//go:build darwin
|
||||||
|
|
||||||
package ui
|
package os
|
||||||
|
|
||||||
import "fyne.io/fyne/v2"
|
import (
|
||||||
|
"fyne.io/fyne/v2"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ControlModifier = fyne.KeyModifierSuper
|
ControlModifier = fyne.KeyModifierSuper
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
//go:build !darwin
|
//go:build !darwin
|
||||||
|
|
||||||
package ui
|
package os
|
||||||
|
|
||||||
import "fyne.io/fyne/v2"
|
import "fyne.io/fyne/v2"
|
||||||
|
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
type ListSelectionManager struct {
|
||||||
|
lastSelectedRow int
|
||||||
|
numSelected int
|
||||||
|
selected BitSet
|
||||||
|
len func() int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewListSelectionManager(lenFn func() int) ListSelectionManager {
|
||||||
|
return ListSelectionManager{lastSelectedRow: -1, len: lenFn}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the given row is not selected, reset the selection
|
||||||
|
// and select only the given row.
|
||||||
|
func (l *ListSelectionManager) Select(row int) {
|
||||||
|
if row < 0 || l.selected.IsSet(uint(row)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
l.UnselectAll()
|
||||||
|
l.selectAdd(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it is not selected, add the given row to the selection.
|
||||||
|
// If it is selected, unselet it.
|
||||||
|
func (l *ListSelectionManager) SelectAddOrRemove(row int) {
|
||||||
|
if row < 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if l.selected.IsSet(uint(row)) {
|
||||||
|
// find new last selected row
|
||||||
|
if row == l.lastSelectedRow {
|
||||||
|
for i := row - 1; i >= -1; i++ {
|
||||||
|
if i == -1 {
|
||||||
|
l.lastSelectedRow = i
|
||||||
|
} else if l.selected.IsSet(uint(i)) {
|
||||||
|
l.lastSelectedRow = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l.selected.Unset(uint(row))
|
||||||
|
l.numSelected -= 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l.selectAdd(row)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListSelectionManager) selectAdd(row int) {
|
||||||
|
l.numSelected += 1
|
||||||
|
l.selected.Set(uint(row))
|
||||||
|
if row > l.lastSelectedRow {
|
||||||
|
l.lastSelectedRow = row
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select a range between the given row and the furthest-down
|
||||||
|
// row that is currently selected (which may be above the given row)
|
||||||
|
// Note: this is modeled after what, as far as I can tell, is Gmail's selection behavior
|
||||||
|
func (l *ListSelectionManager) SelectRange(row int) {
|
||||||
|
if row < 0 || l.selected.IsSet(uint(row)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if l.numSelected == 0 {
|
||||||
|
l.selectAdd(row)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m := maxInt(row, l.lastSelectedRow)
|
||||||
|
for i := minInt(l.lastSelectedRow, row); i <= m; i++ {
|
||||||
|
l.selectAdd(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListSelectionManager) SelectAll() {
|
||||||
|
for i := 0; i < l.len(); i++ {
|
||||||
|
l.selectAdd(i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListSelectionManager) UnselectAll() {
|
||||||
|
l.selected = nil
|
||||||
|
l.numSelected = 0
|
||||||
|
l.lastSelectedRow = -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListSelectionManager) IsSelected(row int) bool {
|
||||||
|
return row >= 0 && l.selected.IsSet(uint(row))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListSelectionManager) GetSelection() []int {
|
||||||
|
var sel []int
|
||||||
|
for i := 0; i < l.len(); i++ {
|
||||||
|
if l.selected.IsSet(uint(i)) {
|
||||||
|
sel = append(sel, i)
|
||||||
|
}
|
||||||
|
if len(sel) == l.numSelected {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ListSelectionManager) AreAllSelected() bool {
|
||||||
|
return l.numSelected == l.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
func minInt(a, b int) int {
|
||||||
|
if a < b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func maxInt(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitSet implementation from
|
||||||
|
// https://stackoverflow.com/questions/2311373/how-to-implement-bitset-with-go
|
||||||
|
|
||||||
|
const uint64size = 64
|
||||||
|
|
||||||
|
// BitSet is a set of bits that can be set, cleared and queried.
|
||||||
|
type BitSet []uint64
|
||||||
|
|
||||||
|
// Set ensures that the given bit is set in the BitSet.
|
||||||
|
func (s *BitSet) Set(i uint) {
|
||||||
|
if len(*s) < int(i/uint64size+1) {
|
||||||
|
r := make([]uint64, i/uint64size+1)
|
||||||
|
copy(r, *s)
|
||||||
|
*s = r
|
||||||
|
}
|
||||||
|
(*s)[i/uint64size] |= 1 << (i % uint64size)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unset ensures that the given bit is cleared (not set) in the BitSet.
|
||||||
|
func (s *BitSet) Unset(i uint) {
|
||||||
|
if len(*s) >= int(i/uint64size+1) {
|
||||||
|
(*s)[i/uint64size] &^= 1 << (i % uint64size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsSet returns true if the given bit is set, false if it is cleared.
|
||||||
|
func (s *BitSet) IsSet(i uint) bool {
|
||||||
|
idx := i / uint64size
|
||||||
|
if idx >= uint(len(*s)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return (*s)[i/uint64size]&(1<<(i%uint64size)) != 0
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/canvas"
|
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
)
|
)
|
||||||
@@ -33,27 +32,6 @@ type PopUpProvider interface {
|
|||||||
WindowSize() fyne.Size
|
WindowSize() fyne.Size
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowPopUpImage(img image.Image, popUpProvider PopUpProvider) {
|
|
||||||
im := canvas.NewImageFromImage(img)
|
|
||||||
im.FillMode = canvas.ImageFillContain
|
|
||||||
pop := popUpProvider.CreatePopUp(im)
|
|
||||||
s := popUpProvider.WindowSize()
|
|
||||||
var popS fyne.Size
|
|
||||||
if asp := 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,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
func RichTextSegsFromHTMLString(s string) []widget.RichTextSegment {
|
func RichTextSegsFromHTMLString(s string) []widget.RichTextSegment {
|
||||||
tokr := html.NewTokenizer(strings.NewReader(s))
|
tokr := html.NewTokenizer(strings.NewReader(s))
|
||||||
var segs []widget.RichTextSegment
|
var segs []widget.RichTextSegment
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
"fyne.io/fyne/v2/driver/desktop"
|
"fyne.io/fyne/v2/driver/desktop"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ fyne.Widget = (*AlbumCard)(nil)
|
var _ fyne.Widget = (*AlbumCard)(nil)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
const albumFetchBatchSize = 6
|
const albumFetchBatchSize = 6
|
||||||
|
|||||||
+131
-17
@@ -3,33 +3,41 @@ package widgets
|
|||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"supersonic/ui/layouts"
|
"supersonic/ui/layouts"
|
||||||
|
"supersonic/ui/os"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
|
"time"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
|
"fyne.io/fyne/v2/canvas"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
|
"fyne.io/fyne/v2/driver/desktop"
|
||||||
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
"github.com/dweymouth/go-subsonic"
|
"github.com/dweymouth/go-subsonic/subsonic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TrackRow struct {
|
type TrackRow struct {
|
||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
|
// internal state
|
||||||
|
trackIdx int
|
||||||
trackID string
|
trackID string
|
||||||
prevTrackID string
|
isPlaying bool
|
||||||
prevIsPlaying bool
|
tappedAt int64 // unixMillis
|
||||||
|
|
||||||
num *widget.RichText
|
num *widget.RichText
|
||||||
name *widget.RichText
|
name *widget.RichText
|
||||||
artist *widget.RichText
|
artist *widget.RichText
|
||||||
dur *widget.RichText
|
dur *widget.RichText
|
||||||
|
|
||||||
|
OnTapped func()
|
||||||
OnDoubleTapped func()
|
OnDoubleTapped func()
|
||||||
|
OnTappedSecondary func(e *fyne.PointEvent, trackIdx int)
|
||||||
|
|
||||||
|
selectionRect *canvas.Rectangle
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ fyne.DoubleTappable = (*TrackRow)(nil)
|
|
||||||
|
|
||||||
func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
||||||
t := &TrackRow{}
|
t := &TrackRow{}
|
||||||
t.ExtendBaseWidget(t)
|
t.ExtendBaseWidget(t)
|
||||||
@@ -42,17 +50,19 @@ func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
|||||||
t.dur = widget.NewRichTextWithText("")
|
t.dur = widget.NewRichTextWithText("")
|
||||||
t.dur.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignTrailing
|
t.dur.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignTrailing
|
||||||
|
|
||||||
t.container = container.New(layout,
|
t.selectionRect = canvas.NewRectangle(theme.SelectionColor())
|
||||||
t.num, t.name, t.artist, t.dur)
|
t.selectionRect.Hidden = true
|
||||||
|
t.container = container.NewMax(t.selectionRect,
|
||||||
|
container.New(layout,
|
||||||
|
t.num, t.name, t.artist, t.dur))
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
||||||
if tr.ID == t.prevTrackID && isPlaying == t.prevIsPlaying {
|
if tr.ID == t.trackID && isPlaying == t.isPlaying {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.prevTrackID = t.trackID
|
t.isPlaying = isPlaying
|
||||||
t.prevIsPlaying = isPlaying
|
|
||||||
t.trackID = tr.ID
|
t.trackID = tr.ID
|
||||||
|
|
||||||
if rowNum < 0 {
|
if rowNum < 0 {
|
||||||
@@ -75,10 +85,26 @@ func (t *TrackRow) CreateRenderer() fyne.WidgetRenderer {
|
|||||||
return widget.NewSimpleRenderer(t.container)
|
return widget.NewSimpleRenderer(t.container)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackRow) DoubleTapped(*fyne.PointEvent) {
|
// We implement our own double tapping so that the Tapped behavior
|
||||||
|
// can be triggered instantly.
|
||||||
|
func (t *TrackRow) Tapped(*fyne.PointEvent) {
|
||||||
|
prevTap := t.tappedAt
|
||||||
|
t.tappedAt = time.Now().UnixMilli()
|
||||||
|
if t.tappedAt-prevTap < 300 {
|
||||||
if t.OnDoubleTapped != nil {
|
if t.OnDoubleTapped != nil {
|
||||||
t.OnDoubleTapped()
|
t.OnDoubleTapped()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if t.OnTapped != nil {
|
||||||
|
t.OnTapped()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *TrackRow) TappedSecondary(e *fyne.PointEvent) {
|
||||||
|
if t.OnTappedSecondary != nil {
|
||||||
|
t.OnTappedSecondary(e, t.trackIdx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tracklist struct {
|
type Tracklist struct {
|
||||||
@@ -86,29 +112,46 @@ type Tracklist struct {
|
|||||||
|
|
||||||
Tracks []*subsonic.Child
|
Tracks []*subsonic.Child
|
||||||
AutoNumber bool
|
AutoNumber bool
|
||||||
OnPlayTrackAt func(int)
|
// must be set before the context menu is shown for the first time
|
||||||
|
AuxiliaryMenuItems []*fyne.MenuItem
|
||||||
|
|
||||||
|
// user action callbacks
|
||||||
|
OnPlayTrackAt func(int)
|
||||||
|
OnPlaySelection func(tracks []*subsonic.Child)
|
||||||
|
OnAddToQueue func(trackIDs []*subsonic.Child)
|
||||||
|
OnAddToPlaylist func(trackIDs []string)
|
||||||
|
|
||||||
|
selectionMgr util.ListSelectionManager
|
||||||
nowPlayingIdx int
|
nowPlayingIdx int
|
||||||
colLayout *layouts.ColumnsLayout
|
colLayout *layouts.ColumnsLayout
|
||||||
hdr *ListHeader
|
hdr *ListHeader
|
||||||
list *widget.List
|
list *widget.List
|
||||||
|
ctxMenu *fyne.Menu
|
||||||
container *fyne.Container
|
container *fyne.Container
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
||||||
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
|
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
|
||||||
t.ExtendBaseWidget(t)
|
t.ExtendBaseWidget(t)
|
||||||
|
t.selectionMgr = util.NewListSelectionManager(func() int { return len(t.Tracks) })
|
||||||
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, 60})
|
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, 60})
|
||||||
t.hdr = NewListHeader([]ListColumn{{"#", true}, {"Title", false}, {"Artist", false}, {"Time", true}}, t.colLayout)
|
t.hdr = NewListHeader([]ListColumn{{"#", true}, {"Title", false}, {"Artist", false}, {"Time", true}}, t.colLayout)
|
||||||
t.list = widget.NewList(
|
t.list = widget.NewList(
|
||||||
func() int { return len(t.Tracks) },
|
func() int { return len(t.Tracks) },
|
||||||
func() fyne.CanvasObject { return NewTrackRow(t.colLayout) },
|
func() fyne.CanvasObject {
|
||||||
|
tr := NewTrackRow(t.colLayout)
|
||||||
|
tr.OnTapped = func() { t.onSelectTrack(tr.trackIdx) }
|
||||||
|
tr.OnTappedSecondary = t.onShowContextMenu
|
||||||
|
tr.OnDoubleTapped = func() { t.onPlayTrackAt(tr.trackIdx) }
|
||||||
|
return tr
|
||||||
|
},
|
||||||
func(itemID widget.ListItemID, item fyne.CanvasObject) {
|
func(itemID widget.ListItemID, item fyne.CanvasObject) {
|
||||||
tr := item.(*TrackRow)
|
tr := item.(*TrackRow)
|
||||||
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
|
tr.trackIdx = itemID
|
||||||
i := itemID + 1
|
tr.selectionRect.Hidden = !t.selectionMgr.IsSelected(itemID)
|
||||||
if !t.AutoNumber {
|
i := -1 // signal that we want to display the actual track num.
|
||||||
i = -1 // signal that we want to use the track num.
|
if t.AutoNumber {
|
||||||
|
i = itemID + 1
|
||||||
}
|
}
|
||||||
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx, i)
|
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx, i)
|
||||||
})
|
})
|
||||||
@@ -127,6 +170,11 @@ func (t *Tracklist) SetNowPlaying(trackID string) {
|
|||||||
t.list.Refresh()
|
t.list.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) UnselectAll() {
|
||||||
|
t.selectionMgr.UnselectAll()
|
||||||
|
t.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(t.container)
|
return widget.NewSimpleRenderer(t.container)
|
||||||
}
|
}
|
||||||
@@ -136,3 +184,69 @@ func (t *Tracklist) onPlayTrackAt(idx int) {
|
|||||||
t.OnPlayTrackAt(idx)
|
t.OnPlayTrackAt(idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) onSelectTrack(idx int) {
|
||||||
|
if d, ok := fyne.CurrentApp().Driver().(desktop.Driver); ok {
|
||||||
|
if d.ActiveKeyModifiers()&os.ControlModifier != 0 {
|
||||||
|
t.selectionMgr.SelectAddOrRemove(idx)
|
||||||
|
} else if (d.ActiveKeyModifiers() & fyne.KeyModifierShift) != 0 {
|
||||||
|
t.selectionMgr.SelectRange(idx)
|
||||||
|
} else {
|
||||||
|
t.selectionMgr.Select(idx)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.selectionMgr.Select(idx)
|
||||||
|
}
|
||||||
|
t.list.Refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) onShowContextMenu(e *fyne.PointEvent, trackIdx int) {
|
||||||
|
t.selectionMgr.Select(trackIdx)
|
||||||
|
t.Refresh()
|
||||||
|
if t.ctxMenu == nil {
|
||||||
|
t.ctxMenu = fyne.NewMenu("",
|
||||||
|
fyne.NewMenuItem("Play", func() {
|
||||||
|
if t.OnPlaySelection != nil {
|
||||||
|
t.OnPlaySelection(t.selectedTracks())
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
fyne.NewMenuItem("Add to queue", func() {
|
||||||
|
if t.OnPlaySelection != nil {
|
||||||
|
t.OnAddToQueue(t.selectedTracks())
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
fyne.NewMenuItem("Add to playlist...", func() {
|
||||||
|
if t.OnAddToPlaylist != nil {
|
||||||
|
t.OnAddToPlaylist(t.selectedTrackIDs())
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
if len(t.AuxiliaryMenuItems) > 0 {
|
||||||
|
t.ctxMenu.Items = append(t.ctxMenu.Items, fyne.NewMenuItemSeparator())
|
||||||
|
t.ctxMenu.Items = append(t.ctxMenu.Items, t.AuxiliaryMenuItems...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
widget.ShowPopUpMenuAtPosition(t.ctxMenu, fyne.CurrentApp().Driver().CanvasForObject(t), e.AbsolutePosition)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) selectedTracks() []*subsonic.Child {
|
||||||
|
sel := t.selectionMgr.GetSelection()
|
||||||
|
tracks := make([]*subsonic.Child, 0, len(sel))
|
||||||
|
for _, idx := range sel {
|
||||||
|
tracks = append(tracks, t.Tracks[idx])
|
||||||
|
}
|
||||||
|
return tracks
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) selectedTrackIDs() []string {
|
||||||
|
sel := t.selectionMgr.GetSelection()
|
||||||
|
tracks := make([]string, 0, len(sel))
|
||||||
|
for _, idx := range sel {
|
||||||
|
tracks = append(tracks, t.Tracks[idx].ID)
|
||||||
|
}
|
||||||
|
return tracks
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) SelectedTrackIndexes() []int {
|
||||||
|
return t.selectionMgr.GetSelection()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user