2022-08-31 12:12:15 -06:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
2022-09-01 13:55:33 -06:00
|
|
|
"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() {
|
2022-09-01 13:55:33 -06:00
|
|
|
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 {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send("Could Not Play the Song")
|
2022-08-31 12:12:15 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s PlaylistView) ShowParentContent() {
|
2022-09-01 13:55:33 -06:00
|
|
|
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() {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.App.Stop()
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p PlaylistView) FocusBuffSearchView() {}
|
|
|
|
|
|
|
|
func (p PlaylistView) DeleteSongFromPlaylist() {
|
2022-09-01 13:55:33 -06:00
|
|
|
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 {
|
2022-09-01 13:55:33 -06:00
|
|
|
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) {
|
2022-09-01 13:55:33 -06:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|