Skip to content

Commit

Permalink
save scroll position of Playlists page views in browsing history
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Apr 27, 2024
1 parent 02d4082 commit e4514c5
Showing 1 changed file with 48 additions and 20 deletions.
68 changes: 48 additions & 20 deletions ui/browsing/playlistspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,39 @@ type PlaylistsPage struct {
listView *PlaylistList
listSort widgets.ListHeaderSort
gridView *widgets.GridView

initialListScrollPos float32
initialGridScrollPos float32
}

func NewPlaylistsPage(contr *controller.Controller, pool *util.WidgetPool, cfg *backend.PlaylistsPageConfig, mp mediaprovider.MediaProvider) *PlaylistsPage {
activeView := 0
if cfg.InitialView == "Grid" {
activeView = 1
}
return newPlaylistsPage(contr, pool, cfg, mp, "", activeView, widgets.ListHeaderSort{})
}

func newPlaylistsPage(contr *controller.Controller, pool *util.WidgetPool, cfg *backend.PlaylistsPageConfig, mp mediaprovider.MediaProvider, searchText string, activeView int, listSort widgets.ListHeaderSort) *PlaylistsPage {
return newPlaylistsPage(contr, pool, cfg, mp, "", activeView, widgets.ListHeaderSort{}, 0, 0)
}

func newPlaylistsPage(
contr *controller.Controller,
pool *util.WidgetPool,
cfg *backend.PlaylistsPageConfig,
mp mediaprovider.MediaProvider,
searchText string,
activeView int,
listSort widgets.ListHeaderSort,
listScrollPos float32,
gridScrollPos float32,
) *PlaylistsPage {
a := &PlaylistsPage{
pool: pool,
cfg: cfg,
mp: mp,
contr: contr,
listSort: listSort,
titleDisp: widget.NewRichTextWithText("Playlists"),
pool: pool,
cfg: cfg,
mp: mp,
contr: contr,
listSort: listSort,
titleDisp: widget.NewRichTextWithText("Playlists"),
initialListScrollPos: listScrollPos,
initialGridScrollPos: gridScrollPos,
}
a.ExtendBaseWidget(a)
a.titleDisp.Segments[0].(*widget.TextSegment).Style.SizeName = theme.SizeNameHeadingText
Expand Down Expand Up @@ -224,9 +239,18 @@ func (a *PlaylistsPage) refreshView(playlists []*mediaprovider.Playlist) {
a.gridView.ResetFixed(createPlaylistGridViewModel(playlists))
}
if a.viewToggle.ActivatedButtonIndex() == 0 {
a.listView.Refresh()
a.listView.Refresh() // ensures content size updates for ScrollToOffset too
if a.initialListScrollPos != 0 {
a.listView.list.ScrollToOffset(a.initialListScrollPos)
a.initialListScrollPos = 0
}
} else {
a.gridView.Refresh()
if a.initialGridScrollPos != 0 {
a.gridView.ScrollToOffset(a.initialGridScrollPos)
a.initialGridScrollPos = 0
} else {
a.gridView.Refresh()
}
}
}

Expand Down Expand Up @@ -254,27 +278,31 @@ func (a *PlaylistsPage) Save() SavedPage {
activeView: a.viewToggle.ActivatedButtonIndex(),
}
if a.gridView != nil {
s.gridScrollPos = a.gridView.GetScrollOffset()
a.gridView.Clear()
a.pool.Release(util.WidgetTypeGridView, a.gridView)
}
if a.listView != nil {
s.listScrollPos = a.listView.list.GetScrollOffset()
s.listSort = a.listView.sorting
}
return s
}

type savedPlaylistsPage struct {
contr *controller.Controller
pool *util.WidgetPool
cfg *backend.PlaylistsPageConfig
mp mediaprovider.MediaProvider
searchText string
activeView int
listSort widgets.ListHeaderSort
contr *controller.Controller
pool *util.WidgetPool
cfg *backend.PlaylistsPageConfig
mp mediaprovider.MediaProvider
searchText string
activeView int
listSort widgets.ListHeaderSort
listScrollPos float32
gridScrollPos float32
}

func (s *savedPlaylistsPage) Restore() Page {
return newPlaylistsPage(s.contr, s.pool, s.cfg, s.mp, s.searchText, s.activeView, s.listSort)
return newPlaylistsPage(s.contr, s.pool, s.cfg, s.mp, s.searchText, s.activeView, s.listSort, s.listScrollPos, s.gridScrollPos)
}

func (a *PlaylistsPage) buildContainer(initialView fyne.CanvasObject) {
Expand Down

0 comments on commit e4514c5

Please sign in to comment.