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"
|
||||
"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
|
||||
|
||||
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"
|
||||
"time"
|
||||
|
||||
subsonic "github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -157,6 +157,10 @@ func (p *PlaybackManager) PlayPlaylist(playlistID string, firstTrack int) error
|
||||
return p.player.PlayTrackAt(firstTrack)
|
||||
}
|
||||
|
||||
func (p *PlaybackManager) PlayFromBeginning() error {
|
||||
return p.player.PlayFromBeginning()
|
||||
}
|
||||
|
||||
func (p *PlaybackManager) checkScrobble(playDur time.Duration) {
|
||||
if playDur.Seconds() < 0.1 || p.curTrackTime < 0.1 {
|
||||
return
|
||||
|
||||
@@ -3,7 +3,7 @@ package backend
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
subsonic "github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ go 1.19
|
||||
require (
|
||||
fyne.io/fyne/v2 v2.2.4
|
||||
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/pelletier/go-toml v1.9.3
|
||||
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
|
||||
)
|
||||
|
||||
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
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.20230119024415-238e09217d09/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-20221214005741-bd8048fa1863/go.mod h1:fUez6NFiEJiQTZizZ1BThZr5GJXAbigzGYjEPNm4tdI=
|
||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230207011038-d2ef06e09a93 h1:4GGNszUwZhcneapbaBO+rbHtmCjKjZXHKPCqFXQPg4E=
|
||||
github.com/dweymouth/fyne/v2 v2.2.5-0.20230207011038-d2ef06e09a93/go.mod h1:MBoGuHzLLSXdQOWFAwWhIhYTEMp33zqtGCReSWhaQTA=
|
||||
github.com/dweymouth/go-subsonic v0.0.0-20230210044542-537b9238299b h1:8JbTKYDdQg6JKu7ZDbEaVbXxutc3pRF58yNvTVMBHec=
|
||||
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.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
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/container"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type BottomPanel struct {
|
||||
|
||||
+49
-32
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/controller"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/util"
|
||||
"supersonic/ui/widgets"
|
||||
@@ -13,42 +14,68 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type AlbumPage struct {
|
||||
widget.BaseWidget
|
||||
|
||||
albumID string
|
||||
sm *backend.ServerManager
|
||||
im *backend.ImageManager
|
||||
lm *backend.LibraryManager
|
||||
nav func(Route)
|
||||
header *AlbumPageHeader
|
||||
tracklist *widgets.Tracklist
|
||||
nowPlayingID string
|
||||
container *fyne.Container
|
||||
popUpProvider util.PopUpProvider
|
||||
albumPageState
|
||||
|
||||
header *AlbumPageHeader
|
||||
tracklist *widgets.Tracklist
|
||||
nowPlayingID string
|
||||
container *fyne.Container
|
||||
|
||||
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(
|
||||
albumID string,
|
||||
sm *backend.ServerManager,
|
||||
pm *backend.PlaybackManager,
|
||||
lm *backend.LibraryManager,
|
||||
im *backend.ImageManager,
|
||||
popUpProvider util.PopUpProvider,
|
||||
contr *controller.Controller,
|
||||
nav func(Route),
|
||||
) *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.header = NewAlbumPageHeader(a)
|
||||
a.tracklist = widgets.NewTracklist(nil)
|
||||
// connect tracklist actions
|
||||
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(
|
||||
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))
|
||||
|
||||
a.loadAsync()
|
||||
return a
|
||||
}
|
||||
@@ -62,13 +89,8 @@ func (a *AlbumPage) SetPlayAlbumCallback(cb func(string, int)) {
|
||||
}
|
||||
|
||||
func (a *AlbumPage) Save() SavedPage {
|
||||
return &savedAlbumPage{
|
||||
albumID: a.albumID,
|
||||
lm: a.lm,
|
||||
im: a.im,
|
||||
nav: a.nav,
|
||||
popUpProvider: a.popUpProvider,
|
||||
}
|
||||
s := a.albumPageState
|
||||
return &s
|
||||
}
|
||||
|
||||
func (a *AlbumPage) Route() Route {
|
||||
@@ -88,6 +110,10 @@ func (a *AlbumPage) Reload() {
|
||||
a.loadAsync()
|
||||
}
|
||||
|
||||
func (a *AlbumPage) Tapped(*fyne.PointEvent) {
|
||||
a.tracklist.UnselectAll()
|
||||
}
|
||||
|
||||
func (a *AlbumPage) onPlayTrackAt(tracknum int) {
|
||||
if a.OnPlayAlbum != nil {
|
||||
a.OnPlayAlbum(a.albumID, tracknum)
|
||||
@@ -217,22 +243,13 @@ func (a *AlbumPageHeader) showPopUpCover() {
|
||||
log.Printf("error getting full size album cover: %s", err.Error())
|
||||
return
|
||||
}
|
||||
util.ShowPopUpImage(cover, a.page.popUpProvider)
|
||||
a.page.contr.ShowPopUpImage(cover)
|
||||
}
|
||||
|
||||
func formatMiscLabelStr(a *subsonic.AlbumID3) string {
|
||||
return fmt.Sprintf("%d · %d tracks · %s", a.Year, a.SongCount, util.SecondsToTimeString(float64(a.Duration)))
|
||||
}
|
||||
|
||||
type savedAlbumPage struct {
|
||||
albumID string
|
||||
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)
|
||||
func (s *albumPageState) Restore() Page {
|
||||
return NewAlbumPage(s.albumID, s.sm, s.pm, s.lm, s.im, s.contr, s.nav)
|
||||
}
|
||||
|
||||
+24
-33
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
"supersonic/backend"
|
||||
"supersonic/res"
|
||||
"supersonic/ui/controller"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/util"
|
||||
"supersonic/ui/widgets"
|
||||
@@ -16,35 +17,38 @@ import (
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
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 {
|
||||
widget.BaseWidget
|
||||
|
||||
artistID string
|
||||
im *backend.ImageManager
|
||||
sm *backend.ServerManager
|
||||
nav func(Route)
|
||||
popUpProvider util.PopUpProvider
|
||||
artistPageState
|
||||
|
||||
grid *widgets.AlbumGrid
|
||||
header *ArtistPageHeader
|
||||
container *fyne.Container
|
||||
|
||||
OnPlayAlbum func(string, int)
|
||||
}
|
||||
|
||||
func NewArtistPage(artistID string, sm *backend.ServerManager, im *backend.ImageManager, popUp util.PopUpProvider, nav func(Route)) *ArtistPage {
|
||||
a := &ArtistPage{
|
||||
artistID: artistID,
|
||||
sm: sm,
|
||||
im: im,
|
||||
nav: nav,
|
||||
popUpProvider: popUp,
|
||||
}
|
||||
func NewArtistPage(artistID string, sm *backend.ServerManager, im *backend.ImageManager, contr *controller.Controller, nav func(Route)) *ArtistPage {
|
||||
a := &ArtistPage{artistPageState: artistPageState{
|
||||
artistID: artistID,
|
||||
sm: sm,
|
||||
im: im,
|
||||
nav: nav,
|
||||
contr: contr,
|
||||
}}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.header = NewArtistPageHeader(a, nav)
|
||||
a.container = container.NewBorder(
|
||||
@@ -67,13 +71,8 @@ func (a *ArtistPage) Reload() {
|
||||
}
|
||||
|
||||
func (a *ArtistPage) Save() SavedPage {
|
||||
return &savedArtistPage{
|
||||
artistID: a.artistID,
|
||||
sm: a.sm,
|
||||
im: a.im,
|
||||
nav: a.nav,
|
||||
popUpProvider: a.popUpProvider,
|
||||
}
|
||||
s := a.artistPageState
|
||||
return &s
|
||||
}
|
||||
|
||||
func (a *ArtistPage) onPlayAlbum(albumID string) {
|
||||
@@ -112,16 +111,8 @@ func (a *ArtistPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
|
||||
type savedArtistPage struct {
|
||||
artistID string
|
||||
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)
|
||||
func (s *artistPageState) Restore() Page {
|
||||
return NewArtistPage(s.artistID, s.sm, s.im, s.contr, s.nav)
|
||||
}
|
||||
|
||||
type ArtistPageHeader struct {
|
||||
@@ -200,7 +191,7 @@ func (a *ArtistPageHeader) UpdateInfo(info *subsonic.ArtistInfo2) {
|
||||
return
|
||||
}
|
||||
a.artistImage.OnTapped = func() {
|
||||
util.ShowPopUpImage(im, a.artistPage.popUpProvider)
|
||||
a.artistPage.contr.ShowPopUpImage(im)
|
||||
}
|
||||
a.artistImage.SetImage(im, true /*tappable*/)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
var _ fyne.Widget = (*ArtistPage)(nil)
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type Page interface {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type FavoritesPage struct {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"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?
|
||||
|
||||
+39
-24
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
"supersonic/backend"
|
||||
"supersonic/res"
|
||||
"supersonic/ui/controller"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/util"
|
||||
"supersonic/ui/widgets"
|
||||
@@ -13,36 +14,54 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type PlaylistPage struct {
|
||||
widget.BaseWidget
|
||||
|
||||
playlistID string
|
||||
sm *backend.ServerManager
|
||||
pm *backend.PlaybackManager
|
||||
im *backend.ImageManager
|
||||
nav func(Route)
|
||||
playlistPageState
|
||||
|
||||
header *PlaylistPageHeader
|
||||
tracklist *widgets.Tracklist
|
||||
nowPlayingID string
|
||||
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(
|
||||
playlistID string,
|
||||
contr *controller.Controller,
|
||||
sm *backend.ServerManager,
|
||||
pm *backend.PlaybackManager,
|
||||
im *backend.ImageManager,
|
||||
nav func(Route),
|
||||
) *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.header = NewPlaylistPageHeader(a)
|
||||
a.tracklist = widgets.NewTracklist(nil)
|
||||
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.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(
|
||||
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))
|
||||
@@ -55,13 +74,8 @@ func (a *PlaylistPage) CreateRenderer() fyne.WidgetRenderer {
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) Save() SavedPage {
|
||||
return &savedPlaylistPage{
|
||||
playlistID: a.playlistID,
|
||||
sm: a.sm,
|
||||
pm: a.pm,
|
||||
im: a.im,
|
||||
nav: a.nav,
|
||||
}
|
||||
p := a.playlistPageState
|
||||
return &p
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) Route() Route {
|
||||
@@ -81,6 +95,10 @@ func (a *PlaylistPage) Reload() {
|
||||
a.loadAsync()
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) Tapped(*fyne.PointEvent) {
|
||||
a.tracklist.UnselectAll()
|
||||
}
|
||||
|
||||
func (a *PlaylistPage) onPlayTrackAt(tracknum int) {
|
||||
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 {
|
||||
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)))
|
||||
}
|
||||
|
||||
type savedPlaylistPage struct {
|
||||
playlistID string
|
||||
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)
|
||||
func (s *playlistPageState) Restore() Page {
|
||||
return NewPlaylistPage(s.playlistID, s.contr, s.sm, s.pm, s.im, s.nav)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type PlaylistsPage struct {
|
||||
|
||||
+7
-22
@@ -2,10 +2,8 @@ package browsing
|
||||
|
||||
import (
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/controller"
|
||||
"supersonic/ui/util"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
)
|
||||
|
||||
type PageName int
|
||||
@@ -69,42 +67,29 @@ type NavigationHandler interface {
|
||||
|
||||
type Router struct {
|
||||
App *backend.App
|
||||
MainWindow fyne.Window
|
||||
Controller *controller.Controller
|
||||
Nav NavigationHandler
|
||||
|
||||
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{
|
||||
App: app,
|
||||
MainWindow: mainWindow,
|
||||
Controller: controller,
|
||||
Nav: nav,
|
||||
}
|
||||
r.pop = &popUpProvider{window: r.MainWindow}
|
||||
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 {
|
||||
switch rte.Page {
|
||||
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:
|
||||
return NewAlbumsPage("Albums", rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
|
||||
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:
|
||||
return NewArtistsGenresPage(false, r.App.ServerManager, r.OpenRoute)
|
||||
case Favorites:
|
||||
@@ -114,7 +99,7 @@ func (r Router) CreatePage(rte Route) Page {
|
||||
case Genres:
|
||||
return NewArtistsGenresPage(true, r.App.ServerManager, r.OpenRoute)
|
||||
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:
|
||||
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/res"
|
||||
"supersonic/ui/browsing"
|
||||
"supersonic/ui/controller"
|
||||
"supersonic/ui/os"
|
||||
"supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
var (
|
||||
ShortcutBack = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: AltModifier}
|
||||
ShortcutForward = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: AltModifier}
|
||||
ShortcutReload = desktop.CustomShortcut{KeyName: fyne.KeyR, Modifier: ControlModifier}
|
||||
ShortcutSearch = desktop.CustomShortcut{KeyName: fyne.KeyF, Modifier: ControlModifier}
|
||||
ShortcutBack = desktop.CustomShortcut{KeyName: fyne.KeyLeft, Modifier: os.AltModifier}
|
||||
ShortcutForward = desktop.CustomShortcut{KeyName: fyne.KeyRight, Modifier: os.AltModifier}
|
||||
ShortcutReload = desktop.CustomShortcut{KeyName: fyne.KeyR, Modifier: os.ControlModifier}
|
||||
ShortcutSearch = desktop.CustomShortcut{KeyName: fyne.KeyF, Modifier: os.ControlModifier}
|
||||
)
|
||||
|
||||
type MainWindow struct {
|
||||
@@ -25,6 +27,7 @@ type MainWindow struct {
|
||||
|
||||
App *backend.App
|
||||
Router browsing.Router
|
||||
Controller *controller.Controller
|
||||
BrowsingPane *browsing.BrowsingPane
|
||||
BottomPanel *BottomPanel
|
||||
|
||||
@@ -42,7 +45,11 @@ func NewMainWindow(fyneApp fyne.App, appName string, app *backend.App, size fyne
|
||||
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.SetPlaybackManager(app.PlaybackManager)
|
||||
m.BottomPanel.ImageManager = app.ImageManager
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
//go:build darwin
|
||||
|
||||
package ui
|
||||
package os
|
||||
|
||||
import "fyne.io/fyne/v2"
|
||||
import (
|
||||
"fyne.io/fyne/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
ControlModifier = fyne.KeyModifierSuper
|
||||
@@ -1,6 +1,6 @@
|
||||
//go:build !darwin
|
||||
|
||||
package ui
|
||||
package os
|
||||
|
||||
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"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
@@ -33,27 +32,6 @@ type PopUpProvider interface {
|
||||
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 {
|
||||
tokr := html.NewTokenizer(strings.NewReader(s))
|
||||
var segs []widget.RichTextSegment
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
var _ fyne.Widget = (*AlbumCard)(nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
const albumFetchBatchSize = 6
|
||||
|
||||
+138
-24
@@ -3,33 +3,41 @@ package widgets
|
||||
import (
|
||||
"strconv"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/os"
|
||||
"supersonic/ui/util"
|
||||
"time"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/driver/desktop"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type TrackRow struct {
|
||||
widget.BaseWidget
|
||||
|
||||
trackID string
|
||||
prevTrackID string
|
||||
prevIsPlaying bool
|
||||
// internal state
|
||||
trackIdx int
|
||||
trackID string
|
||||
isPlaying bool
|
||||
tappedAt int64 // unixMillis
|
||||
|
||||
num *widget.RichText
|
||||
name *widget.RichText
|
||||
artist *widget.RichText
|
||||
dur *widget.RichText
|
||||
|
||||
OnDoubleTapped func()
|
||||
OnTapped func()
|
||||
OnDoubleTapped func()
|
||||
OnTappedSecondary func(e *fyne.PointEvent, trackIdx int)
|
||||
|
||||
container *fyne.Container
|
||||
selectionRect *canvas.Rectangle
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
var _ fyne.DoubleTappable = (*TrackRow)(nil)
|
||||
|
||||
func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
||||
t := &TrackRow{}
|
||||
t.ExtendBaseWidget(t)
|
||||
@@ -42,17 +50,19 @@ func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
||||
t.dur = widget.NewRichTextWithText("")
|
||||
t.dur.Segments[0].(*widget.TextSegment).Style.Alignment = fyne.TextAlignTrailing
|
||||
|
||||
t.container = container.New(layout,
|
||||
t.num, t.name, t.artist, t.dur)
|
||||
t.selectionRect = canvas.NewRectangle(theme.SelectionColor())
|
||||
t.selectionRect.Hidden = true
|
||||
t.container = container.NewMax(t.selectionRect,
|
||||
container.New(layout,
|
||||
t.num, t.name, t.artist, t.dur))
|
||||
return t
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
t.prevTrackID = t.trackID
|
||||
t.prevIsPlaying = isPlaying
|
||||
t.isPlaying = isPlaying
|
||||
t.trackID = tr.ID
|
||||
|
||||
if rowNum < 0 {
|
||||
@@ -75,40 +85,73 @@ func (t *TrackRow) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(t.container)
|
||||
}
|
||||
|
||||
func (t *TrackRow) DoubleTapped(*fyne.PointEvent) {
|
||||
if t.OnDoubleTapped != nil {
|
||||
t.OnDoubleTapped()
|
||||
// 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 {
|
||||
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 {
|
||||
widget.BaseWidget
|
||||
|
||||
Tracks []*subsonic.Child
|
||||
AutoNumber bool
|
||||
OnPlayTrackAt func(int)
|
||||
Tracks []*subsonic.Child
|
||||
AutoNumber bool
|
||||
// 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
|
||||
colLayout *layouts.ColumnsLayout
|
||||
hdr *ListHeader
|
||||
list *widget.List
|
||||
ctxMenu *fyne.Menu
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
||||
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1}
|
||||
t.ExtendBaseWidget(t)
|
||||
t.selectionMgr = util.NewListSelectionManager(func() int { return len(t.Tracks) })
|
||||
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, 60})
|
||||
t.hdr = NewListHeader([]ListColumn{{"#", true}, {"Title", false}, {"Artist", false}, {"Time", true}}, t.colLayout)
|
||||
t.list = widget.NewList(
|
||||
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) {
|
||||
tr := item.(*TrackRow)
|
||||
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
|
||||
i := itemID + 1
|
||||
if !t.AutoNumber {
|
||||
i = -1 // signal that we want to use the track num.
|
||||
tr.trackIdx = itemID
|
||||
tr.selectionRect.Hidden = !t.selectionMgr.IsSelected(itemID)
|
||||
i := -1 // signal that we want to display the actual track num.
|
||||
if t.AutoNumber {
|
||||
i = itemID + 1
|
||||
}
|
||||
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx, i)
|
||||
})
|
||||
@@ -127,6 +170,11 @@ func (t *Tracklist) SetNowPlaying(trackID string) {
|
||||
t.list.Refresh()
|
||||
}
|
||||
|
||||
func (t *Tracklist) UnselectAll() {
|
||||
t.selectionMgr.UnselectAll()
|
||||
t.Refresh()
|
||||
}
|
||||
|
||||
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(t.container)
|
||||
}
|
||||
@@ -136,3 +184,69 @@ func (t *Tracklist) onPlayTrackAt(idx int) {
|
||||
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