Skip to content

Commit

Permalink
add option to show album years in grid views
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jun 28, 2024
1 parent 2b39c6b commit edf85a4
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 43 deletions.
4 changes: 4 additions & 0 deletions backend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type AlbumPageConfig struct {

type AlbumsPageConfig struct {
SortOrder string
ShowYears bool
}

type ArtistPageConfig struct {
Expand All @@ -73,6 +74,7 @@ type ArtistsPageConfig struct {
type FavoritesPageConfig struct {
InitialView string
TracklistColumns []string
ShowAlbumYears bool
}

type PlaylistPageConfig struct {
Expand Down Expand Up @@ -167,6 +169,7 @@ func DefaultConfig(appVersionTag string) *Config {
},
AlbumsPage: AlbumsPageConfig{
SortOrder: string("Recently Added"),
ShowYears: false,
},
ArtistPage: ArtistPageConfig{
InitialView: "Discography",
Expand All @@ -178,6 +181,7 @@ func DefaultConfig(appVersionTag string) *Config {
FavoritesPage: FavoritesPageConfig{
TracklistColumns: []string{"Album", "Time", "Plays"},
InitialView: "Albums",
ShowAlbumYears: false,
},
PlaylistPage: PlaylistPageConfig{
TracklistColumns: []string{"Album", "Time", "Plays"},
Expand Down
8 changes: 7 additions & 1 deletion ui/browsing/albumspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func (a *albumsPageAdapter) SearchIter(query string, filter mediaprovider.AlbumF
return widgets.NewGridViewAlbumIterator(a.mp.SearchAlbums(query, filter))
}

func (a *albumsPageAdapter) ConnectGridActions(gv *widgets.GridView) {
func (a *albumsPageAdapter) InitGrid(gv *widgets.GridView) {
a.contr.ConnectAlbumGridActions(gv)
gv.ShowSuffix = a.cfg.ShowYears
}

func (a *albumsPageAdapter) RefreshGrid(gv *widgets.GridView) {
gv.ShowSuffix = a.cfg.ShowYears
gv.Refresh()
}
6 changes: 5 additions & 1 deletion ui/browsing/artistspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ func (a *artistsPageAdapter) SearchIter(query string, filter mediaprovider.Artis
return widgets.NewGridViewArtistIterator(a.mp.SearchArtists(query, filter))
}

func (a *artistsPageAdapter) ConnectGridActions(gv *widgets.GridView) {
func (a *artistsPageAdapter) InitGrid(gv *widgets.GridView) {
canShareArtists := false
if r, canShare := a.mp.(mediaprovider.SupportsSharing); canShare {
canShareArtists = r.CanShareArtists()
}
gv.DisableSharing = !canShareArtists
a.contr.ConnectArtistGridActions(gv)
}

func (a *artistsPageAdapter) RefreshGrid(gv *widgets.GridView) {
gv.Refresh()
}
6 changes: 6 additions & 0 deletions ui/browsing/browsingpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ func (b *BrowsingPane) ScrollDown() {
}
}

func (b *BrowsingPane) RefreshPage() {
if b.curPage != nil {
b.curPage.Refresh()
}
}

func (b *BrowsingPane) doSetPage(p Page) bool {
if b.curPage != nil && b.curPage.Route() == p.Route() {
return false
Expand Down
8 changes: 8 additions & 0 deletions ui/browsing/favoritespage.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func NewFavoritesPage(cfg *backend.FavoritesPageConfig, pool *util.WidgetPool, c
} else {
a.albumGrid = widgets.NewGridView(iter, a.im, myTheme.AlbumIcon)
}
a.albumGrid.ShowSuffix = cfg.ShowAlbumYears
a.contr.ConnectAlbumGridActions(a.albumGrid)
if cfg.InitialView == "Artists" {
a.toggleBtns.SetActivatedButton(1)
Expand Down Expand Up @@ -285,6 +286,13 @@ func (a *FavoritesPage) SelectAll() {
}
}

func (a *FavoritesPage) Refresh() {
if a.albumGrid != nil {
a.albumGrid.ShowSuffix = a.cfg.ShowAlbumYears
}
a.BaseWidget.Refresh()
}

func (a *FavoritesPage) tracklistOrNil() *widgets.Tracklist {
if a.tracklistCtr != nil {
return a.tracklistCtr.Objects[0].(*widgets.Tracklist)
Expand Down
13 changes: 10 additions & 3 deletions ui/browsing/genrepage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ import (

type genrePageAdapter struct {
genre string
cfg *backend.AlbumsPageConfig
contr *controller.Controller
mp mediaprovider.MediaProvider
pm *backend.PlaybackManager
filter mediaprovider.AlbumFilter
filterBtn *widgets.AlbumFilterButton
}

func NewGenrePage(genre string, pool *util.WidgetPool, contr *controller.Controller, pm *backend.PlaybackManager, mp mediaprovider.MediaProvider, im *backend.ImageManager) Page {
adapter := &genrePageAdapter{genre: genre, contr: contr, mp: mp, pm: pm}
func NewGenrePage(genre string, cfg *backend.AlbumsPageConfig, pool *util.WidgetPool, contr *controller.Controller, pm *backend.PlaybackManager, mp mediaprovider.MediaProvider, im *backend.ImageManager) Page {
adapter := &genrePageAdapter{genre: genre, cfg: cfg, contr: contr, mp: mp, pm: pm}
return NewGridViewPage(adapter, pool, mp, im)
}

Expand Down Expand Up @@ -68,6 +69,12 @@ func (a *genrePageAdapter) SearchIter(query string, filter mediaprovider.AlbumFi
return widgets.NewGridViewAlbumIterator(a.mp.SearchAlbums(query, filter))
}

func (g *genrePageAdapter) ConnectGridActions(gv *widgets.GridView) {
func (g *genrePageAdapter) InitGrid(gv *widgets.GridView) {
g.contr.ConnectAlbumGridActions(gv)
gv.ShowSuffix = g.cfg.ShowYears
}

func (g *genrePageAdapter) RefreshGrid(gv *widgets.GridView) {
gv.ShowSuffix = g.cfg.ShowYears
gv.Refresh()
}
17 changes: 13 additions & 4 deletions ui/browsing/gridviewpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,13 @@ type GridViewPageAdapter[M, F any] interface {
// Returns the iterator for the given search query and filter.
SearchIter(query string, filter mediaprovider.MediaFilter[M, F]) widgets.GridViewIterator

// Function that connects the GridView callbacks to the appropriate action handlers.
ConnectGridActions(*widgets.GridView)
// Function that initialized the GridView with page-specific settings
// and connects the GridView callbacks to the appropriate action handlers.
InitGrid(*widgets.GridView)

// Function called when settings may have changed and the grid needs
// reconfiguring with possible settings changes.
RefreshGrid(*widgets.GridView)
}

type SortableGridViewPageAdapter interface {
Expand Down Expand Up @@ -124,7 +129,7 @@ func NewGridViewPage[M, F any](
gp.grid = widgets.NewGridView(iter, im, adapter.PlaceholderResource())
}
gp.grid.DisableSharing = !canShare
adapter.ConnectGridActions(gp.grid)
adapter.InitGrid(gp.grid)
gp.createSearchAndFilter()
gp.createContainer()
return gp
Expand Down Expand Up @@ -206,6 +211,10 @@ func (g *GridViewPage[M, F]) OnSearched(query string) {
g.searchText = query
}

func (g *GridViewPage[M, F]) Refresh() {
g.adapter.RefreshGrid(g.grid)
}

func (g *GridViewPage[M, F]) doSearch(query string) {
if g.searchText == "" {
g.gridState = g.grid.SaveToState()
Expand Down Expand Up @@ -294,7 +303,7 @@ func (s *savedGridViewPage[M, F]) Restore() Page {
} else {
gp.grid = widgets.NewGridViewFromState(state)
}
gp.adapter.ConnectGridActions(gp.grid)
gp.adapter.InitGrid(gp.grid)
gp.createSearchAndFilter()
gp.createContainer()
return gp
Expand Down
2 changes: 1 addition & 1 deletion ui/browsing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (r Router) CreatePage(rte controller.Route) Page {
case controller.Favorites:
return NewFavoritesPage(&r.App.Config.FavoritesPage, r.widgetPool, r.Controller, r.App.ServerManager.Server, r.App.PlaybackManager, r.App.ImageManager)
case controller.Genre:
return NewGenrePage(rte.Arg, r.widgetPool, r.Controller, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager)
return NewGenrePage(rte.Arg, &r.App.Config.AlbumsPage, r.widgetPool, r.Controller, r.App.PlaybackManager, r.App.ServerManager.Server, r.App.ImageManager)
case controller.Genres:
return NewGenresPage(r.Controller, r.App.ServerManager.Server)
case controller.NowPlaying:
Expand Down
16 changes: 8 additions & 8 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ import (

type NavigationHandler func(Route)

type ReloadFunc func()

type CurPageFunc func() Route

type Controller struct {
AppVersion string
MainWindow fyne.Window
App *backend.App
NavHandler NavigationHandler
CurPageFunc CurPageFunc
ReloadFunc ReloadFunc
AppVersion string
App *backend.App
MainWindow fyne.Window
NavHandler NavigationHandler
CurPageFunc CurPageFunc
ReloadFunc func()
RefreshPageFunc func()

escapablePopUp *widget.PopUp
haveModal bool
Expand Down Expand Up @@ -559,6 +558,7 @@ func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map
copy(eq.BandGains[:], c.App.Config.LocalPlayback.GraphicEqualizerBands)
c.App.LocalPlayer.SetEqualizer(eq)
}
dlg.OnPageNeedsRefresh = c.RefreshPageFunc
pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas())
dlg.OnDismiss = func() {
pop.Hide()
Expand Down
10 changes: 10 additions & 0 deletions ui/dialogs/settingsdialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type SettingsDialog struct {
OnThemeSettingChanged func()
OnDismiss func()
OnEqualizerSettingsChanged func()
OnPageNeedsRefresh func()

config *backend.Config
audioDevices []mpv.AudioDevice
Expand Down Expand Up @@ -185,6 +186,14 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.

trackNotif := widget.NewCheckWithData("Show notification on track change",
binding.BindBool(&s.config.Application.ShowTrackChangeNotification))
albumGridYears := widget.NewCheck("Show year in album grid cards", func(b bool) {
s.config.AlbumsPage.ShowYears = b
s.config.FavoritesPage.ShowAlbumYears = b
if s.OnPageNeedsRefresh != nil {
s.OnPageNeedsRefresh()
}
})
albumGridYears.Checked = s.config.AlbumsPage.ShowYears

// Scrobble settings

Expand Down Expand Up @@ -276,6 +285,7 @@ func (s *SettingsDialog) createGeneralTab(canSaveQueueToServer bool) *container.
container.NewHBox(systemTrayEnable, closeToTray),
saveQueueHBox,
trackNotif,
albumGridYears,
s.newSectionSeparator(),

widget.NewRichText(&widget.TextSegment{Text: "Scrobbling", Style: util.BoldRichTextStyle}),
Expand Down
1 change: 1 addition & 0 deletions ui/mainwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
m.Controller.NavHandler = m.Router.NavigateTo
m.Controller.ReloadFunc = m.BrowsingPane.Reload
m.Controller.CurPageFunc = m.BrowsingPane.CurrentPage
m.Controller.RefreshPageFunc = m.BrowsingPane.RefreshPage

m.BottomPanel = NewBottomPanel(app.PlaybackManager, app.ImageManager, m.Controller)
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
Expand Down
8 changes: 8 additions & 0 deletions ui/theme/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const (
ColorNameIconButton fyne.ThemeColorName = "IconButton"
ColorNameHoveredIconButton fyne.ThemeColorName = "HoveredIconButton"
ColorNameNowPlayingPanel fyne.ThemeColorName = "NowPlayingPanel"

SizeNameSubText fyne.ThemeSizeName = "subText" // in between Text and Caption
SizeNameSuffixText fyne.ThemeSizeName = "suffixText" // a tiny bit smaller than subText
)

var (
Expand Down Expand Up @@ -243,6 +246,11 @@ func (m *MyTheme) Font(style fyne.TextStyle) fyne.Resource {
}

func (m *MyTheme) Size(name fyne.ThemeSizeName) float32 {
if name == SizeNameSubText {
return 13
} else if name == SizeNameSuffixText {
return 12
}
return theme.DefaultTheme().Size(name)
}

Expand Down
11 changes: 10 additions & 1 deletion ui/widgets/gridview.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package widgets
import (
"context"
"fmt"
"strconv"
"sync"

"github.com/dweymouth/supersonic/backend/mediaprovider"
Expand Down Expand Up @@ -51,13 +52,17 @@ type gridViewAlbumIterator struct {
func (g gridViewAlbumIterator) NextN(n int) []GridViewItemModel {
albums := g.iter.NextN(n)
return sharedutil.MapSlice(albums, func(al *mediaprovider.Album) GridViewItemModel {
return GridViewItemModel{
model := GridViewItemModel{
Name: al.Name,
ID: al.ID,
CoverArtID: al.CoverArtID,
Secondary: al.ArtistNames,
SecondaryIDs: al.ArtistIDs,
}
if al.Year > 0 {
model.Suffix = strconv.Itoa(al.Year)
}
return model
})
}

Expand Down Expand Up @@ -92,6 +97,8 @@ func NewGridViewArtistIterator(iter mediaprovider.ArtistIterator) GridViewIterat
type GridView struct {
widget.BaseWidget

ShowSuffix bool

stateMutex sync.RWMutex
fetchCancel context.CancelFunc
GridViewState
Expand Down Expand Up @@ -322,9 +329,11 @@ func (g *GridView) doUpdateItemCard(itemIdx int, card *GridViewItem) {
card.ItemIndex = itemIdx
g.itemForIndex[itemIdx] = card
card.Cover.Im.PlaceholderIcon = g.Placeholder
card.ShowSuffix = g.ShowSuffix
if !card.NeedsUpdate(item) && card.ItemIndex == itemIdx {
// nothing to do
g.stateMutex.Unlock()
card.Refresh()
return
}
g.stateMutex.Unlock()
Expand Down
Loading

0 comments on commit edf85a4

Please sign in to comment.