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.albumID = song.AlbumID
|
||||||
a.nowPlayingID = sharedutil.TrackIDOrEmptyStr(song)
|
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) {
|
a.imageLoadCancel = a.im.GetFullSizeCoverArtAsync(song.CoverArtID, func(img image.Image, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error loading cover art: %v\n", err)
|
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/layout"
|
||||||
"fyne.io/fyne/v2/theme"
|
"fyne.io/fyne/v2/theme"
|
||||||
"fyne.io/fyne/v2/widget"
|
"fyne.io/fyne/v2/widget"
|
||||||
|
"github.com/dweymouth/supersonic/backend/mediaprovider"
|
||||||
"github.com/dweymouth/supersonic/ui/layouts"
|
"github.com/dweymouth/supersonic/ui/layouts"
|
||||||
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
myTheme "github.com/dweymouth/supersonic/ui/theme"
|
||||||
)
|
)
|
||||||
@@ -23,7 +24,7 @@ type LargeNowPlayingCard struct {
|
|||||||
artistName *MultiHyperlink
|
artistName *MultiHyperlink
|
||||||
albumName *widget.Hyperlink
|
albumName *widget.Hyperlink
|
||||||
rating *StarRating
|
rating *StarRating
|
||||||
favorite *widget.Icon
|
favorite *FavoriteIcon
|
||||||
cover *ImagePlaceholder
|
cover *ImagePlaceholder
|
||||||
|
|
||||||
OnArtistNameTapped func(artistID string)
|
OnArtistNameTapped func(artistID string)
|
||||||
@@ -40,11 +41,13 @@ func NewLargeNowPlayingCard() *LargeNowPlayingCard {
|
|||||||
artistName: NewMultiHyperlink(),
|
artistName: NewMultiHyperlink(),
|
||||||
albumName: widget.NewHyperlink("", nil),
|
albumName: widget.NewHyperlink("", nil),
|
||||||
rating: NewStarRating(),
|
rating: NewStarRating(),
|
||||||
favorite: widget.NewIcon(myTheme.NotFavoriteIcon),
|
favorite: NewFavoriteIcon(),
|
||||||
cover: NewImagePlaceholder(myTheme.TracksIcon, 300),
|
cover: NewImagePlaceholder(myTheme.TracksIcon, 300),
|
||||||
}
|
}
|
||||||
n.ExtendBaseWidget(n)
|
n.ExtendBaseWidget(n)
|
||||||
n.rating.StarSize = theme.IconInlineSize() + theme.InnerPadding()/2
|
n.rating.StarSize = theme.IconInlineSize() + theme.InnerPadding()/2
|
||||||
|
n.rating.OnRatingChanged = n.onSetRating
|
||||||
|
n.favorite.OnTapped = n.onToggleFavorite
|
||||||
// set up the layout
|
// set up the layout
|
||||||
n.Content = n.cover
|
n.Content = n.cover
|
||||||
n.Caption = container.New(&layouts.VboxCustomPadding{ExtraPad: -13},
|
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 {
|
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) {
|
func (n *LargeNowPlayingCard) Update(track *mediaprovider.Track) {
|
||||||
n.trackName.Segments[0].(*widget.TextSegment).Text = track
|
n.trackName.Segments[0].(*widget.TextSegment).Text = track.Name
|
||||||
n.trackName.Hidden = track == ""
|
n.trackName.Hidden = track.Name == ""
|
||||||
n.artistName.BuildSegments(artists, artistIDs)
|
n.artistName.BuildSegments(track.ArtistNames, track.ArtistIDs)
|
||||||
n.albumName.SetText(album)
|
n.albumName.Text = track.Album
|
||||||
n.albumName.Hidden = album == ""
|
n.albumName.Hidden = track.Album == ""
|
||||||
|
n.rating.Rating = track.Rating
|
||||||
|
n.favorite.Favorite = track.Favorite
|
||||||
|
|
||||||
n.Refresh()
|
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.album.OnTapped = func() { tracklist.onAlbumTapped(t.albumID) }
|
||||||
t.dur = newTrailingAlignLabel()
|
t.dur = newTrailingAlignLabel()
|
||||||
t.year = newTrailingAlignLabel()
|
t.year = newTrailingAlignLabel()
|
||||||
favorite := NewTappableIcon(myTheme.NotFavoriteIcon)
|
favorite := NewFavoriteIcon()
|
||||||
favorite.OnTapped = t.toggleFavorited
|
favorite.OnTapped = t.toggleFavorited
|
||||||
t.favorite = container.NewCenter(favorite)
|
t.favorite = container.NewCenter(favorite)
|
||||||
t.rating = NewStarRating()
|
t.rating = NewStarRating()
|
||||||
@@ -868,13 +868,8 @@ func (t *TrackRow) Update(tm *trackModel, rowNum int) {
|
|||||||
|
|
||||||
// Update favorite column
|
// Update favorite column
|
||||||
if tr.Favorite != t.isFavorite {
|
if tr.Favorite != t.isFavorite {
|
||||||
if tr.Favorite {
|
t.isFavorite = tr.Favorite
|
||||||
t.isFavorite = true
|
t.favorite.Objects[0].(*FavoriteIcon).Favorite = tr.Favorite
|
||||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
|
|
||||||
} else {
|
|
||||||
t.isFavorite = false
|
|
||||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
|
|
||||||
}
|
|
||||||
changed = true
|
changed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -914,17 +909,11 @@ func (t *TrackRow) Update(tm *trackModel, rowNum int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackRow) toggleFavorited() {
|
func (t *TrackRow) toggleFavorited() {
|
||||||
if t.isFavorite {
|
t.isFavorite = !t.isFavorite
|
||||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
|
favIcon := t.favorite.Objects[0].(*FavoriteIcon)
|
||||||
t.favorite.Refresh()
|
favIcon.Favorite = t.isFavorite
|
||||||
t.isFavorite = false
|
t.favorite.Refresh()
|
||||||
t.tracklist.onSetFavorite(t.trackID, false)
|
t.tracklist.onSetFavorite(t.trackID, t.isFavorite)
|
||||||
} else {
|
|
||||||
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
|
|
||||||
t.favorite.Refresh()
|
|
||||||
t.isFavorite = true
|
|
||||||
t.tracklist.onSetFavorite(t.trackID, true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TrackRow) setTrackRating(rating int) {
|
func (t *TrackRow) setTrackRating(rating int) {
|
||||||
|
|||||||
Reference in New Issue
Block a user