2022-08-31 12:12:15 -06:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
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 FileView struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) GetViewName() string {
|
|
|
|
return "FileView"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) 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()
|
|
|
|
SetCurrentView(FView)
|
2022-09-01 13:55:33 -06:00
|
|
|
if len(client.DirTree.Children[r].Children) == 0 {
|
2022-09-08 13:16:38 -06:00
|
|
|
if id, err := CONN.AddID(client.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
|
|
|
client.DirTree.Children[r].Path))
|
2022-08-31 12:12:15 -06:00
|
|
|
} else {
|
2022-09-08 13:16:38 -06:00
|
|
|
if err := CONN.PlayID(id); err != nil {
|
2022-09-01 13:55:33 -06:00
|
|
|
notify.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
|
|
|
client.DirTree.Children[r].Path))
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-09-01 13:55:33 -06:00
|
|
|
client.DirTree = &client.DirTree.Children[r]
|
2022-08-31 12:12:15 -06:00
|
|
|
FView.Update(UI.ExpandedView)
|
|
|
|
UI.ExpandedView.Select(0, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) ShowParentContent() {
|
2022-09-01 13:55:33 -06:00
|
|
|
UI := ui.Ui
|
|
|
|
if client.DirTree.Parent != nil {
|
|
|
|
client.DirTree = client.DirTree.Parent
|
2022-08-31 12:12:15 -06:00
|
|
|
FView.Update(UI.ExpandedView)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) AddToPlaylist() {
|
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()
|
2022-09-01 13:55:33 -06:00
|
|
|
if err := CONN.Add(client.DirTree.Children[r].AbsolutePath); err != nil {
|
|
|
|
notify.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
|
|
|
client.DirTree.Children[r].Path))
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) Quit() {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.App.Stop()
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) FocusBuffSearchView() {
|
2022-09-01 13:55:33 -06:00
|
|
|
UI := ui.Ui
|
2022-08-31 12:12:15 -06:00
|
|
|
SetCurrentView(BuffSView)
|
|
|
|
UI.App.SetFocus(UI.SearchBar)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f FileView) DeleteSongFromPlaylist() {}
|
|
|
|
|
|
|
|
func (f FileView) Update(inputTable *tview.Table) {
|
|
|
|
inputTable.Clear()
|
2022-09-01 13:55:33 -06:00
|
|
|
for i, j := range client.DirTree.Children {
|
2022-08-31 12:12:15 -06:00
|
|
|
if len(j.Children) == 0 {
|
2022-09-01 13:55:33 -06:00
|
|
|
_songAttributes, err := client.Conn.ListAllInfo(j.AbsolutePath)
|
2022-08-31 12:12:15 -06:00
|
|
|
if err == nil && _songAttributes[0]["Title"] != "" {
|
|
|
|
_, _, w, _ := inputTable.GetInnerRect()
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false))
|
|
|
|
|
|
|
|
inputTable.SetCell(i, 1,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false))
|
|
|
|
inputTable.SetCell(i, 2,
|
|
|
|
GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false))
|
|
|
|
|
|
|
|
} else if _songAttributes[0]["Title"] == "" {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(j.Path, tcell.ColorBlue, true))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(j.Path, tcell.ColorYellow, true))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|