add FavoriteIcon and use in fullscreen page
This commit is contained in:
@@ -96,7 +96,7 @@ func (a *FullscreenPage) OnSongChange(song, lastScrobbledIfAny *mediaprovider.Tr
|
||||
}
|
||||
a.albumID = song.AlbumID
|
||||
a.nowPlayingID = sharedutil.TrackIDOrEmptyStr(song)
|
||||
a.card.Update(song.Name, song.ArtistNames, song.ArtistIDs, song.Album)
|
||||
a.card.Update(song)
|
||||
a.imageLoadCancel = a.im.GetFullSizeCoverArtAsync(song.CoverArtID, func(img image.Image, err error) {
|
||||
if err != nil {
|
||||
log.Printf("error loading cover art: %v\n", err)
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"github.com/dweymouth/supersonic/ui/theme"
|
||||
)
|
||||
|
||||
type FavoriteIcon struct {
|
||||
TappableIcon
|
||||
|
||||
Favorite bool
|
||||
}
|
||||
|
||||
func NewFavoriteIcon() *FavoriteIcon {
|
||||
f := &FavoriteIcon{}
|
||||
f.Resource = theme.NotFavoriteIcon
|
||||
f.ExtendBaseWidget(f)
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *FavoriteIcon) Refresh() {
|
||||
if f.Favorite {
|
||||
f.Resource = theme.FavoriteIcon
|
||||
} else {
|
||||
f.Resource = theme.NotFavoriteIcon
|
||||
}
|
||||
f.BaseWidget.Refresh()
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"fyne.io/fyne/v2/layout"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||
"github.com/dweymouth/supersonic/ui/layouts"
|
||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||
)
|
||||
@@ -23,7 +24,7 @@ type LargeNowPlayingCard struct {
|
||||
artistName *MultiHyperlink
|
||||
albumName *widget.Hyperlink
|
||||
rating *StarRating
|
||||
favorite *widget.Icon
|
||||
favorite *FavoriteIcon
|
||||
cover *ImagePlaceholder
|
||||
|
||||
OnArtistNameTapped func(artistID string)
|
||||
@@ -40,11 +41,13 @@ func NewLargeNowPlayingCard() *LargeNowPlayingCard {
|
||||
artistName: NewMultiHyperlink(),
|
||||
albumName: widget.NewHyperlink("", nil),
|
||||
rating: NewStarRating(),
|
||||
favorite: widget.NewIcon(myTheme.NotFavoriteIcon),
|
||||
favorite: NewFavoriteIcon(),
|
||||
cover: NewImagePlaceholder(myTheme.TracksIcon, 300),
|
||||
}
|
||||
n.ExtendBaseWidget(n)
|
||||
n.rating.StarSize = theme.IconInlineSize() + theme.InnerPadding()/2
|
||||
n.rating.OnRatingChanged = n.onSetRating
|
||||
n.favorite.OnTapped = n.onToggleFavorite
|
||||
// set up the layout
|
||||
n.Content = n.cover
|
||||
n.Caption = container.New(&layouts.VboxCustomPadding{ExtraPad: -13},
|
||||
@@ -90,9 +93,11 @@ func (n *LargeNowPlayingCard) onShowCoverImage(*fyne.PointEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *LargeNowPlayingCard) onSetFavorite(fav bool) {
|
||||
func (n *LargeNowPlayingCard) onToggleFavorite() {
|
||||
n.favorite.Favorite = !n.favorite.Favorite
|
||||
n.favorite.Refresh()
|
||||
if n.OnSetFavorite != nil {
|
||||
n.OnSetFavorite(fav)
|
||||
n.OnSetFavorite(n.favorite.Favorite)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,12 +107,15 @@ func (n *LargeNowPlayingCard) onSetRating(rating int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (n *LargeNowPlayingCard) Update(track string, artists, artistIDs []string, album string) {
|
||||
n.trackName.Segments[0].(*widget.TextSegment).Text = track
|
||||
n.trackName.Hidden = track == ""
|
||||
n.artistName.BuildSegments(artists, artistIDs)
|
||||
n.albumName.SetText(album)
|
||||
n.albumName.Hidden = album == ""
|
||||
func (n *LargeNowPlayingCard) Update(track *mediaprovider.Track) {
|
||||
n.trackName.Segments[0].(*widget.TextSegment).Text = track.Name
|
||||
n.trackName.Hidden = track.Name == ""
|
||||
n.artistName.BuildSegments(track.ArtistNames, track.ArtistIDs)
|
||||
n.albumName.Text = track.Album
|
||||
n.albumName.Hidden = track.Album == ""
|
||||
n.rating.Rating = track.Rating
|
||||
n.favorite.Favorite = track.Favorite
|
||||
|
||||
n.Refresh()
|
||||
}
|
||||
|
||||
|
||||
+8
-19
@@ -761,7 +761,7 @@ func NewTrackRow(tracklist *Tracklist, playingIcon fyne.CanvasObject) *TrackRow
|
||||
t.album.OnTapped = func() { tracklist.onAlbumTapped(t.albumID) }
|
||||
t.dur = newTrailingAlignLabel()
|
||||
t.year = newTrailingAlignLabel()
|
||||
favorite := NewTappableIcon(myTheme.NotFavoriteIcon)
|
||||
favorite := NewFavoriteIcon()
|
||||
favorite.OnTapped = t.toggleFavorited
|
||||
t.favorite = container.NewCenter(favorite)
|
||||
t.rating = NewStarRating()
|
||||
@@ -868,13 +868,8 @@ func (t *TrackRow) Update(tm *trackModel, rowNum int) {
|
||||
|
||||
// Update favorite column
|
||||
if tr.Favorite != t.isFavorite {
|
||||
if tr.Favorite {
|
||||
t.isFavorite = true
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
|
||||
} else {
|
||||
t.isFavorite = false
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
|
||||
}
|
||||
t.isFavorite = tr.Favorite
|
||||
t.favorite.Objects[0].(*FavoriteIcon).Favorite = tr.Favorite
|
||||
changed = true
|
||||
}
|
||||
|
||||
@@ -914,17 +909,11 @@ func (t *TrackRow) Update(tm *trackModel, rowNum int) {
|
||||
}
|
||||
|
||||
func (t *TrackRow) toggleFavorited() {
|
||||
if t.isFavorite {
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
|
||||
t.favorite.Refresh()
|
||||
t.isFavorite = false
|
||||
t.tracklist.onSetFavorite(t.trackID, false)
|
||||
} else {
|
||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
|
||||
t.favorite.Refresh()
|
||||
t.isFavorite = true
|
||||
t.tracklist.onSetFavorite(t.trackID, true)
|
||||
}
|
||||
t.isFavorite = !t.isFavorite
|
||||
favIcon := t.favorite.Objects[0].(*FavoriteIcon)
|
||||
favIcon.Favorite = t.isFavorite
|
||||
t.favorite.Refresh()
|
||||
t.tracklist.onSetFavorite(t.trackID, t.isFavorite)
|
||||
}
|
||||
|
||||
func (t *TrackRow) setTrackRating(rating int) {
|
||||
|
||||
Reference in New Issue
Block a user