gomp/views/playlistview.go

83 lines
2.0 KiB
Go
Raw Normal View History

2022-08-31 12:12:15 -06:00
package views
import (
"github.com/aditya-K2/gomp/client"
"github.com/aditya-K2/gomp/notify"
"github.com/aditya-K2/gomp/ui"
2022-08-31 12:12:15 -06:00
"github.com/aditya-K2/gomp/utils"
"github.com/aditya-K2/tview"
"github.com/gdamore/tcell/v2"
)
type PlaylistView struct {
}
func (s PlaylistView) GetViewName() string {
return "PlaylistView"
}
func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
return tview.NewTableCell(text).
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(foreground).
Background(tcell.ColorBlack).
Bold(bold))
}
func (p PlaylistView) ShowChildrenContent() {
UI := ui.Ui
CONN := client.Conn
2022-08-31 12:12:15 -06:00
r, _ := UI.ExpandedView.GetSelection()
if err := CONN.Play(r); err != nil {
notify.Notify.Send("Could Not Play the Song")
2022-08-31 12:12:15 -06:00
return
}
}
func (s PlaylistView) ShowParentContent() {
notify.Notify.Send("Not Allowed in this View")
2022-08-31 12:12:15 -06:00
return
}
func (p PlaylistView) AddToPlaylist() {}
func (p PlaylistView) Quit() {
ui.Ui.App.Stop()
2022-08-31 12:12:15 -06:00
}
func (p PlaylistView) FocusBuffSearchView() {}
func (p PlaylistView) DeleteSongFromPlaylist() {
UI := ui.Ui
CONN := client.Conn
2022-08-31 12:12:15 -06:00
r, _ := UI.ExpandedView.GetSelection()
if err := CONN.Delete(r, -1); err != nil {
notify.Notify.Send("Could not Remove the Song from Playlist")
2022-08-31 12:12:15 -06:00
}
}
func (p PlaylistView) Update(inputTable *tview.Table) {
CONN := client.Conn
2022-08-31 12:12:15 -06:00
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
inputTable.Clear()
for i, j := range _playlistAttr {
_, _, w, _ := inputTable.GetInnerRect()
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
inputTable.SetCell(i, 0,
GetCell(
utils.GetFormattedString(j["file"], w/3), tcell.ColorBlue, true))
} else {
inputTable.SetCell(i, 0,
GetCell(
utils.GetFormattedString(j["Title"], w/3), tcell.ColorGreen, false))
inputTable.SetCell(i, 1,
GetCell(
utils.GetFormattedString(j["Artist"], w/3), tcell.ColorPurple, false))
inputTable.SetCell(i, 2,
GetCell(j["Album"], tcell.ColorYellow, false))
}
}
}