restore scroll position when navigating back to Album and Playlist pages
This commit is contained in:
@@ -37,6 +37,7 @@ type AlbumPage struct {
|
||||
type albumPageState struct {
|
||||
albumID string
|
||||
sort widgets.TracklistSort
|
||||
scroll float32
|
||||
cfg *backend.AlbumPageConfig
|
||||
pool *util.WidgetPool
|
||||
mp mediaprovider.MediaProvider
|
||||
@@ -54,7 +55,7 @@ func NewAlbumPage(
|
||||
im *backend.ImageManager,
|
||||
contr *controller.Controller,
|
||||
) *AlbumPage {
|
||||
return newAlbumPage(albumID, cfg, pool, pm, mp, im, contr, widgets.TracklistSort{})
|
||||
return newAlbumPage(albumID, cfg, pool, pm, mp, im, contr, widgets.TracklistSort{}, 0)
|
||||
}
|
||||
|
||||
func newAlbumPage(
|
||||
@@ -66,6 +67,7 @@ func newAlbumPage(
|
||||
im *backend.ImageManager,
|
||||
contr *controller.Controller,
|
||||
sort widgets.TracklistSort,
|
||||
scroll float32,
|
||||
) *AlbumPage {
|
||||
a := &AlbumPage{
|
||||
albumPageState: albumPageState{
|
||||
@@ -76,6 +78,7 @@ func newAlbumPage(
|
||||
mp: mp,
|
||||
im: im,
|
||||
contr: contr,
|
||||
scroll: scroll,
|
||||
},
|
||||
}
|
||||
a.ExtendBaseWidget(a)
|
||||
@@ -122,6 +125,7 @@ func (a *AlbumPage) Save() SavedPage {
|
||||
a.tracklist.SetLoading(false)
|
||||
s := a.albumPageState
|
||||
s.sort = a.tracklist.Sorting()
|
||||
s.scroll = a.tracklist.GetScrollOffset()
|
||||
a.header.page = nil
|
||||
a.pool.Release(util.WidgetTypeAlbumPageHeader, a.header)
|
||||
a.tracklist.Clear()
|
||||
@@ -159,7 +163,7 @@ func (a *AlbumPage) UnselectAll() {
|
||||
var _ Scrollable = (*AlbumPage)(nil)
|
||||
|
||||
func (a *AlbumPage) Scroll(scrollAmt float32) {
|
||||
a.tracklist.Scroll(scrollAmt)
|
||||
a.tracklist.ScrollBy(scrollAmt)
|
||||
}
|
||||
|
||||
// should be called asynchronously
|
||||
@@ -188,6 +192,10 @@ func (a *AlbumPage) load() {
|
||||
a.tracks = album.Tracks
|
||||
a.tracklist.SetTracks(album.Tracks)
|
||||
a.tracklist.SetNowPlaying(a.nowPlayingID)
|
||||
if a.scroll != 0 {
|
||||
a.tracklist.ScrollToOffset(a.scroll)
|
||||
a.scroll = 0
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -396,5 +404,5 @@ func formatMiscLabelStr(a *mediaprovider.AlbumWithTracks) string {
|
||||
}
|
||||
|
||||
func (s *albumPageState) Restore() Page {
|
||||
return newAlbumPage(s.albumID, s.cfg, s.pool, s.pm, s.mp, s.im, s.contr, s.sort)
|
||||
return newAlbumPage(s.albumID, s.cfg, s.pool, s.pm, s.mp, s.im, s.contr, s.sort, s.scroll)
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ func (a *FavoritesPage) Scroll(amount float32) {
|
||||
grid = a.artistGrid
|
||||
default:
|
||||
if tr := a.tracklistOrNil(); tr != nil {
|
||||
tr.Scroll(amount)
|
||||
tr.ScrollBy(amount)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ type playlistPageState struct {
|
||||
pm *backend.PlaybackManager
|
||||
im *backend.ImageManager
|
||||
trackSort widgets.TracklistSort
|
||||
scroll float32
|
||||
}
|
||||
|
||||
func NewPlaylistPage(
|
||||
@@ -57,7 +58,7 @@ func NewPlaylistPage(
|
||||
pm *backend.PlaybackManager,
|
||||
im *backend.ImageManager,
|
||||
) *PlaylistPage {
|
||||
return newPlaylistPage(playlistID, conf, contr, pool, sm, pm, im, widgets.TracklistSort{})
|
||||
return newPlaylistPage(playlistID, conf, contr, pool, sm, pm, im, widgets.TracklistSort{}, 0)
|
||||
}
|
||||
|
||||
func newPlaylistPage(
|
||||
@@ -69,8 +70,9 @@ func newPlaylistPage(
|
||||
pm *backend.PlaybackManager,
|
||||
im *backend.ImageManager,
|
||||
trackSort widgets.TracklistSort,
|
||||
scroll float32,
|
||||
) *PlaylistPage {
|
||||
a := &PlaylistPage{playlistPageState: playlistPageState{playlistID: playlistID, conf: conf, contr: contr, widgetPool: pool, sm: sm, pm: pm, im: im}}
|
||||
a := &PlaylistPage{playlistPageState: playlistPageState{playlistID: playlistID, conf: conf, contr: contr, widgetPool: pool, sm: sm, pm: pm, im: im, scroll: scroll}}
|
||||
a.ExtendBaseWidget(a)
|
||||
if h := a.widgetPool.Obtain(util.WidgetTypePlaylistPageHeader); h != nil {
|
||||
a.header = h.(*PlaylistPageHeader)
|
||||
@@ -123,6 +125,7 @@ func (a *PlaylistPage) Save() SavedPage {
|
||||
a.tracklist.SetLoading(false)
|
||||
p := a.playlistPageState
|
||||
p.trackSort = a.tracklist.Sorting()
|
||||
p.scroll = a.tracklist.GetScrollOffset()
|
||||
p.widgetPool.Release(util.WidgetTypePlaylistPageHeader, a.header)
|
||||
a.tracklist.Clear()
|
||||
a.tracklist.OnReorderTracks = nil
|
||||
@@ -160,7 +163,7 @@ func (a *PlaylistPage) UnselectAll() {
|
||||
var _ Scrollable = (*PlaylistPage)(nil)
|
||||
|
||||
func (a *PlaylistPage) Scroll(scrollAmt float32) {
|
||||
a.tracklist.Scroll(scrollAmt)
|
||||
a.tracklist.ScrollBy(scrollAmt)
|
||||
}
|
||||
|
||||
// should be called asynchronously
|
||||
@@ -188,6 +191,10 @@ func (a *PlaylistPage) load() {
|
||||
a.tracks = playlist.Tracks
|
||||
a.tracklist.SetTracks(playlist.Tracks)
|
||||
a.tracklist.SetNowPlaying(a.nowPlayingID)
|
||||
if a.scroll != 0 {
|
||||
a.tracklist.ScrollToOffset(a.scroll)
|
||||
a.scroll = 0
|
||||
}
|
||||
a.header.Update(playlist)
|
||||
})
|
||||
}
|
||||
@@ -495,5 +502,5 @@ func (a *PlaylistPageHeader) formatPlaylistTrackTimeStr(p *mediaprovider.Playlis
|
||||
}
|
||||
|
||||
func (s *playlistPageState) Restore() Page {
|
||||
return newPlaylistPage(s.playlistID, s.conf, s.contr, s.widgetPool, s.sm, s.pm, s.im, s.trackSort)
|
||||
return newPlaylistPage(s.playlistID, s.conf, s.contr, s.widgetPool, s.sm, s.pm, s.im, s.trackSort, s.scroll)
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func (t *TracksPage) OnSongChange(item mediaprovider.MediaItem, lastScrobbledIfA
|
||||
var _ Scrollable = (*TracksPage)(nil)
|
||||
|
||||
func (g *TracksPage) Scroll(scrollAmt float32) {
|
||||
g.tracklist.Scroll(scrollAmt)
|
||||
g.tracklist.ScrollBy(scrollAmt)
|
||||
}
|
||||
|
||||
var _ Searchable = (*TracksPage)(nil)
|
||||
|
||||
Reference in New Issue
Block a user