2022-08-31 12:12:15 -06:00
|
|
|
package views
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/aditya-K2/gomp/client"
|
2022-09-01 13:55:33 -06:00
|
|
|
"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 SearchView struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s SearchView) GetViewName() string {
|
|
|
|
return "SearchView"
|
|
|
|
}
|
|
|
|
func (s SearchView) ShowChildrenContent() {
|
2022-09-01 13:55:33 -06:00
|
|
|
UI := ui.Ui
|
|
|
|
SearchContentSlice := client.SearchContentSlice
|
|
|
|
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
|
|
|
notify.Notify.Send("No Search Results")
|
2022-08-31 12:42:17 -06:00
|
|
|
} else {
|
|
|
|
r, _ := UI.ExpandedView.GetSelection()
|
|
|
|
client.AddToPlaylist(SearchContentSlice[r], true)
|
|
|
|
}
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s SearchView) 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 (s SearchView) AddToPlaylist() {
|
2022-09-01 13:55:33 -06:00
|
|
|
UI := ui.Ui
|
|
|
|
SearchContentSlice := client.SearchContentSlice
|
|
|
|
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
|
|
|
notify.Notify.Send("No Search Results")
|
2022-08-31 12:42:17 -06:00
|
|
|
} else {
|
|
|
|
r, _ := UI.ExpandedView.GetSelection()
|
|
|
|
client.AddToPlaylist(SearchContentSlice[r], false)
|
|
|
|
}
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p SearchView) Quit() {
|
2022-09-01 13:55:33 -06:00
|
|
|
ui.Ui.App.Stop()
|
2022-08-31 12:12:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s SearchView) FocusBuffSearchView() {}
|
|
|
|
func (s SearchView) DeleteSongFromPlaylist() {}
|
|
|
|
|
|
|
|
func (s SearchView) Update(inputTable *tview.Table) {
|
|
|
|
inputTable.Clear()
|
2022-09-01 13:55:33 -06:00
|
|
|
c := client.SearchContentSlice
|
2022-08-31 12:12:15 -06:00
|
|
|
_, _, width, _ := inputTable.GetInnerRect()
|
|
|
|
for i, content := range c {
|
|
|
|
switch content.(type) {
|
|
|
|
case [3]string:
|
|
|
|
{
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(content.([3]string)[0], width/3), tcell.ColorGreen, false))
|
|
|
|
inputTable.SetCell(i, 1,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(content.([3]string)[1], width/3), tcell.ColorPurple, false))
|
|
|
|
inputTable.SetCell(i, 2,
|
|
|
|
GetCell(content.([3]string)[2], tcell.ColorYellow, false))
|
|
|
|
}
|
|
|
|
case [2]string:
|
|
|
|
{
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(content.([2]string)[0], width/3), tcell.ColorYellow, false))
|
|
|
|
inputTable.SetCell(i, 1,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(content.([2]string)[1], width/3), tcell.ColorPurple, false))
|
|
|
|
}
|
|
|
|
case string:
|
|
|
|
{
|
|
|
|
b := content.(string)
|
|
|
|
if !strings.HasPrefix(b, client.WHITE_AND_BOLD) {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(content.(string), tcell.ColorPurple, false))
|
|
|
|
} else {
|
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(content.(string), tcell.ColorWhite, true).SetSelectable(false))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|