gomp/views/fileview.go

97 lines
2.3 KiB
Go
Raw Normal View History

2022-08-31 12:12:15 -06:00
package views
import (
"fmt"
"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() {
UI := ui.Ui
CONN := client.Conn
2022-08-31 12:12:15 -06:00
r, _ := UI.ExpandedView.GetSelection()
SetCurrentView(FView)
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 {
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 {
notify.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
client.DirTree.Children[r].Path))
2022-08-31 12:12:15 -06:00
}
}
} else {
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() {
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() {
UI := ui.Ui
CONN := client.Conn
2022-08-31 12:12:15 -06:00
r, _ := UI.ExpandedView.GetSelection()
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() {
ui.Ui.App.Stop()
2022-08-31 12:12:15 -06:00
}
func (f FileView) FocusBuffSearchView() {
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()
for i, j := range client.DirTree.Children {
2022-08-31 12:12:15 -06:00
if len(j.Children) == 0 {
2022-10-07 15:21:22 -06:00
if j.Title != "" {
2022-08-31 12:12:15 -06:00
_, _, w, _ := inputTable.GetInnerRect()
inputTable.SetCell(i, 0,
GetCell(
2022-10-07 15:21:22 -06:00
utils.GetFormattedString(j.Title, w/3), tcell.ColorGreen, false))
2022-08-31 12:12:15 -06:00
inputTable.SetCell(i, 1,
GetCell(
2022-10-07 15:21:22 -06:00
utils.GetFormattedString(j.Artist, w/3), tcell.ColorPurple, false))
2022-08-31 12:12:15 -06:00
inputTable.SetCell(i, 2,
2022-10-07 15:21:22 -06:00
GetCell(j.Album, tcell.ColorYellow, false))
} else if j.Title == "" {
2022-08-31 12:12:15 -06:00
inputTable.SetCell(i, 0,
GetCell(j.Path, tcell.ColorBlue, true))
}
} else {
inputTable.SetCell(i, 0,
GetCell(j.Path, tcell.ColorYellow, true))
}
}
}