From aee62216917e658cfb14ea4292fe2237823a3c76 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 9 Apr 2023 13:14:39 -0700 Subject: [PATCH] Fix #55: show disc number and disc count for multi-disc albums --- CHANGELOG.md | 1 + ui/browsing/albumpage.go | 7 ++++++- ui/widgets/tracklist.go | 19 +++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc792d4..868480d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - **todo-commithash** Don't show update available prompt if the found version is the same as the running app version - [#120](https://github.com/dweymouth/supersonic/issues/120),[#87](https://github.com/dweymouth/supersonic/issues/87) Update Mac build process to support OS versions back to High Sierra (thanks @whorfin!) - [#125](https://github.com/dweymouth/supersonic/issues/125) Navigating back twice to an albums page with search result clears search state +- [#55](https://github.com/dweymouth/supersonic/issues/55) Show disc number and disc count for multi-disc albums ## [0.1.0-beta] - 2023-04-01 diff --git a/ui/browsing/albumpage.go b/ui/browsing/albumpage.go index a4eaf03..b3b6368 100644 --- a/ui/browsing/albumpage.go +++ b/ui/browsing/albumpage.go @@ -121,6 +121,7 @@ func (a *AlbumPage) load() { return } a.header.Update(album, a.im) + a.tracklist.ShowDiscNumber = album.Song[0].DiscNumber != album.Song[len(album.Song)-1].DiscNumber a.tracklist.Tracks = album.Song a.tracklist.SetNowPlaying(a.nowPlayingID) } @@ -236,7 +237,11 @@ func (a *AlbumPageHeader) showPopUpCover() { } func formatMiscLabelStr(a *subsonic.AlbumID3) string { - return fmt.Sprintf("%d · %d tracks · %s", a.Year, a.SongCount, util.SecondsToTimeString(float64(a.Duration))) + var discs string + if discCount := a.Song[len(a.Song)-1].DiscNumber; discCount > 1 { + discs = fmt.Sprintf("%d discs · ", discCount) + } + return fmt.Sprintf("%d · %d tracks · %s%s", a.Year, a.SongCount, discs, util.SecondsToTimeString(float64(a.Duration))) } func (s *albumPageState) Restore() Page { diff --git a/ui/widgets/tracklist.go b/ui/widgets/tracklist.go index eaed121..f47d693 100644 --- a/ui/widgets/tracklist.go +++ b/ui/widgets/tracklist.go @@ -1,6 +1,7 @@ package widgets import ( + "fmt" "log" "strconv" "supersonic/res" @@ -40,6 +41,10 @@ type Tracklist struct { // or to use the number from the track's metadata AutoNumber bool + // ShowDiscNumber sets whether to display the disc number as part of the '#' column, + // (with format %d.%02d). Only applies if AutoNumber==false. + ShowDiscNumber bool + // AuxiliaryMenuItems sets additional menu items appended to the context menu // must be set before the context menu is shown for the first time AuxiliaryMenuItems []*fyne.MenuItem @@ -77,7 +82,7 @@ func NewTracklist(tracks []*subsonic.Child) *Tracklist { t.ExtendBaseWidget(t) t.selectionMgr = util.NewListSelectionManager(func() int { return len(t.Tracks) }) // #, Title, Artist, Album, Time, Year, Favorite, Plays, Bitrate, Size, Path - t.colLayout = layouts.NewColumnsLayout([]float32{35, -1, -1, -1, 60, 60, 47, 65, 75, 70, -1}) + t.colLayout = layouts.NewColumnsLayout([]float32{40, -1, -1, -1, 60, 60, 47, 65, 75, 70, -1}) t.buildHeader() t.hdr.OnColumnVisibilityChanged = t.setColumnVisible t.hdr.OnColumnVisibilityMenuShown = func(pop *widget.PopUp) { @@ -438,11 +443,21 @@ func (t *TrackRow) Update(tr *subsonic.Child, isPlaying bool, rowNum int) { // Update track num if needed // (which can change based on bound *subsonic.Child or tracklist.AutoNumber) if t.trackNum != rowNum { + discNum := -1 + var str string if rowNum < 0 { rowNum = tr.Track + if t.tracklist.ShowDiscNumber { + discNum = tr.DiscNumber + } } t.trackNum = rowNum - t.num.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(rowNum) + if discNum >= 0 { + str = fmt.Sprintf("%d.%02d", discNum, rowNum) + } else { + str = strconv.Itoa(rowNum) + } + t.num.Segments[0].(*widget.TextSegment).Text = str } // Update play count if needed