make tracks page show now playing + tracklist now playing refactor
This commit is contained in:
@@ -3,6 +3,7 @@ package browsing
|
||||
import (
|
||||
"supersonic/backend"
|
||||
"supersonic/res"
|
||||
"supersonic/sharedutil"
|
||||
"supersonic/ui/controller"
|
||||
"supersonic/ui/layouts"
|
||||
"supersonic/ui/widgets"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic/subsonic"
|
||||
)
|
||||
|
||||
type TracksPage struct {
|
||||
@@ -18,6 +20,8 @@ type TracksPage struct {
|
||||
|
||||
tracksPageState
|
||||
|
||||
nowPlayingID string
|
||||
|
||||
title *widget.RichText
|
||||
searcher *widgets.Searcher
|
||||
tracklist *widgets.Tracklist
|
||||
@@ -71,6 +75,19 @@ func (t *TracksPage) Reload() {
|
||||
t.loader = widgets.NewTracklistLoader(t.tracklist, iter)
|
||||
}
|
||||
|
||||
func (t *TracksPage) OnSongChange(track *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
|
||||
t.nowPlayingID = sharedutil.TrackIDOrEmptyStr(track)
|
||||
t.tracklist.SetNowPlaying(t.nowPlayingID)
|
||||
if t.searchTracklist != nil {
|
||||
t.searchTracklist.SetNowPlaying(t.nowPlayingID)
|
||||
}
|
||||
playedID := sharedutil.TrackIDOrEmptyStr(lastScrobbledIfAny)
|
||||
t.tracklist.IncrementPlayCount(playedID)
|
||||
if t.searchTracklist != nil {
|
||||
t.searchTracklist.IncrementPlayCount(playedID)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TracksPage) OnSearched(query string) {
|
||||
t.searchText = query
|
||||
if query == "" {
|
||||
@@ -89,6 +106,7 @@ func (t *TracksPage) doSearch(query string) {
|
||||
t.searchTracklist = widgets.NewTracklist(nil)
|
||||
t.searchTracklist.AutoNumber = true
|
||||
t.searchTracklist.SetVisibleColumns(t.conf.TracklistColumns)
|
||||
t.searchTracklist.SetNowPlaying(t.nowPlayingID)
|
||||
t.contr.ConnectTracklistActions(t.searchTracklist)
|
||||
} else {
|
||||
t.searchTracklist.Clear()
|
||||
|
||||
+13
-21
@@ -71,18 +71,18 @@ type Tracklist struct {
|
||||
|
||||
visibleColumns []bool
|
||||
|
||||
tracksMutex sync.RWMutex
|
||||
selectionMgr util.ListSelectionManager
|
||||
nowPlayingIdx int
|
||||
colLayout *layouts.ColumnsLayout
|
||||
hdr *ListHeader
|
||||
list *widget.List
|
||||
ctxMenu *fyne.Menu
|
||||
container *fyne.Container
|
||||
tracksMutex sync.RWMutex
|
||||
selectionMgr util.ListSelectionManager
|
||||
nowPlayingID string
|
||||
colLayout *layouts.ColumnsLayout
|
||||
hdr *ListHeader
|
||||
list *widget.List
|
||||
ctxMenu *fyne.Menu
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
||||
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1, visibleColumns: make([]bool, 11)}
|
||||
t := &Tracklist{Tracks: tracks, visibleColumns: make([]bool, 11)}
|
||||
|
||||
t.ExtendBaseWidget(t)
|
||||
t.selectionMgr = util.NewListSelectionManager(t.lenTracks)
|
||||
@@ -113,7 +113,7 @@ func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
||||
if t.AutoNumber {
|
||||
i = itemID + 1
|
||||
}
|
||||
tr.Update(t.TrackAt(itemID), itemID == t.nowPlayingIdx, i)
|
||||
tr.Update(t.TrackAt(itemID), i)
|
||||
if t.OnTrackShown != nil {
|
||||
t.OnTrackShown(itemID)
|
||||
}
|
||||
@@ -185,15 +185,7 @@ func (t *Tracklist) setColumnVisible(colNum int, vis bool) {
|
||||
}
|
||||
|
||||
func (t *Tracklist) SetNowPlaying(trackID string) {
|
||||
t.nowPlayingIdx = -1
|
||||
t.tracksMutex.RLock()
|
||||
for i, tr := range t.Tracks {
|
||||
if tr.ID == trackID {
|
||||
t.nowPlayingIdx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
t.tracksMutex.RUnlock()
|
||||
t.nowPlayingID = trackID
|
||||
t.list.Refresh()
|
||||
}
|
||||
|
||||
@@ -466,7 +458,7 @@ func NewTrackRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *TrackRow
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
||||
func (t *TrackRow) Update(tr *subsonic.Child, rowNum int) {
|
||||
// Update info that can change if this row is bound to
|
||||
// a new track (*subsonic.Child)
|
||||
if tr.ID != t.trackID {
|
||||
@@ -516,7 +508,7 @@ func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
||||
}
|
||||
|
||||
// Render whether track is playing or not
|
||||
if isPlaying != t.isPlaying {
|
||||
if isPlaying := t.tracklist.nowPlayingID == tr.ID; isPlaying != t.isPlaying {
|
||||
t.isPlaying = isPlaying
|
||||
t.name.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
||||
t.dur.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
||||
|
||||
Reference in New Issue
Block a user