Using Updated Ui values

This commit is contained in:
aditya-K2
2023-04-19 09:17:07 +05:30
parent f7133df79e
commit edaa93de69
17 changed files with 31 additions and 30 deletions

View File

@@ -11,7 +11,7 @@ func main() {
if err := spt.InitClient(); err != nil {
panic(err)
}
if err := ui.NewApplication().App.Run(); err != nil {
if err := ui.NewApplication().Run(); err != nil {
panic(err)
}
}

View File

@@ -60,7 +60,7 @@ func getFontWidth() (int, int, error) {
if err != nil {
return 0, 0, err
}
_, _, rw, rh := Ui.Root.Root.GetRect()
_, _, rw, rh := root.Root.GetRect()
if rw == 0 || rh == 0 {
return 0, 0, errors.New("Unable to get row width and height")
}

View File

@@ -23,5 +23,5 @@ func OpenDeviceMenu() {
RefreshProgress(true)
}
})
Ui.Root.AddCenteredWidget(m)
root.AddCenteredWidget(m)
}

View File

@@ -3,8 +3,8 @@ package ui
import (
"errors"
"github.com/gdamore/tcell/v2"
"github.com/aditya-K2/tview"
"github.com/gdamore/tcell/v2"
)
var (
@@ -162,7 +162,7 @@ func (i *interactiveView) getHandler(s string) func(e *tcell.EventKey) *tcell.Ev
},
"openCtx": func(e *tcell.EventKey) *tcell.EventKey {
if GetCurrentView().ContextOpener() != nil {
GetCurrentView().ContextOpener()(Ui.Root, Ui.Main.SelectionHandler)
GetCurrentView().ContextOpener()(root, Main.SelectionHandler)
return nil
}
return e

View File

@@ -56,6 +56,7 @@ func NewPlaylistNav() *PlaylistNav {
T := tview.NewTable()
T.SetSelectable(true, false).SetBorder(true)
T.SetTitle("Playlists").SetTitleAlign(tview.AlignLeft)
T.SetBackgroundColor(tcell.ColorDefault)
v := &PlaylistNav{&defView{}, T, nil, make(chan bool), func(err error) {
if err != nil {
SendNotification(err.Error())

View File

@@ -6,8 +6,8 @@ import (
"github.com/aditya-K2/utils"
"github.com/gdamore/tcell/v2"
"github.com/aditya-K2/tview"
"github.com/gdamore/tcell/v2"
)
var (
@@ -138,18 +138,18 @@ func notify(n *notification) {
npos = posArr.GetNextPosition()
}
n.position = npos
Ui.Root.Root.AddPage(currentTime, n, false, true)
Ui.App.Draw()
Ui.App.SetFocus(Ui.Main.Table)
root.Root.AddPage(currentTime, n, false, true)
App.Draw()
App.SetFocus(Main.Table)
if n.msg != nil {
n.text = <-n.msg
Ui.App.Draw()
App.Draw()
}
time.Sleep(n.timer)
Ui.Root.Root.RemovePage(currentTime)
root.Root.RemovePage(currentTime)
posArr.Free(npos)
Ui.App.SetFocus(Ui.Main.Table)
Ui.App.Draw()
App.SetFocus(Main.Table)
App.Draw()
}()
}

View File

@@ -11,8 +11,8 @@ import (
"github.com/aditya-K2/gspt/config"
"github.com/aditya-K2/gspt/spt"
"github.com/aditya-K2/utils"
"github.com/aditya-K2/tview"
"github.com/aditya-K2/utils"
)
var (
@@ -89,7 +89,7 @@ func RefreshProgress(force bool) {
stateLock.Lock()
state = s
stateLock.Unlock()
if Ui != nil && Ui.CoverArt != nil {
if coverArt != nil {
// If No Item is playing
if (state.Item == nil) ||
// An Item is Playing but doesn't match the cached Track ID
@@ -100,7 +100,7 @@ func RefreshProgress(force bool) {
ctrackId = state.Item.ID
}
if !config.Config.HideImage {
Ui.CoverArt.RefreshState()
coverArt.RefreshState()
}
}
}

View File

@@ -22,14 +22,14 @@ func NewSearchBar() *tview.InputField {
switch k {
case tcell.KeyEscape:
{
Ui.App.SetFocus(Ui.Main.Table)
App.SetFocus(Main.Table)
T.SetText("")
}
case tcell.KeyEnter:
{
searchView.SetSearch(T.GetText())
SetCurrentView(searchView)
Ui.App.SetFocus(Ui.Main.Table)
App.SetFocus(Main.Table)
T.SetText("")
}
}

View File

@@ -88,7 +88,7 @@ func (a *AlbumView) ContextHandler() func(start, end, sel int) {
}
func (a *AlbumView) PlaySelectEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if err := spt.PlaySongWithContext(&a.currentFullAlbum.URI, r); err != nil {
SendNotification(err.Error())
}

View File

@@ -48,13 +48,13 @@ func (a *AlbumsView) Content() func() [][]Content {
}
func (a *AlbumsView) OpenAlbum() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
albumView.SetAlbum((*a.savedAlbums)[r].Name, &(*a.savedAlbums)[r].ID)
SetCurrentView(albumView)
}
func (a *AlbumsView) PlaySelectEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if err := spt.PlayContext(&(*a.savedAlbums)[r].URI); err != nil {
SendNotification(err.Error())
}

View File

@@ -67,7 +67,7 @@ func (a *ArtistView) Content() func() [][]Content {
}
func (a *ArtistView) PlayEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if r > 0 {
if r < (len(a.albums) + 1) {
if err := spt.PlayContext(&a.albums[r-1].URI); err != nil {
@@ -78,7 +78,7 @@ func (a *ArtistView) PlayEntry() {
}
func (a *ArtistView) OpenEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if r > 0 {
if r < (len(a.albums) + 1) {
albumView.SetAlbum(a.albums[r-1].Name, &a.albums[r-1].ID)

View File

@@ -47,7 +47,7 @@ func (a *ArtistsView) Content() func() [][]Content {
}
func (a *ArtistsView) OpenArtist() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
artistView.SetArtist(&(*a.followedArtists)[r].ID)
artistView.RefreshState()
SetCurrentView(artistView)

View File

@@ -75,7 +75,7 @@ func (l *LikedSongsView) ContextHandler() func(start, end, sel int) {
}
func (l *LikedSongsView) OpenEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if err := spt.PlaySong((*l.likedSongs)[r].URI); err != nil {
SendNotification(err.Error())
}

View File

@@ -86,7 +86,7 @@ func (p *PlaylistView) ContextHandler() func(start, end, sel int) {
}
func (p *PlaylistView) PlaySelectEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if err := spt.PlaySongWithContext(&p.currentPlaylist.URI, r); err != nil {
SendNotification(err.Error())
}

View File

@@ -84,7 +84,7 @@ func (r *RecentlyPlayedView) RefreshState() {
}
func (re *RecentlyPlayedView) SelectEntry(e *tcell.EventKey) *tcell.EventKey {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
contextUri := re.recentlyPlayed[r].PlaybackContext.URI
if string(contextUri) != "" {
if err := spt.PlaySongWithContextURI(&re.recentlyPlayed[r].PlaybackContext.URI, &re.recentlyPlayed[r].Track.URI); err != nil {

View File

@@ -102,7 +102,7 @@ func (a *SearchView) Content() func() [][]Content {
}
func (a *SearchView) SelectEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
switch a.searchContent[r].Type {
case "track":
{

View File

@@ -70,7 +70,7 @@ func (a *TopTracksView) Content() func() [][]Content {
}
func (a *TopTracksView) PlaySelectedEntry() {
r, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.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, _ := Ui.Main.Table.GetSelection()
r, _ := Main.Table.GetSelection()
if r > 0 {
if r < (len(a.topArtists) + 1) {
artistView.SetArtist(&(a.topArtists)[r-1].ID)