auto-number playlist track list in sequential order
This commit is contained in:
@@ -39,6 +39,7 @@ func NewPlaylistPage(
|
|||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
a.header = NewPlaylistPageHeader(a)
|
a.header = NewPlaylistPageHeader(a)
|
||||||
a.tracklist = widgets.NewTracklist(nil)
|
a.tracklist = widgets.NewTracklist(nil)
|
||||||
|
a.tracklist.AutoNumber = true
|
||||||
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
|
a.tracklist.OnPlayTrackAt = a.onPlayTrackAt
|
||||||
a.container = container.NewBorder(
|
a.container = container.NewBorder(
|
||||||
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15, PadTop: 15, PadBottom: 10}, a.header),
|
||||||
|
|||||||
+12
-3
@@ -45,14 +45,18 @@ func NewTrackRow(layout *layouts.ColumnsLayout) *TrackRow {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool) {
|
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
||||||
if tr.ID == t.prevTrackID && isPlaying == t.prevIsPlaying {
|
if tr.ID == t.prevTrackID && isPlaying == t.prevIsPlaying {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
t.prevTrackID = t.trackID
|
t.prevTrackID = t.trackID
|
||||||
t.prevIsPlaying = isPlaying
|
t.prevIsPlaying = isPlaying
|
||||||
t.trackID = tr.ID
|
t.trackID = tr.ID
|
||||||
t.num.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(tr.Track)
|
|
||||||
|
if rowNum < 0 {
|
||||||
|
rowNum = tr.Track
|
||||||
|
}
|
||||||
|
t.num.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(rowNum)
|
||||||
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
|
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
|
||||||
t.artist.Segments[0].(*widget.TextSegment).Text = tr.Artist
|
t.artist.Segments[0].(*widget.TextSegment).Text = tr.Artist
|
||||||
t.dur.Segments[0].(*widget.TextSegment).Text = util.SecondsToTimeString(float64(tr.Duration))
|
t.dur.Segments[0].(*widget.TextSegment).Text = util.SecondsToTimeString(float64(tr.Duration))
|
||||||
@@ -79,6 +83,7 @@ type Tracklist struct {
|
|||||||
widget.BaseWidget
|
widget.BaseWidget
|
||||||
|
|
||||||
Tracks []*subsonic.Child
|
Tracks []*subsonic.Child
|
||||||
|
AutoNumber bool
|
||||||
OnPlayTrackAt func(int)
|
OnPlayTrackAt func(int)
|
||||||
|
|
||||||
nowPlayingIdx int
|
nowPlayingIdx int
|
||||||
@@ -99,7 +104,11 @@ func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
|||||||
func(itemID widget.ListItemID, item fyne.CanvasObject) {
|
func(itemID widget.ListItemID, item fyne.CanvasObject) {
|
||||||
tr := item.(*TrackRow)
|
tr := item.(*TrackRow)
|
||||||
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
|
tr.OnDoubleTapped = func() { t.onPlayTrackAt(itemID) }
|
||||||
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx)
|
i := itemID + 1
|
||||||
|
if !t.AutoNumber {
|
||||||
|
i = -1 // signal that we want to use the track num.
|
||||||
|
}
|
||||||
|
tr.Update(t.Tracks[itemID], itemID == t.nowPlayingIdx, i)
|
||||||
})
|
})
|
||||||
t.container = container.NewBorder(t.hdr, nil, nil, nil, t.list)
|
t.container = container.NewBorder(t.hdr, nil, nil, nil, t.list)
|
||||||
return t
|
return t
|
||||||
|
|||||||
Reference in New Issue
Block a user