add album filters to favorites page
This commit is contained in:
@@ -29,6 +29,7 @@ type FavoritesPage struct {
|
||||
sm *backend.ServerManager
|
||||
lm *backend.LibraryManager
|
||||
|
||||
filter backend.AlbumFilter
|
||||
searchText string
|
||||
nowPlayingID string
|
||||
pendingViewSwitch bool
|
||||
@@ -38,6 +39,7 @@ type FavoritesPage struct {
|
||||
artistListCtr *fyne.Container
|
||||
tracklistCtr *fyne.Container
|
||||
searcher *widgets.SearchEntry
|
||||
filterBtn *widgets.AlbumFilterButton
|
||||
titleDisp *widget.RichText
|
||||
toggleBtns *widgets.ToggleButtonGroup
|
||||
container *fyne.Container
|
||||
@@ -45,16 +47,17 @@ type FavoritesPage struct {
|
||||
|
||||
func NewFavoritesPage(cfg *backend.FavoritesPageConfig, contr *controller.Controller, sm *backend.ServerManager, pm *backend.PlaybackManager, lm *backend.LibraryManager, im *backend.ImageManager) *FavoritesPage {
|
||||
a := &FavoritesPage{
|
||||
cfg: cfg,
|
||||
contr: contr,
|
||||
pm: pm,
|
||||
lm: lm,
|
||||
sm: sm,
|
||||
im: im,
|
||||
filter: backend.AlbumFilter{ExcludeUnfavorited: true},
|
||||
cfg: cfg,
|
||||
contr: contr,
|
||||
pm: pm,
|
||||
lm: lm,
|
||||
sm: sm,
|
||||
im: im,
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.createHeader(0, "")
|
||||
iter := lm.StarredIter(backend.AlbumFilter{})
|
||||
a.createHeader(0)
|
||||
iter := lm.StarredIter(a.filter)
|
||||
a.grid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im)
|
||||
a.contr.ConnectAlbumGridActions(a.grid)
|
||||
if cfg.InitialView == "Artists" {
|
||||
@@ -69,7 +72,7 @@ func NewFavoritesPage(cfg *backend.FavoritesPageConfig, contr *controller.Contro
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *FavoritesPage) createHeader(activeBtnIdx int, searchText string) {
|
||||
func (a *FavoritesPage) createHeader(activeBtnIdx int) {
|
||||
a.titleDisp = widget.NewRichTextWithText("Favorites")
|
||||
a.titleDisp.Segments[0].(*widget.TextSegment).Style = widget.RichTextStyle{
|
||||
SizeName: theme.SizeNameHeadingText,
|
||||
@@ -80,27 +83,32 @@ func (a *FavoritesPage) createHeader(activeBtnIdx int, searchText string) {
|
||||
widget.NewButtonWithIcon("", myTheme.TracksIcon, a.onShowFavoriteSongs))
|
||||
a.searcher = widgets.NewSearchEntry()
|
||||
a.searcher.OnSearched = a.OnSearched
|
||||
a.searcher.Entry.Text = searchText
|
||||
a.searcher.Entry.Text = a.searchText
|
||||
a.filterBtn = widgets.NewAlbumFilterButton(&a.filter)
|
||||
a.filterBtn.FavoriteDisabled = true
|
||||
a.filterBtn.OnChanged = a.Reload
|
||||
}
|
||||
|
||||
func (a *FavoritesPage) createContainer(initialView fyne.CanvasObject) {
|
||||
searchVbox := container.NewVBox(layout.NewSpacer(), a.searcher, layout.NewSpacer())
|
||||
a.container = container.NewBorder(
|
||||
container.NewHBox(util.NewHSpace(9), a.titleDisp, container.NewCenter(a.toggleBtns), layout.NewSpacer(), searchVbox, util.NewHSpace(15)),
|
||||
a.container = container.NewBorder(container.NewHBox(util.NewHSpace(9),
|
||||
a.titleDisp, container.NewCenter(a.toggleBtns), layout.NewSpacer(), container.NewCenter(a.filterBtn), searchVbox, util.NewHSpace(15)),
|
||||
nil, nil, nil, initialView)
|
||||
}
|
||||
|
||||
func restoreFavoritesPage(saved *savedFavoritesPage) *FavoritesPage {
|
||||
a := &FavoritesPage{
|
||||
cfg: saved.cfg,
|
||||
contr: saved.contr,
|
||||
pm: saved.pm,
|
||||
lm: saved.lm,
|
||||
sm: saved.sm,
|
||||
im: saved.im,
|
||||
cfg: saved.cfg,
|
||||
contr: saved.contr,
|
||||
pm: saved.pm,
|
||||
lm: saved.lm,
|
||||
sm: saved.sm,
|
||||
im: saved.im,
|
||||
searchText: saved.searchText,
|
||||
filter: saved.filter,
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
a.createHeader(saved.activeToggleBtn, saved.searchText)
|
||||
a.createHeader(saved.activeToggleBtn)
|
||||
a.grid = widgets.NewGridViewFromState(saved.gridState)
|
||||
|
||||
if saved.searchText != "" {
|
||||
@@ -129,7 +137,7 @@ func (a *FavoritesPage) Reload() {
|
||||
if a.searchText != "" {
|
||||
a.doSearchAlbums(a.searchText)
|
||||
} else {
|
||||
iter := a.lm.StarredIter(backend.AlbumFilter{})
|
||||
iter := a.lm.StarredIter(a.filter)
|
||||
a.grid.Reset(widgets.NewGridViewAlbumIterator(iter))
|
||||
}
|
||||
if a.tracklistCtr != nil || a.artistListCtr != nil {
|
||||
@@ -170,6 +178,7 @@ func (a *FavoritesPage) Save() SavedPage {
|
||||
sm: a.sm,
|
||||
im: a.im,
|
||||
lm: a.lm,
|
||||
filter: a.filter,
|
||||
searchText: a.searchText,
|
||||
gridState: a.grid.SaveToState(),
|
||||
activeToggleBtn: a.toggleBtns.ActivatedButtonIndex(),
|
||||
@@ -212,7 +221,7 @@ func (a *FavoritesPage) OnSongChange(song *subsonic.Child, _ *subsonic.Child) {
|
||||
}
|
||||
|
||||
func (a *FavoritesPage) doSearchAlbums(query string) {
|
||||
iter := a.lm.SearchIterWithFilter(query, backend.AlbumFilter{ExcludeUnfavorited: true})
|
||||
iter := a.lm.SearchIterWithFilter(query, a.filter)
|
||||
if a.searchGrid == nil {
|
||||
a.searchGrid = widgets.NewGridView(widgets.NewGridViewAlbumIterator(iter), a.im)
|
||||
a.contr.ConnectAlbumGridActions(a.searchGrid)
|
||||
@@ -226,6 +235,7 @@ func (a *FavoritesPage) doSearchAlbums(query string) {
|
||||
func (a *FavoritesPage) onShowFavoriteAlbums() {
|
||||
a.cfg.InitialView = "Albums" // save setting
|
||||
a.searcher.Entry.Show()
|
||||
a.filterBtn.Show()
|
||||
if a.searchText == "" {
|
||||
a.container.Objects[0] = a.grid
|
||||
} else {
|
||||
@@ -237,6 +247,7 @@ func (a *FavoritesPage) onShowFavoriteAlbums() {
|
||||
func (a *FavoritesPage) onShowFavoriteArtists() {
|
||||
a.cfg.InitialView = "Artists" // save setting
|
||||
a.searcher.Entry.Hide() // disable search on artists for now
|
||||
a.filterBtn.Hide()
|
||||
if a.artistListCtr == nil {
|
||||
if a.pendingViewSwitch {
|
||||
return
|
||||
@@ -285,6 +296,7 @@ func buildArtistListModel(artists []*subsonic.ArtistID3) []widgets.ArtistGenreLi
|
||||
func (a *FavoritesPage) onShowFavoriteSongs() {
|
||||
a.cfg.InitialView = "Songs" // save setting
|
||||
a.searcher.Entry.Hide() // disable search on songs for now
|
||||
a.filterBtn.Hide()
|
||||
if a.tracklistCtr == nil {
|
||||
if a.pendingViewSwitch {
|
||||
return
|
||||
@@ -334,6 +346,7 @@ type savedFavoritesPage struct {
|
||||
lm *backend.LibraryManager
|
||||
gridState widgets.GridViewState
|
||||
searchGridState widgets.GridViewState
|
||||
filter backend.AlbumFilter
|
||||
searchText string
|
||||
activeToggleBtn int
|
||||
}
|
||||
|
||||
@@ -17,8 +17,9 @@ import (
|
||||
type AlbumFilterButton struct {
|
||||
widget.Button
|
||||
|
||||
OnChanged func()
|
||||
GenreDisabled bool
|
||||
OnChanged func()
|
||||
GenreDisabled bool
|
||||
FavoriteDisabled bool
|
||||
|
||||
filter *backend.AlbumFilter
|
||||
dialog *widget.PopUp
|
||||
@@ -37,7 +38,7 @@ func NewAlbumFilterButton(filter *backend.AlbumFilter) *AlbumFilterButton {
|
||||
}
|
||||
|
||||
func (a *AlbumFilterButton) Refresh() {
|
||||
if a.filter.IsEmpty() || (a.GenreDisabled && a.filterEmptyExceptGenre()) {
|
||||
if a.filterEmpty() {
|
||||
a.Importance = widget.MediumImportance
|
||||
} else {
|
||||
a.Importance = widget.HighImportance
|
||||
@@ -45,9 +46,10 @@ func (a *AlbumFilterButton) Refresh() {
|
||||
a.Button.Refresh()
|
||||
}
|
||||
|
||||
func (a *AlbumFilterButton) filterEmptyExceptGenre() bool {
|
||||
return !a.filter.ExcludeFavorited && !a.filter.ExcludeUnfavorited &&
|
||||
a.filter.MinYear == 0 && a.filter.MaxYear == 0
|
||||
func (a *AlbumFilterButton) filterEmpty() bool {
|
||||
return a.filter.MinYear == 0 && a.filter.MaxYear == 0 &&
|
||||
(a.FavoriteDisabled || !a.filter.ExcludeFavorited && !a.filter.ExcludeUnfavorited) &&
|
||||
(a.GenreDisabled || len(a.filter.Genres) == 0)
|
||||
}
|
||||
|
||||
func (a *AlbumFilterButton) onFilterChanged() {
|
||||
@@ -59,7 +61,7 @@ func (a *AlbumFilterButton) onFilterChanged() {
|
||||
|
||||
func (a *AlbumFilterButton) showFilterDialog() {
|
||||
if a.dialog == nil {
|
||||
filterDlg := NewAlbumFilterPopup(a.filter)
|
||||
filterDlg := NewAlbumFilterPopup(a)
|
||||
filterDlg.OnChanged = a.onFilterChanged
|
||||
a.dialog = widget.NewPopUp(filterDlg, fyne.CurrentApp().Driver().CanvasForObject(a))
|
||||
}
|
||||
@@ -72,12 +74,14 @@ type AlbumFilterPopup struct {
|
||||
|
||||
OnChanged func()
|
||||
|
||||
filter *backend.AlbumFilter
|
||||
container *fyne.Container
|
||||
isFavorite *widget.Check
|
||||
isNotFavorite *widget.Check
|
||||
filterBtn *AlbumFilterButton
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewAlbumFilterPopup(filter *backend.AlbumFilter) *AlbumFilterPopup {
|
||||
a := &AlbumFilterPopup{filter: filter}
|
||||
func NewAlbumFilterPopup(filter *AlbumFilterButton) *AlbumFilterPopup {
|
||||
a := &AlbumFilterPopup{filterBtn: filter}
|
||||
a.ExtendBaseWidget(a)
|
||||
|
||||
debounceOnChanged := util.NewDebouncer(350*time.Millisecond, a.emitOnChanged)
|
||||
@@ -90,45 +94,46 @@ func NewAlbumFilterPopup(filter *backend.AlbumFilter) *AlbumFilterPopup {
|
||||
minYear.SetMinCharWidth(4)
|
||||
minYear.OnChanged = func(yearStr string) {
|
||||
if yearStr == "" {
|
||||
a.filter.MinYear = 0
|
||||
a.filterBtn.filter.MinYear = 0
|
||||
} else if i, err := strconv.Atoi(yearStr); err == nil {
|
||||
a.filter.MinYear = i
|
||||
a.filterBtn.filter.MinYear = i
|
||||
}
|
||||
debounceOnChanged()
|
||||
}
|
||||
if filter.MinYear > 0 {
|
||||
minYear.Text = strconv.Itoa(filter.MinYear)
|
||||
if a.filterBtn.filter.MinYear > 0 {
|
||||
minYear.Text = strconv.Itoa(a.filterBtn.filter.MinYear)
|
||||
}
|
||||
maxYear := NewTextRestrictedEntry(yearValidator)
|
||||
maxYear.SetMinCharWidth(4)
|
||||
maxYear.OnChanged = func(yearStr string) {
|
||||
if yearStr == "" {
|
||||
a.filter.MaxYear = 0
|
||||
a.filterBtn.filter.MaxYear = 0
|
||||
} else if i, err := strconv.Atoi(yearStr); err == nil {
|
||||
a.filter.MaxYear = i
|
||||
a.filterBtn.filter.MaxYear = i
|
||||
}
|
||||
debounceOnChanged()
|
||||
}
|
||||
if filter.MaxYear > 0 {
|
||||
maxYear.Text = strconv.Itoa(filter.MaxYear)
|
||||
if a.filterBtn.filter.MaxYear > 0 {
|
||||
maxYear.Text = strconv.Itoa(a.filterBtn.filter.MaxYear)
|
||||
}
|
||||
|
||||
// setup is favorite/not favorite filters
|
||||
var isNotFavorite *widget.Check
|
||||
isFavorite := widget.NewCheck("Is favorite", func(fav bool) {
|
||||
a.isFavorite = widget.NewCheck("Is favorite", func(fav bool) {
|
||||
if fav {
|
||||
isNotFavorite.SetChecked(false)
|
||||
a.isNotFavorite.SetChecked(false)
|
||||
}
|
||||
a.filter.ExcludeUnfavorited = fav
|
||||
a.filterBtn.filter.ExcludeUnfavorited = fav
|
||||
debounceOnChanged()
|
||||
})
|
||||
isNotFavorite = widget.NewCheck("Is not favorite", func(fav bool) {
|
||||
a.isFavorite.Hidden = a.filterBtn.FavoriteDisabled
|
||||
a.isNotFavorite = widget.NewCheck("Is not favorite", func(fav bool) {
|
||||
if fav {
|
||||
isFavorite.SetChecked(false)
|
||||
a.isFavorite.SetChecked(false)
|
||||
}
|
||||
a.filter.ExcludeFavorited = fav
|
||||
a.filterBtn.filter.ExcludeFavorited = fav
|
||||
debounceOnChanged()
|
||||
})
|
||||
a.isNotFavorite.Hidden = a.filterBtn.FavoriteDisabled
|
||||
|
||||
// setup container
|
||||
title := widget.NewLabel("Album filters")
|
||||
@@ -136,12 +141,18 @@ func NewAlbumFilterPopup(filter *backend.AlbumFilter) *AlbumFilterPopup {
|
||||
a.container = container.NewVBox(
|
||||
container.NewHBox(layout.NewSpacer(), title, layout.NewSpacer()),
|
||||
container.NewHBox(widget.NewLabel("Year from"), minYear, widget.NewLabel("to"), maxYear),
|
||||
container.NewHBox(isFavorite, isNotFavorite),
|
||||
container.NewHBox(a.isFavorite, a.isNotFavorite),
|
||||
)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *AlbumFilterPopup) Refresh() {
|
||||
a.isFavorite.Hidden = a.filterBtn.FavoriteDisabled
|
||||
a.isNotFavorite.Hidden = a.filterBtn.FavoriteDisabled
|
||||
a.BaseWidget.Refresh()
|
||||
}
|
||||
|
||||
func (a *AlbumFilterPopup) emitOnChanged() {
|
||||
if a.OnChanged != nil {
|
||||
a.OnChanged()
|
||||
|
||||
Reference in New Issue
Block a user