Fix #350: add option to shuffle artist's discography by albums of tracks
This commit is contained in:
+24
-17
@@ -323,26 +323,36 @@ func NewArtistPageHeader(page *ArtistPage) *ArtistPageHeader {
|
|||||||
})
|
})
|
||||||
a.playRadioBtn = widget.NewButtonWithIcon("Play Artist Radio", myTheme.ShuffleIcon, a.artistPage.playArtistRadio)
|
a.playRadioBtn = widget.NewButtonWithIcon("Play Artist Radio", myTheme.ShuffleIcon, a.artistPage.playArtistRadio)
|
||||||
|
|
||||||
// TODO: Uncomment when at least one media provider supports sharing artists.
|
var pop *widget.PopUpMenu
|
||||||
// a.shareMenuItem = fyne.NewMenuItem("Share...", func() {
|
a.menuBtn = widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
|
||||||
|
a.menuBtn.OnTapped = func() {
|
||||||
|
if pop == nil {
|
||||||
|
shuffleTracks := fyne.NewMenuItem("Shuffle tracks", func() {
|
||||||
|
go a.artistPage.contr.PlayArtistDiscography(a.artistID, true /*shuffle*/)
|
||||||
|
})
|
||||||
|
shuffleTracks.Icon = myTheme.TracksIcon
|
||||||
|
shuffleAlbums := fyne.NewMenuItem("Shuffle albums", func() {
|
||||||
|
go a.artistPage.contr.ShuffleArtistAlbums(a.artistID)
|
||||||
|
})
|
||||||
|
shuffleAlbums.Icon = myTheme.AlbumIcon
|
||||||
|
menu := fyne.NewMenu("", shuffleTracks, shuffleAlbums)
|
||||||
|
pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
|
||||||
|
}
|
||||||
|
pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(a.menuBtn)
|
||||||
|
pop.ShowAtPosition(fyne.NewPos(pos.X, pos.Y+a.menuBtn.Size().Height))
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Uncomment and merge into OnTapped above when at least one media provider supports sharing artists.
|
||||||
|
// shareMenuItem = fyne.NewMenuItem("Share...", func() {
|
||||||
// a.artistPage.contr.ShowShareDialog(a.artistID)
|
// a.artistPage.contr.ShowShareDialog(a.artistID)
|
||||||
// })
|
// })
|
||||||
// a.shareMenuItem.Icon = myTheme.ShareIcon
|
// a.shareMenuItem.Icon = myTheme.ShareIcon
|
||||||
// var pop *widget.PopUpMenu
|
//
|
||||||
// a.menuBtn = widget.NewButtonWithIcon("", theme.MoreHorizontalIcon(), nil)
|
|
||||||
// a.menuBtn.OnTapped = func() {
|
|
||||||
// if pop == nil {
|
|
||||||
// menu := fyne.NewMenu("", a.shareMenuItem)
|
|
||||||
// pop = widget.NewPopUpMenu(menu, fyne.CurrentApp().Driver().CanvasForObject(a))
|
|
||||||
// }
|
|
||||||
// pos := fyne.CurrentApp().Driver().AbsolutePositionForObject(a.menuBtn)
|
|
||||||
// pop.ShowAtPosition(fyne.NewPos(pos.X, pos.Y+a.menuBtn.Size().Height))
|
|
||||||
// }
|
|
||||||
// canShareArtists := false
|
// canShareArtists := false
|
||||||
// if r, canShare := a.artistPage.mp.(mediaprovider.SupportsSharing); canShare {
|
// if r, canShare := a.artistPage.mp.(mediaprovider.SupportsSharing); canShare {
|
||||||
// canShareArtists = r.CanShareArtists()
|
// canShareArtists = r.CanShareArtists()
|
||||||
// }
|
// }
|
||||||
// a.shareMenuItem.Disabled = !canShareArtists
|
// shareMenuItem.Disabled = !canShareArtists
|
||||||
|
|
||||||
a.biographyDisp.Wrapping = fyne.TextWrapWord
|
a.biographyDisp.Wrapping = fyne.TextWrapWord
|
||||||
a.biographyDisp.Truncation = fyne.TextTruncateEllipsis
|
a.biographyDisp.Truncation = fyne.TextTruncateEllipsis
|
||||||
@@ -433,10 +443,7 @@ func (a *ArtistPageHeader) toggleFavorited() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *ArtistPageHeader) createContainer() {
|
func (a *ArtistPageHeader) createContainer() {
|
||||||
btnContainer := container.NewHBox(util.NewHSpace(2), a.favoriteBtn, a.playBtn, a.playRadioBtn)
|
btnContainer := container.NewHBox(util.NewHSpace(2), a.favoriteBtn, a.playBtn, a.playRadioBtn, a.menuBtn)
|
||||||
if a.menuBtn != nil {
|
|
||||||
btnContainer.Add(a.menuBtn)
|
|
||||||
}
|
|
||||||
|
|
||||||
a.container = util.AddHeaderBackground(
|
a.container = util.AddHeaderBackground(
|
||||||
container.NewBorder(nil, nil, a.artistImage, nil,
|
container.NewBorder(nil, nil, a.artistImage, nil,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"math/rand"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -231,8 +232,35 @@ func (m *Controller) GetArtistTracks(artistID string) []*mediaprovider.Track {
|
|||||||
return allTracks
|
return allTracks
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Controller) PlayArtistDiscography(artistID string, shuffle bool) {
|
func (m *Controller) PlayArtistDiscography(artistID string, shuffleTracks bool) {
|
||||||
m.App.PlaybackManager.LoadTracks(m.GetArtistTracks(artistID), false, shuffle)
|
m.App.PlaybackManager.LoadTracks(m.GetArtistTracks(artistID), false, shuffleTracks)
|
||||||
|
if m.App.Config.ReplayGain.Mode == backend.ReplayGainAuto {
|
||||||
|
if shuffleTracks {
|
||||||
|
m.App.PlaybackManager.SetReplayGainMode(player.ReplayGainTrack)
|
||||||
|
} else {
|
||||||
|
m.App.PlaybackManager.SetReplayGainMode(player.ReplayGainAlbum)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.App.PlaybackManager.PlayFromBeginning()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Controller) ShuffleArtistAlbums(artistID string) {
|
||||||
|
artist, err := m.App.ServerManager.Server.GetArtist(artistID)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error getting artist discography: %v", err.Error())
|
||||||
|
}
|
||||||
|
if len(artist.Albums) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
rand.Shuffle(len(artist.Albums), func(i, j int) {
|
||||||
|
artist.Albums[i], artist.Albums[j] = artist.Albums[j], artist.Albums[i]
|
||||||
|
})
|
||||||
|
m.App.PlaybackManager.StopAndClearPlayQueue()
|
||||||
|
for _, al := range artist.Albums {
|
||||||
|
m.App.PlaybackManager.LoadAlbum(al.ID, true /*append*/, false /*shuffle*/)
|
||||||
|
}
|
||||||
|
|
||||||
if m.App.Config.ReplayGain.Mode == backend.ReplayGainAuto {
|
if m.App.Config.ReplayGain.Mode == backend.ReplayGainAuto {
|
||||||
m.App.PlaybackManager.SetReplayGainMode(player.ReplayGainAlbum)
|
m.App.PlaybackManager.SetReplayGainMode(player.ReplayGainAlbum)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user