fix toggle column visibility bug with 0 play count tracks
This commit is contained in:
@@ -113,18 +113,3 @@ func (l *ListHeader) createOnChangedCallbk(colNum int) func(bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type colVisibleToggle struct {
|
|
||||||
widget.Check
|
|
||||||
}
|
|
||||||
|
|
||||||
func newColVisibleToggle(colNum int, colName string, visibilities []bool, onChanged func(bool)) *colVisibleToggle {
|
|
||||||
c := &colVisibleToggle{
|
|
||||||
Check: widget.Check{
|
|
||||||
Text: colName,
|
|
||||||
OnChanged: onChanged,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
c.ExtendBaseWidget(c)
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|||||||
+23
-30
@@ -55,16 +55,13 @@ type Tracklist struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
|
||||||
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1, visibleColumns: make([]bool, 5)}
|
t := &Tracklist{Tracks: tracks, nowPlayingIdx: -1, visibleColumns: make([]bool, 7)}
|
||||||
|
|
||||||
t.ExtendBaseWidget(t)
|
t.ExtendBaseWidget(t)
|
||||||
t.selectionMgr = util.NewListSelectionManager(func() int { return len(t.Tracks) })
|
t.selectionMgr = util.NewListSelectionManager(func() int { return len(t.Tracks) })
|
||||||
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, -1, 60, 65, 75})
|
t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, -1, 60, 65, 75})
|
||||||
t.buildHeader()
|
t.buildHeader()
|
||||||
t.hdr.OnColumnVisibilityChanged = func(col int, vis bool) {
|
t.hdr.OnColumnVisibilityChanged = t.setColumnVisible
|
||||||
// first 2 columns are builtin and always visible
|
|
||||||
t.SetColumnVisible(col-2, vis)
|
|
||||||
}
|
|
||||||
playingIcon := container.NewCenter(container.NewHBox(NewHSpace(2), widget.NewIcon(theme.MediaPlayIcon())))
|
playingIcon := container.NewCenter(container.NewHBox(NewHSpace(2), widget.NewIcon(theme.MediaPlayIcon())))
|
||||||
t.list = widget.NewList(
|
t.list = widget.NewList(
|
||||||
func() int { return len(t.Tracks) },
|
func() int { return len(t.Tracks) },
|
||||||
@@ -102,15 +99,19 @@ func (t *Tracklist) buildHeader() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracklist) SetVisibleColumns(cols []TracklistColumn) {
|
func (t *Tracklist) SetVisibleColumns(cols []TracklistColumn) {
|
||||||
for i := range t.visibleColumns {
|
t.visibleColumns[0] = true
|
||||||
|
t.visibleColumns[1] = true
|
||||||
|
for i := 2; i < len(t.visibleColumns); i++ {
|
||||||
t.visibleColumns[i] = false
|
t.visibleColumns[i] = false
|
||||||
|
t.hdr.SetColumnVisible(i, false)
|
||||||
}
|
}
|
||||||
for _, col := range cols {
|
for _, col := range cols {
|
||||||
t.visibleColumns[col.ColNumber()] = true
|
t.visibleColumns[col.ColNumber()] = true
|
||||||
|
t.hdr.SetColumnVisible(col.ColNumber(), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracklist) SetColumnVisible(colNum int, vis bool) {
|
func (t *Tracklist) setColumnVisible(colNum int, vis bool) {
|
||||||
if colNum >= len(t.visibleColumns) {
|
if colNum >= len(t.visibleColumns) {
|
||||||
log.Printf("error: Tracklist.SetColumnVisible: column index %d out of range", colNum)
|
log.Printf("error: Tracklist.SetColumnVisible: column index %d out of range", colNum)
|
||||||
return
|
return
|
||||||
@@ -153,14 +154,6 @@ func (t *Tracklist) UnselectAll() {
|
|||||||
t.Refresh()
|
t.Refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracklist) Refresh() {
|
|
||||||
for i, tf := range t.visibleColumns {
|
|
||||||
// first 2 columns are built-in and always visible
|
|
||||||
t.hdr.SetColumnVisible(i+2, tf)
|
|
||||||
}
|
|
||||||
t.BaseWidget.Refresh()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
func (t *Tracklist) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(t.container)
|
return widget.NewSimpleRenderer(t.container)
|
||||||
}
|
}
|
||||||
@@ -258,15 +251,15 @@ func (c TracklistColumn) ColNumber() int {
|
|||||||
// built-in columns # and Title are always visible
|
// built-in columns # and Title are always visible
|
||||||
switch c {
|
switch c {
|
||||||
case ColumnArtist:
|
case ColumnArtist:
|
||||||
return 0
|
|
||||||
case ColumnAlbum:
|
|
||||||
return 1
|
|
||||||
case ColumnTime:
|
|
||||||
return 2
|
return 2
|
||||||
case ColumnPlays:
|
case ColumnAlbum:
|
||||||
return 3
|
return 3
|
||||||
case ColumnBitrate:
|
case ColumnTime:
|
||||||
return 4
|
return 4
|
||||||
|
case ColumnPlays:
|
||||||
|
return 5
|
||||||
|
case ColumnBitrate:
|
||||||
|
return 6
|
||||||
default:
|
default:
|
||||||
return -100
|
return -100
|
||||||
}
|
}
|
||||||
@@ -327,11 +320,10 @@ func NewTrackRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *TrackRow
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
||||||
if tr.ID == t.trackID && isPlaying == t.isPlaying && tr.PlayCount == t.playCount {
|
if tr.ID != t.trackID || isPlaying != t.isPlaying || tr.PlayCount != t.playCount {
|
||||||
return
|
|
||||||
}
|
|
||||||
t.isPlaying = isPlaying
|
t.isPlaying = isPlaying
|
||||||
t.trackID = tr.ID
|
t.trackID = tr.ID
|
||||||
|
t.playCount = tr.PlayCount
|
||||||
|
|
||||||
if rowNum < 0 {
|
if rowNum < 0 {
|
||||||
rowNum = tr.Track
|
rowNum = tr.Track
|
||||||
@@ -351,17 +343,18 @@ func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) {
|
|||||||
t.plays.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
t.plays.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
||||||
t.bitrate.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
t.bitrate.Segments[0].(*widget.TextSegment).Style.TextStyle.Bold = isPlaying
|
||||||
|
|
||||||
t.artist.Hidden = !t.tracklist.visibleColumns[ColumnArtist.ColNumber()]
|
|
||||||
t.album.Hidden = !t.tracklist.visibleColumns[ColumnAlbum.ColNumber()]
|
|
||||||
t.dur.Hidden = !t.tracklist.visibleColumns[ColumnTime.ColNumber()]
|
|
||||||
t.plays.Hidden = !t.tracklist.visibleColumns[ColumnPlays.ColNumber()]
|
|
||||||
t.bitrate.Hidden = !t.tracklist.visibleColumns[ColumnBitrate.ColNumber()]
|
|
||||||
|
|
||||||
if isPlaying {
|
if isPlaying {
|
||||||
t.container.Objects[1].(*fyne.Container).Objects[0] = container.NewCenter(t.playingIcon)
|
t.container.Objects[1].(*fyne.Container).Objects[0] = container.NewCenter(t.playingIcon)
|
||||||
} else {
|
} else {
|
||||||
t.container.Objects[1].(*fyne.Container).Objects[0] = t.num
|
t.container.Objects[1].(*fyne.Container).Objects[0] = t.num
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.artist.Hidden = !t.tracklist.visibleColumns[ColumnArtist.ColNumber()]
|
||||||
|
t.album.Hidden = !t.tracklist.visibleColumns[ColumnAlbum.ColNumber()]
|
||||||
|
t.dur.Hidden = !t.tracklist.visibleColumns[ColumnTime.ColNumber()]
|
||||||
|
t.plays.Hidden = !t.tracklist.visibleColumns[ColumnPlays.ColNumber()]
|
||||||
|
t.bitrate.Hidden = !t.tracklist.visibleColumns[ColumnBitrate.ColNumber()]
|
||||||
|
|
||||||
t.Refresh()
|
t.Refresh()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user