add cover and details to album page
This commit is contained in:
+75
-10
@@ -1,15 +1,19 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"supersonic/backend"
|
||||
"supersonic/ui/util"
|
||||
"supersonic/ui/widgets"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/canvas"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/go-subsonic"
|
||||
)
|
||||
|
||||
type AlbumPage struct {
|
||||
@@ -18,21 +22,19 @@ type AlbumPage struct {
|
||||
albumID string
|
||||
im *backend.ImageManager
|
||||
lm *backend.LibraryManager
|
||||
titleDisp *widget.RichText
|
||||
nav func(Route)
|
||||
header *AlbumPageHeader
|
||||
tracklist *widgets.Tracklist
|
||||
container *fyne.Container
|
||||
|
||||
OnPlayAlbum func(string, int)
|
||||
}
|
||||
|
||||
func NewAlbumPage(albumID string, lm *backend.LibraryManager) *AlbumPage {
|
||||
a := &AlbumPage{albumID: albumID, lm: lm}
|
||||
func NewAlbumPage(albumID string, lm *backend.LibraryManager, im *backend.ImageManager, nav func(Route)) *AlbumPage {
|
||||
a := &AlbumPage{albumID: albumID, lm: lm, im: im, nav: nav}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.titleDisp = widget.NewRichTextWithText("Artist")
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||
SizeName: theme.SizeNameHeadingText,
|
||||
}
|
||||
a.container = container.NewBorder(a.titleDisp, nil, nil, nil, layout.NewSpacer())
|
||||
a.header = NewAlbumPageHeader(nav)
|
||||
a.container = container.NewBorder(a.header, nil, nil, nil, layout.NewSpacer())
|
||||
a.loadAsync()
|
||||
return a
|
||||
}
|
||||
@@ -62,11 +64,74 @@ func (a *AlbumPage) loadAsync() {
|
||||
log.Printf("Failed to get album: %s", err.Error())
|
||||
return
|
||||
}
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Text = album.Name
|
||||
a.titleDisp.Refresh()
|
||||
a.header.Update(album, a.im)
|
||||
tl := widgets.NewTracklist(album.Song)
|
||||
tl.OnPlayTrackAt = a.onPlayTrackAt
|
||||
a.container.Objects[0] = tl
|
||||
a.container.Refresh()
|
||||
}()
|
||||
}
|
||||
|
||||
type AlbumPageHeader struct {
|
||||
widget.BaseWidget
|
||||
|
||||
albumID string
|
||||
artistID string
|
||||
|
||||
cover *canvas.Image
|
||||
titleLabel *widget.RichText
|
||||
artistLabel *widgets.CustomHyperlink
|
||||
genreLabel *widget.Label // later custom hyperlink
|
||||
miscLabel *widget.Label
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewAlbumPageHeader(nav func(Route)) *AlbumPageHeader {
|
||||
a := &AlbumPageHeader{}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.cover = &canvas.Image{FillMode: canvas.ImageFillContain}
|
||||
a.cover.SetMinSize(fyne.NewSize(225, 225))
|
||||
a.titleLabel = widget.NewRichTextWithText("Album Title")
|
||||
a.titleLabel.Wrapping = fyne.TextTruncate
|
||||
a.titleLabel.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||
SizeName: theme.SizeNameHeadingText,
|
||||
}
|
||||
a.artistLabel = widgets.NewCustomHyperlink()
|
||||
a.artistLabel.OnTapped = func() {
|
||||
nav(ArtistRoute(a.artistID))
|
||||
}
|
||||
a.genreLabel = widget.NewLabel("")
|
||||
a.miscLabel = widget.NewLabel("")
|
||||
|
||||
a.container = container.NewBorder(nil, nil, a.cover, nil,
|
||||
container.NewVBox(a.titleLabel, a.artistLabel, a.genreLabel, a.miscLabel),
|
||||
)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *AlbumPageHeader) CreateRenderer() fyne.WidgetRenderer {
|
||||
return widget.NewSimpleRenderer(a.container)
|
||||
}
|
||||
|
||||
func (a *AlbumPageHeader) Update(album *subsonic.AlbumID3, im *backend.ImageManager) {
|
||||
a.albumID = album.ID
|
||||
a.artistID = album.ArtistID
|
||||
a.titleLabel.Segments[0].(*widget.TextSegment).Text = album.Name
|
||||
a.artistLabel.SetText(album.Artist)
|
||||
a.genreLabel.SetText(album.Genre)
|
||||
a.miscLabel.SetText(formatMiscLabelStr(album))
|
||||
a.Refresh()
|
||||
go func() {
|
||||
if cover, err := im.GetAlbumThumbnail(album.ID); err == nil {
|
||||
a.cover.Image = cover
|
||||
a.cover.Refresh()
|
||||
} else {
|
||||
log.Printf("error fetching cover: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func formatMiscLabelStr(a *subsonic.AlbumID3) string {
|
||||
return fmt.Sprintf("%d · %d tracks · %s", a.Year, a.SongCount, util.SecondsToTimeString(float64(a.Duration)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user