gomp/views/buffsearchview.go

106 lines
2.6 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 BuffSearchView struct {
}
func (s BuffSearchView) GetViewName() string {
return "BuffSearchView"
}
func (s BuffSearchView) 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[client.Matches[r].Index].AbsolutePath, -1); err != nil {
notify.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
client.DirTree.Children[client.Matches[r].Index].AbsolutePath))
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("Could not Play the Song")
2022-08-31 12:12:15 -06:00
}
}
} else {
client.DirTree = &client.DirTree.Children[client.Matches[r].Index]
2022-08-31 12:12:15 -06:00
FView.Update(UI.ExpandedView)
}
UI.SearchBar.SetText("")
// Resetting client.Matches
client.Matches = nil
2022-08-31 12:12:15 -06:00
}
func (s BuffSearchView) ShowParentContent() {
notify.Notify.Send("Not Allowed in this View")
2022-08-31 12:12:15 -06:00
return
}
func (s BuffSearchView) 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[client.Matches[r].Index].AbsolutePath); err != nil {
notify.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
client.DirTree.Children[client.Matches[r].Index].Path))
2022-08-31 12:12:15 -06:00
} else {
SetCurrentView(FView)
notify.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
client.DirTree.Children[client.Matches[r].Index].Path))
2022-08-31 12:12:15 -06:00
SetCurrentView(BuffSView)
}
}
func (s BuffSearchView) Quit() {
UI := ui.Ui
2022-08-31 12:12:15 -06:00
SetCurrentView(FView)
UI.SearchBar.SetText("")
client.Matches = nil
2022-08-31 12:12:15 -06:00
}
func (f BuffSearchView) FocusBuffSearchView() {
UI := ui.Ui
2022-08-31 12:12:15 -06:00
SetCurrentView(BuffSView)
UI.App.SetFocus(UI.SearchBar)
}
func (f BuffSearchView) DeleteSongFromPlaylist() {}
func (s BuffSearchView) Update(inputTable *tview.Table) {
m := client.Matches
f := client.DirTree.Children
2022-08-31 12:12:15 -06:00
inputTable.Clear()
if m == nil || len(m) == 0 {
FView.Update(inputTable)
} else {
for k, v := range m {
if len(f[v.Index].Children) != 0 {
inputTable.SetCell(k, 0,
GetCell(
utils.GetMatchedString(
utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[blue:-:bi]"),
tcell.ColorYellow, true))
} else {
inputTable.SetCell(k, 0,
GetCell(
utils.GetMatchedString(
utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[yellow:-:bi]"),
tcell.ColorGreen, true))
}
if k == 15 {
break
}
}
}
}