subsonic-tui/internal/tui/views/playlists.go

64 lines
1.2 KiB
Go
Raw Normal View History

package views
import (
"git.dayanhub.com/sagi/subsonic-tui/internal/client"
"github.com/delucks/go-subsonic"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
var _ View = &playlists{}
type playlists struct {
view *tview.Table
client *client.Client
callback func(playlist *subsonic.Playlist)
}
func NewPlaylists(client *client.Client) *playlists {
obj := &playlists{
client: client,
}
list := tview.NewTable()
list.SetBackgroundColor(tcell.ColorBlack)
list.SetTitle("Playlists [3]")
list.SetBorder(true)
list.SetFocusFunc(func() {
list.SetBorderColor(tcell.ColorRed)
list.SetSelectable(true, false)
})
list.SetBlurFunc(func() {
list.SetBorderColor(tcell.ColorWhite)
list.SetSelectable(false, false)
})
pls, _ := client.GetPlaylists()
for i, pl := range pls {
cell := tview.NewTableCell(pl.Name).SetExpansion(1)
list.SetCell(i, 0, cell)
}
list.SetSelectedFunc(func(row, column int) {
obj.callback(pls[row])
})
obj.view = list
return obj
}
func (p *playlists) SetCallback(f func(playlist *subsonic.Playlist)) {
p.callback = f
}
func (p *playlists) Update() {
}
func (p *playlists) GetView() tview.Primitive {
return p.view
}