aboutsummaryrefslogtreecommitdiff
path: root/src/page_artists.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/page_artists.go')
-rw-r--r--src/page_artists.go53
1 files changed, 42 insertions, 11 deletions
diff --git a/src/page_artists.go b/src/page_artists.go
index e8ce180..4361767 100644
--- a/src/page_artists.go
+++ b/src/page_artists.go
@@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "time" 5 "time"
6 6
7 "github.com/delucks/go-subsonic"
7 "github.com/gdamore/tcell/v2" 8 "github.com/gdamore/tcell/v2"
8 "github.com/rivo/tview" 9 "github.com/rivo/tview"
9) 10)
@@ -14,9 +15,7 @@ type selection struct {
14} 15}
15 16
16func (a *app) artistsPage() tview.Primitive { 17func (a *app) artistsPage() tview.Primitive {
17 grid := tview.NewGrid(). 18 grid := tview.NewFlex().SetDirection(tview.FlexColumn)
18 SetColumns(40, 0).
19 SetBorders(true)
20 19
21 // Artist & album list 20 // Artist & album list
22 root := tview.NewTreeNode("Subsonic server").SetColor(tcell.ColorYellow) 21 root := tview.NewTreeNode("Subsonic server").SetColor(tcell.ColorYellow)
@@ -37,18 +36,18 @@ func (a *app) artistsPage() tview.Primitive {
37 36
38 a.loadAlbumInPanel(sel.id) 37 a.loadAlbumInPanel(sel.id)
39 a.tv.SetFocus(a.songsList) 38 a.tv.SetFocus(a.songsList)
40 a.updateFooter()
41 }) 39 })
40 a.artistsTree.SetBorderAttributes(tcell.AttrDim).SetBorder(true)
42 41
43 // Songs list for the selected album 42 // Songs list for the selected album
44 a.songsList = tview.NewList() 43 a.songsList = tview.NewList()
45 a.songsList.ShowSecondaryText(false) 44 a.songsList.ShowSecondaryText(false)
45 a.songsList.SetBorderAttributes(tcell.AttrDim).SetBorder(true)
46 46
47 // Change the left-right keys to switch between the panels 47 // Change the left-right keys to switch between the panels
48 a.artistsTree.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { 48 a.artistsTree.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
49 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight { 49 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight {
50 a.tv.SetFocus(a.songsList) 50 a.tv.SetFocus(a.songsList)
51 a.updateFooter()
52 return nil 51 return nil
53 } 52 }
54 return event 53 return event
@@ -57,14 +56,26 @@ func (a *app) artistsPage() tview.Primitive {
57 a.songsList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey { 56 a.songsList.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
58 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight { 57 if event.Key() == tcell.KeyLeft || event.Key() == tcell.KeyRight {
59 a.tv.SetFocus(a.artistsTree) 58 a.tv.SetFocus(a.artistsTree)
60 a.updateFooter()
61 return nil 59 return nil
62 } 60 }
63 return event 61 return event
64 }) 62 })
65 63
66 grid.AddItem(a.artistsTree, 0, 0, 1, 1, 0, 0, true) 64 grid.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
67 grid.AddItem(a.songsList, 0, 1, 1, 2, 0, 0, false) 65 if event.Rune() == 'l' {
66 a.playQueue.Next()
67 return nil
68 }
69
70 if event.Rune() == 'k' {
71 a.playQueue.TogglePause()
72 return nil
73 }
74 return event
75 })
76
77 grid.AddItem(a.artistsTree, 0, 1, true)
78 grid.AddItem(a.songsList, 0, 1, false)
68 79
69 return grid 80 return grid
70} 81}
@@ -113,12 +124,32 @@ func (a *app) loadAlbumInPanel(id string) error {
113 return err 124 return err
114 } 125 }
115 126
116 a.songsList.SetTitle(album.Name) 127 var songs []*subsonic.Child
128
117 a.songsList.Clear() 129 a.songsList.Clear()
118 for _, song := range album.Child { 130 for i := len(album.Child) - 1; i >= 0; i-- {
131 song := album.Child[i]
132 songNoPtr := *song
133 songs = append([]*subsonic.Child{&songNoPtr}, songs...)
134
135 songsCopy := make([]*subsonic.Child, len(songs))
136 copy(songsCopy, songs)
137
119 dur := time.Duration(song.Duration) * time.Second 138 dur := time.Duration(song.Duration) * time.Second
120 a.songsList.AddItem(fmt.Sprintf("%-10s %d - %s", fmt.Sprintf("[%s]", dur.String()), song.Track, song.Title), "", 0, nil) 139
140 a.songsList.InsertItem(0, fmt.Sprintf("%-10s %d - %s", fmt.Sprintf("[%s]", dur.String()), song.Track, song.Title), "", 0, func() {
141 a.playQueue.Clear()
142 for _, s := range songsCopy {
143 a.playQueue.Append(s)
144 }
145 err := a.playQueue.Play()
146 if err != nil {
147 a.alert("Error: %v", err)
148 }
149 })
121 } 150 }
122 151
152 a.songsList.SetCurrentItem(0)
153
123 return nil 154 return nil
124} 155}