mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 13:58:05 -05:00
Refactoring
This commit is contained in:
36
ui/app.go
36
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 {
|
||||
|
||||
@@ -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())
|
||||
|
||||
20
ui/utils.go
20
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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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":
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user