diff --git a/ui/app.go b/ui/app.go index bdbca1b..095bfcb 100644 --- a/ui/app.go +++ b/ui/app.go @@ -115,36 +115,36 @@ func NewApplication() *tview.Application { root = NewRoot() coverArt = newCoverArt() Main = NewInteractiveView() - Main.Table.SetBorder(true) + Main.SetBorder(true) progressBar := NewProgressBar().SetProgressFunc(progressFunc) searchbar := NewSearchBar() navMenu := NewNavMenu([]navItem{ {"Albums", NewAction(func(e *tcell.EventKey) *tcell.EventKey { SetCurrentView(albumsView) - App.SetFocus(Main.Table) + App.SetFocus(Main) return nil }, nil)}, {"Artists", NewAction(func(e *tcell.EventKey) *tcell.EventKey { SetCurrentView(artistsView) - App.SetFocus(Main.Table) + App.SetFocus(Main) return nil }, nil)}, {"Liked Songs", NewAction(func(e *tcell.EventKey) *tcell.EventKey { SetCurrentView(likedSongsView) - App.SetFocus(Main.Table) + App.SetFocus(Main) return nil }, nil)}, {"Recently Played", NewAction(func(e *tcell.EventKey) *tcell.EventKey { recentlyPlayedView.RefreshState() SetCurrentView(recentlyPlayedView) - App.SetFocus(Main.Table) + App.SetFocus(Main) return nil }, nil)}, }) playlistNav := NewPlaylistNav() - root.AfterContextClose(func() { App.SetFocus(Main.Table) }) + root.AfterContextClose(func() { App.SetFocus(Main) }) // Define Actions openCurrentArtist := func() { @@ -152,7 +152,7 @@ func NewApplication() *tview.Application { if len(state.Item.Artists) != 0 { artistView.SetArtist(&state.Item.Artists[0].ID) SetCurrentView(artistView) - App.SetFocus(Main.Table) + App.SetFocus(Main) } else { SendNotification("No Artist Found!") } @@ -162,7 +162,7 @@ func NewApplication() *tview.Application { if state != nil && state.Item != nil { albumView.SetAlbum(state.Item.Album.Name, &state.Item.Album.ID) SetCurrentView(albumView) - App.SetFocus(Main.Table) + App.SetFocus(Main) } } globalActions := map[string]*Action{ @@ -181,15 +181,15 @@ func NewApplication() *tview.Application { return nil }, nil), "focus_nav": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - App.SetFocus(navMenu.Table) + App.SetFocus(navMenu) return nil }, nil), "focus_playlists": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - App.SetFocus(playlistNav.Table) + App.SetFocus(playlistNav) return nil }, nil), "focus_main_view": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - App.SetFocus(Main.Table) + App.SetFocus(Main) return nil }, nil), "open_current_track_album": NewAction(func(e *tcell.EventKey) *tcell.EventKey { @@ -225,7 +225,7 @@ func NewApplication() *tview.Application { } playlistView.SetPlaylist(&p.SimplePlaylist) SetCurrentView(playlistView) - App.SetFocus(Main.Table) + App.SetFocus(Main) } default: { @@ -254,10 +254,10 @@ func NewApplication() *tview.Application { "play_entry": NewAction(playlistNav.PlaySelectEntry, progressBar), "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - r, _ := playlistNav.Table.GetSelection() + r, _ := playlistNav.GetSelection() playlistView.SetPlaylist(&(*playlistNav.Playlists)[r]) SetCurrentView(playlistView) - App.SetFocus(Main.Table) + App.SetFocus(Main) return nil }, nil), })) @@ -372,9 +372,9 @@ func NewApplication() *tview.Application { // Map Actions playlistNav.SetMappings(mappings["playlist_nav"]) - playlistNav.Table.SetInputCapture(playlistNav.ExternalInputCapture()) + playlistNav.SetInputCapture(playlistNav.ExternalInputCapture()) navMenu.SetMappings(mappings["nav_menu"]) - navMenu.Table.SetInputCapture(navMenu.ExternalInputCapture()) + navMenu.SetInputCapture(navMenu.ExternalInputCapture()) playlistView.SetMappings(mappings["playlist_view"]) recentlyPlayedView.SetMappings(mappings["recently_played_view"]) topTracksView.SetMappings(mappings["top_tracks_view"]) @@ -387,8 +387,8 @@ func NewApplication() *tview.Application { // Set up UI navFlex := tview.NewFlex().SetDirection(tview.FlexRow). - AddItem(navMenu.Table, 6, 3, false). - AddItem(playlistNav.Table, 0, 6, false) + AddItem(navMenu, 6, 3, false). + AddItem(playlistNav, 0, 6, false) if !config.Config.HideImage { navFlex.AddItem(coverArt, 9, 3, false) @@ -397,7 +397,7 @@ func NewApplication() *tview.Application { // mid mFlex := tview.NewFlex(). AddItem(navFlex, 17, 1, false). - AddItem(Main.Table, 0, 4, false) + AddItem(Main, 0, 4, false) // mid + top tFlex := tview.NewFlex().SetDirection(tview.FlexRow). @@ -409,7 +409,7 @@ func NewApplication() *tview.Application { AddItem(progressBar, 5, 1, false) root.Primitive("Main", mainFlex) - App.SetRoot(root.Root, true).SetFocus(Main.Table) + App.SetRoot(root.Root, true).SetFocus(Main) // Start Routines InitNotifier() diff --git a/ui/interactive.go b/ui/interactive.go index 49e39ea..ef771ba 100644 --- a/ui/interactive.go +++ b/ui/interactive.go @@ -25,7 +25,7 @@ type interactiveView struct { visual bool vrange *_range baseSel int - Table *tview.Table + *tview.Table } func NewInteractiveView() *interactiveView { diff --git a/ui/nav.go b/ui/nav.go index 91b21da..3f410a9 100644 --- a/ui/nav.go +++ b/ui/nav.go @@ -13,8 +13,8 @@ type navItem struct { type NavMenu struct { *defView - Table *tview.Table - m []navItem + *tview.Table + m []navItem } func NewNavMenu(m []navItem) *NavMenu { @@ -46,7 +46,7 @@ func (n *NavMenu) SelectEntry(e *tcell.EventKey) *tcell.EventKey { type PlaylistNav struct { *defView - Table *tview.Table + *tview.Table Playlists *spt.UserPlaylists c chan bool done func(error) @@ -63,22 +63,18 @@ func NewPlaylistNav() *PlaylistNav { } }} T.SetDrawFunc(func(s tcell.Screen, x, y, w, h int) (int, int, int, int) { - v.Draw() + if v.Playlists == nil { + v.RefreshState() + } + for k, p := range *v.Playlists { + v.Table.SetCell(k, 0, + GetCell(p.Name, PlaylistNavStyle)) + } return T.GetInnerRect() }) return v } -func (v *PlaylistNav) Draw() { - if v.Playlists == nil { - v.RefreshState() - } - for k, p := range *v.Playlists { - v.Table.SetCell(k, 0, - GetCell(p.Name, PlaylistNavStyle)) - } -} - func (v *PlaylistNav) PlaySelectEntry(e *tcell.EventKey) *tcell.EventKey { r, _ := v.Table.GetSelection() if err := spt.PlayContext(&(*v.Playlists)[r].URI); err != nil { diff --git a/ui/notify.go b/ui/notify.go index 0b3d930..3fcdcf5 100644 --- a/ui/notify.go +++ b/ui/notify.go @@ -140,7 +140,7 @@ func notify(n *notification) { n.position = npos root.Root.AddPage(currentTime, n, false, true) App.Draw() - App.SetFocus(Main.Table) + App.SetFocus(Main) if n.msg != nil { n.text = <-n.msg App.Draw() @@ -148,7 +148,7 @@ func notify(n *notification) { time.Sleep(n.timer) root.Root.RemovePage(currentTime) posArr.Free(npos) - App.SetFocus(Main.Table) + App.SetFocus(Main) App.Draw() }() } diff --git a/ui/search.go b/ui/search.go index 28f2274..85b5910 100644 --- a/ui/search.go +++ b/ui/search.go @@ -22,14 +22,14 @@ func NewSearchBar() *tview.InputField { switch k { case tcell.KeyEscape: { - App.SetFocus(Main.Table) + App.SetFocus(Main) T.SetText("") } case tcell.KeyEnter: { searchView.SetSearch(T.GetText()) SetCurrentView(searchView) - App.SetFocus(Main.Table) + App.SetFocus(Main) T.SetText("") } } diff --git a/ui/view_album.go b/ui/view_album.go index 1fe6bd2..ae5f61a 100644 --- a/ui/view_album.go +++ b/ui/view_album.go @@ -61,7 +61,7 @@ func (a *AlbumView) Content() func() [][]Content { } func (a *AlbumView) AddToPlaylist() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() track := (*(*a.currentFullAlbum).Tracks)[r] addToPlaylist([]spotify.ID{track.ID}) } @@ -77,7 +77,7 @@ func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcel } func (a *AlbumView) PlaySelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if err := spt.PlaySongWithContext(&a.currentFullAlbum.URI, r); err != nil { SendNotification(err.Error()) } diff --git a/ui/view_albums.go b/ui/view_albums.go index 3235a96..219cd11 100644 --- a/ui/view_albums.go +++ b/ui/view_albums.go @@ -47,20 +47,20 @@ func (a *AlbumsView) Content() func() [][]Content { } func (a *AlbumsView) OpenAlbum() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() albumView.SetAlbum((*a.savedAlbums)[r].Name, &(*a.savedAlbums)[r].ID) SetCurrentView(albumView) } func (a *AlbumsView) PlaySelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if err := spt.PlayContext(&(*a.savedAlbums)[r].URI); err != nil { SendNotification(err.Error()) } } func (a *AlbumsView) QueueSelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() alb := (*a.savedAlbums)[r] msg := SendNotificationWithChan("Queueing " + alb.Name + "...") go func() { diff --git a/ui/view_artist.go b/ui/view_artist.go index e1482bf..828f6fd 100644 --- a/ui/view_artist.go +++ b/ui/view_artist.go @@ -72,7 +72,7 @@ func (a *ArtistView) Content() func() [][]Content { } func (a *ArtistView) PlayEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if r > 0 { if r < (len(a.albums) + 1) { if err := spt.PlayContext(&a.albums[r-1].URI); err != nil { @@ -83,7 +83,7 @@ func (a *ArtistView) PlayEntry() { } func (a *ArtistView) OpenEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if r > 0 { if r < (len(a.albums)+1) && len(a.albums) > 0 { albumView.SetAlbum(a.albums[r-1].Name, &a.albums[r-1].ID) diff --git a/ui/view_artists.go b/ui/view_artists.go index 0c85f6d..51fa4c6 100644 --- a/ui/view_artists.go +++ b/ui/view_artists.go @@ -46,7 +46,7 @@ func (a *ArtistsView) Content() func() [][]Content { } func (a *ArtistsView) OpenArtist() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() artistView.SetArtist(&(*a.followedArtists)[r].ID) SetCurrentView(artistView) } diff --git a/ui/view_liked.go b/ui/view_liked.go index 600b7c0..bc4b046 100644 --- a/ui/view_liked.go +++ b/ui/view_liked.go @@ -46,7 +46,7 @@ func (p *LikedSongsView) Content() func() [][]Content { } func (l *LikedSongsView) AddToPlaylist() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() addToPlaylist([]spotify.ID{(*l.likedSongs)[r].ID}) } @@ -60,7 +60,7 @@ func (l *LikedSongsView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) } func (l *LikedSongsView) OpenEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if err := spt.PlaySong((*l.likedSongs)[r].URI); err != nil { SendNotification(err.Error()) } diff --git a/ui/view_playlist.go b/ui/view_playlist.go index 91ce9c9..7a04cb5 100644 --- a/ui/view_playlist.go +++ b/ui/view_playlist.go @@ -60,7 +60,7 @@ func (p *PlaylistView) Content() func() [][]Content { } func (p *PlaylistView) AddToPlaylist() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() addToPlaylist([]spotify.ID{(*(*p.currentUserFullPlaylist).Tracks)[r].Track.ID}) } @@ -75,7 +75,7 @@ func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *t } func (p *PlaylistView) PlaySelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if err := spt.PlaySongWithContext(&p.currentPlaylist.URI, r); err != nil { SendNotification(err.Error()) } diff --git a/ui/view_recent.go b/ui/view_recent.go index e5173a2..378ace2 100644 --- a/ui/view_recent.go +++ b/ui/view_recent.go @@ -41,7 +41,7 @@ func (r *RecentlyPlayedView) Content() func() [][]Content { } func (r *RecentlyPlayedView) AddToPlaylist() { - _r, _ := Main.Table.GetSelection() + _r, _ := Main.GetSelection() addToPlaylist([]spotify.ID{r.recentlyPlayed[_r].Track.ID}) } @@ -66,7 +66,7 @@ func (r *RecentlyPlayedView) RefreshState() { } func (re *RecentlyPlayedView) SelectEntry(e *tcell.EventKey) *tcell.EventKey { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() trackUri := re.recentlyPlayed[r].Track.URI contextUri := re.recentlyPlayed[r].PlaybackContext.URI if string(contextUri) != "" { diff --git a/ui/view_search.go b/ui/view_search.go index 2ad282c..73d05e3 100644 --- a/ui/view_search.go +++ b/ui/view_search.go @@ -102,7 +102,7 @@ func (a *SearchView) Content() func() [][]Content { } func (a *SearchView) SelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() switch a.searchContent[r].Type { case "track": { @@ -134,7 +134,7 @@ func (a *SearchView) SelectEntry() { } func (a *SearchView) PlaySelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() switch a.searchContent[r].Type { case "album", "artist", "playlist": { diff --git a/ui/view_top.go b/ui/view_top.go index 25e063f..f3e36f6 100644 --- a/ui/view_top.go +++ b/ui/view_top.go @@ -70,7 +70,7 @@ func (a *TopTracksView) Content() func() [][]Content { } func (a *TopTracksView) PlaySelectedEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if r > 0 { if r < (len(a.topArtists) + 1) { if err := spt.PlayContext(&a.topArtists[r-1].URI); err != nil { @@ -82,7 +82,7 @@ func (a *TopTracksView) PlaySelectedEntry() { } func (a *TopTracksView) OpenSelectEntry() { - r, _ := Main.Table.GetSelection() + r, _ := Main.GetSelection() if r > 0 { if r < (len(a.topArtists) + 1) { artistView.SetArtist(&(a.topArtists)[r-1].ID)