Change deleteSongFromPlaylist and clearPlaylist

This commit is contained in:
aditya-K2 2022-09-14 19:51:06 +05:30
parent fdd390a731
commit 503701691b
2 changed files with 15 additions and 9 deletions

10
main.go
View File

@ -118,7 +118,7 @@ func main() {
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
// the Draw Function
views.PView.StartWatcher()
views.SetCurrentView(views.PView)
views.SetCurrentView(&views.PView)
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
views.GetCurrentView().Update(ui.Ui.ExpandedView)
return ui.Ui.ExpandedView.GetInnerRect()
@ -148,7 +148,11 @@ func main() {
if err := Conn.Clear(); err != nil {
notify.Notify.Send("Could not Clear the Playlist")
} else {
notify.Notify.Send("Playlist Cleared")
if views.PView.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
utils.Print("RED", "Couldn't get the current Playlist.\n")
panic(err)
}
notify.Notify.Send("Playlist Cleared!")
}
},
"previousSong": func() {
@ -195,7 +199,7 @@ func main() {
views.FView.Update(ui.Ui.ExpandedView)
},
"navigateToPlaylist": func() {
views.SetCurrentView(views.PView)
views.SetCurrentView(&views.PView)
ui.Ui.Navbar.Select(0, 0)
views.PView.Update(ui.Ui.ExpandedView)
},

View File

@ -50,22 +50,24 @@ func (p PlaylistView) Quit() {
func (p PlaylistView) FocusBuffSearchView() {}
func (p PlaylistView) DeleteSongFromPlaylist() {
func (p *PlaylistView) DeleteSongFromPlaylist() {
UI := ui.Ui
CONN := client.Conn
r, _ := UI.ExpandedView.GetSelection()
if err := CONN.Delete(r, -1); err != nil {
notify.Notify.Send("Could not Remove the Song from Playlist")
} else {
if p.Playlist, err = client.Conn.PlaylistInfo(-1, -1); err != nil {
utils.Print("RED", "Couldn't get the current Playlist.\n")
panic(err)
}
}
}
func (p PlaylistView) Update(inputTable *tview.Table) {
inputTable.Clear()
cplaylist := make([]mpd.Attrs, len(p.Playlist))
for k, v := range p.Playlist {
cplaylist[k] = v
}
for i, j := range cplaylist {
for i, j := range p.Playlist {
_, _, w, _ := inputTable.GetInnerRect()
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
inputTable.SetCell(i, 0,