Skip to content

Commit

Permalink
Merge pull request #375 from adamantike/misc/nowplayingcard-update-re…
Browse files Browse the repository at this point in the history
…ceive-track

misc: Make NowPlayingCard.Update receive Track object
  • Loading branch information
dweymouth authored Apr 27, 2024
2 parents a00b395 + 3856ecd commit e196475
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ui/bottompanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func NewBottomPanel(pm *backend.PlaybackManager, contr *controller.Controller) *

func (bp *BottomPanel) onSongChange(song, _ *mediaprovider.Track) {
if song == nil {
bp.NowPlaying.Update("", []string{}, []string{}, "", nil)
bp.NowPlaying.Update(nil, nil)
} else {
bp.coverArtID = song.CoverArtID
var im image.Image
Expand All @@ -116,7 +116,7 @@ func (bp *BottomPanel) onSongChange(song, _ *mediaprovider.Track) {
imgTTLSec := song.Duration + 30
im, _ = bp.ImageManager.GetCoverThumbnailWithTTL(song.CoverArtID, time.Duration(imgTTLSec)*time.Second)
}
bp.NowPlaying.Update(song.Name, song.ArtistNames, song.ArtistIDs, song.Album, im)
bp.NowPlaying.Update(song, im)
}
}

Expand Down
20 changes: 14 additions & 6 deletions ui/widgets/nowplayingcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package widgets
import (
"image"

"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
Expand Down Expand Up @@ -117,12 +118,19 @@ func (n *NowPlayingCard) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(c)
}

func (n *NowPlayingCard) Update(track string, artists, artistIDs []string, album string, cover image.Image) {
n.trackName.SetText(track)
n.trackName.Hidden = track == ""
n.artistName.BuildSegments(artists, artistIDs)
n.albumName.SetText(album)
n.albumName.Hidden = album == ""
func (n *NowPlayingCard) Update(track *mediaprovider.Track, cover image.Image) {
if track != nil {
n.trackName.SetText(track.Name)
n.artistName.BuildSegments(track.ArtistNames, track.ArtistIDs)
n.albumName.SetText(track.Album)
} else {
n.trackName.SetText("")
n.artistName.BuildSegments([]string{}, []string{})
n.albumName.SetText("")
}
n.trackName.Hidden = n.trackName.Text == ""
n.artistName.Hidden = len(n.artistName.Segments) == 0
n.albumName.Hidden = n.albumName.Text == ""
n.cover.Image.Image = cover
n.cover.Hidden = cover == nil
n.Refresh()
Expand Down

0 comments on commit e196475

Please sign in to comment.