genre page is now working and linked to from album page

This commit is contained in:
Drew Weymouth
2023-01-07 14:56:52 -08:00
parent 9122c4e7b9
commit f6a38859f4
4 changed files with 48 additions and 9 deletions
+12 -3
View File
@@ -73,11 +73,15 @@ func (l *LibraryManager) StarredIter() AlbumIterator {
}
func (l *LibraryManager) GenreIter(genre string) AlbumIterator {
return l.newBaseIter("", map[string]string{"genre": genre})
return l.newBaseIter("byGenre", map[string]string{"genre": genre})
}
func (l *LibraryManager) SearchIter(query string) AlbumIterator {
return l.newSearchIter(query)
return l.newSearchIter(query, func(*subsonic.AlbumID3) bool { return true })
}
func (l *LibraryManager) SearchIterWithFilter(query string, filter func(*subsonic.AlbumID3) bool) AlbumIterator {
return l.newSearchIter(query, filter)
}
func (l *LibraryManager) CacheAlbum(a *subsonic.AlbumID3) {
@@ -172,17 +176,19 @@ type searchIter struct {
songOffset int
l *LibraryManager
s *subsonic.Client
filter func(*subsonic.AlbumID3) bool
prefetched []*subsonic.AlbumID3
prefetchedPos int
albumIDset map[string]bool
done bool
}
func (l *LibraryManager) newSearchIter(query string) *searchIter {
func (l *LibraryManager) newSearchIter(query string, filter func(*subsonic.AlbumID3) bool) *searchIter {
return &searchIter{
query: query,
l: l,
s: l.s.Server,
filter: filter,
albumIDset: make(map[string]bool),
}
}
@@ -267,6 +273,9 @@ func (s *searchIter) addNewAlbums(al []*subsonic.AlbumID3) {
if _, have := s.albumIDset[album.ID]; have {
continue
}
if !s.filter(album) {
continue
}
s.prefetched = append(s.prefetched, album)
s.albumIDset[album.ID] = true
}
+7 -2
View File
@@ -93,11 +93,12 @@ type AlbumPageHeader struct {
albumID string
artistID string
genre string
cover *canvas.Image
titleLabel *widget.RichText
artistLabel *widgets.CustomHyperlink
genreLabel *widget.Label // later custom hyperlink
genreLabel *widgets.CustomHyperlink
miscLabel *widget.Label
playButton *widget.Button
@@ -119,7 +120,10 @@ func NewAlbumPageHeader(page *AlbumPage) *AlbumPageHeader {
a.artistLabel.OnTapped = func() {
page.nav(ArtistRoute(a.artistID))
}
a.genreLabel = widget.NewLabel("")
a.genreLabel = widgets.NewCustomHyperlink()
a.genreLabel.OnTapped = func() {
page.nav(GenreRoute(a.genre))
}
a.miscLabel = widget.NewLabel("")
a.playButton = widget.NewButtonWithIcon("Play", theme.MediaPlayIcon(), func() {
page.onPlayTrackAt(0)
@@ -144,6 +148,7 @@ func (a *AlbumPageHeader) Update(album *subsonic.AlbumID3, im *backend.ImageMana
a.artistID = album.ArtistID
a.titleLabel.Segments[0].(*widget.TextSegment).Text = album.Name
a.artistLabel.SetText(album.Artist)
a.genre = album.Genre
a.genreLabel.SetText(album.Genre)
a.miscLabel.SetText(formatMiscLabelStr(album))
a.Refresh()
+27 -4
View File
@@ -9,6 +9,7 @@ import (
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic"
)
// TODO: there is a lot of code duplication between this and albumspage. Refactor?
@@ -43,7 +44,8 @@ func NewGenrePage(genre string, lm *backend.LibraryManager, im *backend.ImageMan
g.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
SizeName: theme.SizeNameHeadingText,
}
g.grid = widgets.NewFixedAlbumGrid(nil, im.GetAlbumThumbnail, false /*showYear*/)
iter := g.lm.GenreIter(g.genre)
g.grid = widgets.NewAlbumGrid(iter, g.im.GetAlbumThumbnail, false)
g.grid.OnPlayAlbum = g.onPlayAlbum
g.grid.OnShowArtistPage = g.onShowArtistPage
g.grid.OnShowAlbumPage = g.onShowAlbumPage
@@ -76,7 +78,7 @@ func (g *GenrePage) Reload() {
if g.searchText != "" {
g.doSearch(g.searchText)
} else {
g.grid.Reset(nil)
g.grid.Reset(g.lm.GenreIter(g.genre))
g.grid.Refresh()
}
}
@@ -96,9 +98,30 @@ func (a *GenrePage) onShowAlbumPage(albumID string) {
}
func (g *GenrePage) OnSearched(query string) {
g.searchText = query
if query == "" {
g.container.Objects[0] = g.grid
if g.searchGrid != nil {
g.searchGrid.Clear()
}
g.Refresh()
return
}
g.doSearch(query)
}
func (g *GenrePage) doSearch(query string) {
iter := g.lm.SearchIterWithFilter(query, func(al *subsonic.AlbumID3) bool {
return al.Genre == g.genre
})
if g.searchGrid == nil {
g.searchGrid = widgets.NewAlbumGrid(iter, g.im.GetAlbumThumbnail, false /*showYear*/)
g.searchGrid.OnPlayAlbum = g.onPlayAlbum
g.searchGrid.OnShowAlbumPage = g.onShowAlbumPage
g.searchGrid.OnShowArtistPage = g.onShowArtistPage
} else {
g.searchGrid.Reset(iter)
}
g.container.Objects[0] = g.searchGrid
g.Refresh()
}
+2
View File
@@ -63,6 +63,8 @@ func (r Router) CreatePage(rte Route) Page {
return NewAlbumsPage("Albums", rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
case Artist:
return NewArtistPage(rte.Arg, r.App.ServerManager, r.App.ImageManager, r.OpenRoute)
case Genre:
return NewGenrePage(rte.Arg, r.App.LibraryManager, r.App.ImageManager, r.OpenRoute)
}
return nil
}