No need to use globals as a separate package to avoid import cycles
This commit is contained in:
@@ -3,7 +3,9 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -17,57 +19,57 @@ func (s BuffSearchView) GetViewName() string {
|
||||
}
|
||||
|
||||
func (s BuffSearchView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
SetCurrentView(FView)
|
||||
if len(globals.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath, -1); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
||||
globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath))
|
||||
if len(client.DirTree.Children[r].Children) == 0 {
|
||||
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))
|
||||
} else {
|
||||
if err := CONN.PlayId(id); err != nil {
|
||||
globals.Notify.Send("Could not Play the Song")
|
||||
notify.Notify.Send("Could not Play the Song")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.DirTree = &globals.DirTree.Children[globals.Matches[r].Index]
|
||||
client.DirTree = &client.DirTree.Children[client.Matches[r].Index]
|
||||
FView.Update(UI.ExpandedView)
|
||||
}
|
||||
UI.SearchBar.SetText("")
|
||||
// Resetting globals.Matches
|
||||
globals.Matches = nil
|
||||
// Resetting client.Matches
|
||||
client.Matches = nil
|
||||
}
|
||||
|
||||
func (s BuffSearchView) ShowParentContent() {
|
||||
globals.Notify.Send("Not Allowed in this View")
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
|
||||
func (s BuffSearchView) AddToPlaylist() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
||||
globals.DirTree.Children[globals.Matches[r].Index].Path))
|
||||
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))
|
||||
} else {
|
||||
SetCurrentView(FView)
|
||||
globals.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||
globals.DirTree.Children[globals.Matches[r].Index].Path))
|
||||
notify.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||
SetCurrentView(BuffSView)
|
||||
}
|
||||
}
|
||||
|
||||
func (s BuffSearchView) Quit() {
|
||||
UI := globals.Ui
|
||||
UI := ui.Ui
|
||||
SetCurrentView(FView)
|
||||
UI.SearchBar.SetText("")
|
||||
globals.Matches = nil
|
||||
client.Matches = nil
|
||||
}
|
||||
|
||||
func (f BuffSearchView) FocusBuffSearchView() {
|
||||
UI := globals.Ui
|
||||
UI := ui.Ui
|
||||
SetCurrentView(BuffSView)
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
@@ -75,8 +77,8 @@ func (f BuffSearchView) FocusBuffSearchView() {
|
||||
func (f BuffSearchView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (s BuffSearchView) Update(inputTable *tview.Table) {
|
||||
m := globals.Matches
|
||||
f := globals.DirTree.Children
|
||||
m := client.Matches
|
||||
f := client.DirTree.Children
|
||||
inputTable.Clear()
|
||||
if m == nil || len(m) == 0 {
|
||||
FView.Update(inputTable)
|
||||
|
||||
@@ -3,7 +3,9 @@ package views
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -17,51 +19,51 @@ func (f FileView) GetViewName() string {
|
||||
}
|
||||
|
||||
func (f FileView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
SetCurrentView(FView)
|
||||
if len(globals.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(globals.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
||||
globals.DirTree.Children[r].Path))
|
||||
if len(client.DirTree.Children[r].Children) == 0 {
|
||||
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))
|
||||
} else {
|
||||
if err := CONN.PlayId(id); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||
globals.DirTree.Children[r].Path))
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||
client.DirTree.Children[r].Path))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
globals.DirTree = &globals.DirTree.Children[r]
|
||||
client.DirTree = &client.DirTree.Children[r]
|
||||
FView.Update(UI.ExpandedView)
|
||||
UI.ExpandedView.Select(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) ShowParentContent() {
|
||||
UI := globals.Ui
|
||||
if globals.DirTree.Parent != nil {
|
||||
globals.DirTree = globals.DirTree.Parent
|
||||
UI := ui.Ui
|
||||
if client.DirTree.Parent != nil {
|
||||
client.DirTree = client.DirTree.Parent
|
||||
FView.Update(UI.ExpandedView)
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) AddToPlaylist() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(globals.DirTree.Children[r].AbsolutePath); err != nil {
|
||||
globals.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
||||
globals.DirTree.Children[r].Path))
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) Quit() {
|
||||
globals.Ui.App.Stop()
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (f FileView) FocusBuffSearchView() {
|
||||
UI := globals.Ui
|
||||
UI := ui.Ui
|
||||
SetCurrentView(BuffSView)
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
@@ -70,9 +72,9 @@ func (f FileView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (f FileView) Update(inputTable *tview.Table) {
|
||||
inputTable.Clear()
|
||||
for i, j := range globals.DirTree.Children {
|
||||
for i, j := range client.DirTree.Children {
|
||||
if len(j.Children) == 0 {
|
||||
_songAttributes, err := globals.Conn.ListAllInfo(j.AbsolutePath)
|
||||
_songAttributes, err := client.Conn.ListAllInfo(j.AbsolutePath)
|
||||
if err == nil && _songAttributes[0]["Title"] != "" {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
inputTable.SetCell(i, 0,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -24,38 +26,38 @@ func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
|
||||
}
|
||||
|
||||
func (p PlaylistView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Play(r); err != nil {
|
||||
globals.Notify.Send("Could Not Play the Song")
|
||||
notify.Notify.Send("Could Not Play the Song")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s PlaylistView) ShowParentContent() {
|
||||
globals.Notify.Send("Not Allowed in this View")
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
func (p PlaylistView) AddToPlaylist() {}
|
||||
|
||||
func (p PlaylistView) Quit() {
|
||||
globals.Ui.App.Stop()
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (p PlaylistView) FocusBuffSearchView() {}
|
||||
|
||||
func (p PlaylistView) DeleteSongFromPlaylist() {
|
||||
UI := globals.Ui
|
||||
CONN := globals.Conn
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Delete(r, -1); err != nil {
|
||||
globals.Notify.Send("Could not Remove the Song from Playlist")
|
||||
notify.Notify.Send("Could not Remove the Song from Playlist")
|
||||
}
|
||||
}
|
||||
|
||||
func (p PlaylistView) Update(inputTable *tview.Table) {
|
||||
CONN := globals.Conn
|
||||
CONN := client.Conn
|
||||
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
||||
|
||||
inputTable.Clear()
|
||||
|
||||
@@ -4,7 +4,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/globals"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
@@ -17,10 +18,10 @@ func (s SearchView) GetViewName() string {
|
||||
return "SearchView"
|
||||
}
|
||||
func (s SearchView) ShowChildrenContent() {
|
||||
UI := globals.Ui
|
||||
SearchContentSlice := globals.SearchContentSlice
|
||||
if len(globals.SearchContentSlice) <= 0 || globals.SearchContentSlice == nil {
|
||||
globals.Notify.Send("No Search Results")
|
||||
UI := ui.Ui
|
||||
SearchContentSlice := client.SearchContentSlice
|
||||
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||
notify.Notify.Send("No Search Results")
|
||||
} else {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], true)
|
||||
@@ -28,15 +29,15 @@ func (s SearchView) ShowChildrenContent() {
|
||||
}
|
||||
|
||||
func (s SearchView) ShowParentContent() {
|
||||
globals.Notify.Send("Not Allowed in this View")
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
|
||||
func (s SearchView) AddToPlaylist() {
|
||||
UI := globals.Ui
|
||||
SearchContentSlice := globals.SearchContentSlice
|
||||
if len(globals.SearchContentSlice) <= 0 || globals.SearchContentSlice == nil {
|
||||
globals.Notify.Send("No Search Results")
|
||||
UI := ui.Ui
|
||||
SearchContentSlice := client.SearchContentSlice
|
||||
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||
notify.Notify.Send("No Search Results")
|
||||
} else {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], false)
|
||||
@@ -44,7 +45,7 @@ func (s SearchView) AddToPlaylist() {
|
||||
}
|
||||
|
||||
func (p SearchView) Quit() {
|
||||
globals.Ui.App.Stop()
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (s SearchView) FocusBuffSearchView() {}
|
||||
@@ -52,7 +53,7 @@ func (s SearchView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (s SearchView) Update(inputTable *tview.Table) {
|
||||
inputTable.Clear()
|
||||
c := globals.SearchContentSlice
|
||||
c := client.SearchContentSlice
|
||||
_, _, width, _ := inputTable.GetInnerRect()
|
||||
for i, content := range c {
|
||||
switch content.(type) {
|
||||
|
||||
Reference in New Issue
Block a user