diff --git a/ui/app.go b/ui/app.go index a22128e..33b35da 100644 --- a/ui/app.go +++ b/ui/app.go @@ -128,24 +128,6 @@ func NewApplication() *tview.Application { root.AfterContextClose(func() { App.SetFocus(Main) }) // Define Actions - openCurrentArtist := func() { - if state != nil && state.Item != nil { - if len(state.Item.Artists) != 0 { - artistView.SetArtist(&state.Item.Artists[0].ID) - SetCurrentView(artistView) - App.SetFocus(Main) - } else { - SendNotification("No Artist Found!") - } - } - } - openCurrentAlbum := func() { - if state != nil && state.Item != nil { - albumView.SetAlbum(state.Item.Album.Name, &state.Item.Album.ID) - SetCurrentView(albumView) - App.SetFocus(Main) - } - } globalActions := map[string]*Action{ "focus_search": NewAction(func(e *tcell.EventKey) *tcell.EventKey { App.SetFocus(searchbar) @@ -232,7 +214,7 @@ func NewApplication() *tview.Application { }, progressBar), } playlistNav.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "play_entry": NewAction(playlistNav.PlaySelectEntry, + "play_entry": NewAction(playlistNav.PlayEntry, progressBar), "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { r, _ := playlistNav.GetSelection() @@ -243,12 +225,12 @@ func NewApplication() *tview.Application { }, nil), })) navMenu.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(navMenu.SelectEntry, + "open_entry": NewAction(navMenu.OpenEntry, nil), })) playlistView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ "open_entry": NewAction(func(*tcell.EventKey) *tcell.EventKey { - playlistView.PlaySelectEntry() + playlistView.OpenEntry() return nil }, progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { @@ -257,7 +239,7 @@ func NewApplication() *tview.Application { }, nil), })) recentlyPlayedView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ - "open_entry": NewAction(recentlyPlayedView.SelectEntry, + "open_entry": NewAction(recentlyPlayedView.OpenEntry, progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { recentlyPlayedView.AddToPlaylist() @@ -266,7 +248,7 @@ func NewApplication() *tview.Application { })) topTracksView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - topTracksView.OpenSelectEntry() + topTracksView.OpenEntry() return nil }, progressBar), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { @@ -286,11 +268,11 @@ func NewApplication() *tview.Application { })) searchView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - searchView.SelectEntry() + searchView.OpenEntry() return nil }, nil), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - searchView.PlaySelectEntry() + searchView.PlayEntry() return nil }, progressBar), })) @@ -316,7 +298,7 @@ func NewApplication() *tview.Application { return nil }, nil), "play_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - albumsView.PlaySelectEntry() + albumsView.PlayEntry() return nil }, progressBar), "queue_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { @@ -326,7 +308,7 @@ func NewApplication() *tview.Application { })) albumView.SetActions(utils.MergeMaps(globalActions, map[string]*Action{ "open_entry": NewAction(func(e *tcell.EventKey) *tcell.EventKey { - albumView.PlaySelectEntry() + albumView.PlayEntry() return nil }, progressBar), "add_to_playlist": NewAction(func(e *tcell.EventKey) *tcell.EventKey { diff --git a/ui/nav.go b/ui/nav.go index 3f410a9..b4df812 100644 --- a/ui/nav.go +++ b/ui/nav.go @@ -36,7 +36,7 @@ func NewNavMenu(m []navItem) *NavMenu { return n } -func (n *NavMenu) SelectEntry(e *tcell.EventKey) *tcell.EventKey { +func (n *NavMenu) OpenEntry(e *tcell.EventKey) *tcell.EventKey { r, _ := n.Table.GetSelection() if r < len(n.m) { return (*n.m[r].action).Func()(e) @@ -75,7 +75,7 @@ func NewPlaylistNav() *PlaylistNav { return v } -func (v *PlaylistNav) PlaySelectEntry(e *tcell.EventKey) *tcell.EventKey { +func (v *PlaylistNav) PlayEntry(e *tcell.EventKey) *tcell.EventKey { r, _ := v.Table.GetSelection() if err := spt.PlayContext(&(*v.Playlists)[r].URI); err != nil { SendNotification(err.Error()) diff --git a/ui/utils.go b/ui/utils.go index d60fad1..d351695 100644 --- a/ui/utils.go +++ b/ui/utils.go @@ -88,3 +88,23 @@ func getFontWidth() (int, int, error) { fh := h / rh return fw, fh, nil } + +func openCurrentArtist() { + if state != nil && state.Item != nil { + if len(state.Item.Artists) != 0 { + artistView.SetArtist(&state.Item.Artists[0].ID) + SetCurrentView(artistView) + App.SetFocus(Main) + } else { + SendNotification("No Artist Found!") + } + } +} + +func openCurrentAlbum() { + if state != nil && state.Item != nil { + albumView.SetAlbum(state.Item.Album.Name, &state.Item.Album.ID) + SetCurrentView(albumView) + App.SetFocus(Main) + } +} diff --git a/ui/view_album.go b/ui/view_album.go index 6eb3087..c91f83c 100644 --- a/ui/view_album.go +++ b/ui/view_album.go @@ -74,7 +74,7 @@ func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcel return nil } -func (a *AlbumView) PlaySelectEntry() { +func (a *AlbumView) PlayEntry() { 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 219cd11..f794ef2 100644 --- a/ui/view_albums.go +++ b/ui/view_albums.go @@ -52,7 +52,7 @@ func (a *AlbumsView) OpenAlbum() { SetCurrentView(albumView) } -func (a *AlbumsView) PlaySelectEntry() { +func (a *AlbumsView) PlayEntry() { r, _ := Main.GetSelection() if err := spt.PlayContext(&(*a.savedAlbums)[r].URI); err != nil { SendNotification(err.Error()) diff --git a/ui/view_playlist.go b/ui/view_playlist.go index d0f1cec..85fc478 100644 --- a/ui/view_playlist.go +++ b/ui/view_playlist.go @@ -72,7 +72,7 @@ func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *t return nil } -func (p *PlaylistView) PlaySelectEntry() { +func (p *PlaylistView) OpenEntry() { 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 378ace2..a30cd83 100644 --- a/ui/view_recent.go +++ b/ui/view_recent.go @@ -9,7 +9,7 @@ import ( var ( RecentlyPlayedViewActions = map[string]*Action{ - "selectEntry": NewAction(recentlyPlayedView.SelectEntry, nil), + "selectEntry": NewAction(recentlyPlayedView.OpenEntry, nil), } ) @@ -65,7 +65,7 @@ func (r *RecentlyPlayedView) RefreshState() { r.recentlyPlayed = _r } -func (re *RecentlyPlayedView) SelectEntry(e *tcell.EventKey) *tcell.EventKey { +func (re *RecentlyPlayedView) OpenEntry(e *tcell.EventKey) *tcell.EventKey { r, _ := Main.GetSelection() trackUri := re.recentlyPlayed[r].Track.URI contextUri := re.recentlyPlayed[r].PlaybackContext.URI diff --git a/ui/view_search.go b/ui/view_search.go index 73d05e3..6b334a4 100644 --- a/ui/view_search.go +++ b/ui/view_search.go @@ -101,7 +101,7 @@ func (a *SearchView) Content() func() [][]Content { } } -func (a *SearchView) SelectEntry() { +func (a *SearchView) OpenEntry() { r, _ := Main.GetSelection() switch a.searchContent[r].Type { case "track": @@ -133,7 +133,7 @@ func (a *SearchView) SelectEntry() { } } -func (a *SearchView) PlaySelectEntry() { +func (a *SearchView) PlayEntry() { 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 f3e36f6..0149edf 100644 --- a/ui/view_top.go +++ b/ui/view_top.go @@ -81,7 +81,7 @@ func (a *TopTracksView) PlaySelectedEntry() { } -func (a *TopTracksView) OpenSelectEntry() { +func (a *TopTracksView) OpenEntry() { r, _ := Main.GetSelection() if r > 0 { if r < (len(a.topArtists) + 1) {