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 {
|
type albumPageState struct {
|
||||||
albumID string
|
albumID string
|
||||||
sort widgets.TracklistSort
|
sort widgets.TracklistSort
|
||||||
|
scroll float32
|
||||||
cfg *backend.AlbumPageConfig
|
cfg *backend.AlbumPageConfig
|
||||||
pool *util.WidgetPool
|
pool *util.WidgetPool
|
||||||
mp mediaprovider.MediaProvider
|
mp mediaprovider.MediaProvider
|
||||||
@@ -54,7 +55,7 @@ func NewAlbumPage(
|
|||||||
im *backend.ImageManager,
|
im *backend.ImageManager,
|
||||||
contr *controller.Controller,
|
contr *controller.Controller,
|
||||||
) *AlbumPage {
|
) *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(
|
func newAlbumPage(
|
||||||
@@ -66,6 +67,7 @@ func newAlbumPage(
|
|||||||
im *backend.ImageManager,
|
im *backend.ImageManager,
|
||||||
contr *controller.Controller,
|
contr *controller.Controller,
|
||||||
sort widgets.TracklistSort,
|
sort widgets.TracklistSort,
|
||||||
|
scroll float32,
|
||||||
) *AlbumPage {
|
) *AlbumPage {
|
||||||
a := &AlbumPage{
|
a := &AlbumPage{
|
||||||
albumPageState: albumPageState{
|
albumPageState: albumPageState{
|
||||||
@@ -76,6 +78,7 @@ func newAlbumPage(
|
|||||||
mp: mp,
|
mp: mp,
|
||||||
im: im,
|
im: im,
|
||||||
contr: contr,
|
contr: contr,
|
||||||
|
scroll: scroll,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
a.ExtendBaseWidget(a)
|
a.ExtendBaseWidget(a)
|
||||||
@@ -122,6 +125,7 @@ func (a *AlbumPage) Save() SavedPage {
|
|||||||
a.tracklist.SetLoading(false)
|
a.tracklist.SetLoading(false)
|
||||||
s := a.albumPageState
|
s := a.albumPageState
|
||||||
s.sort = a.tracklist.Sorting()
|
s.sort = a.tracklist.Sorting()
|
||||||
|
s.scroll = a.tracklist.GetScrollOffset()
|
||||||
a.header.page = nil
|
a.header.page = nil
|
||||||
a.pool.Release(util.WidgetTypeAlbumPageHeader, a.header)
|
a.pool.Release(util.WidgetTypeAlbumPageHeader, a.header)
|
||||||
a.tracklist.Clear()
|
a.tracklist.Clear()
|
||||||
@@ -159,7 +163,7 @@ func (a *AlbumPage) UnselectAll() {
|
|||||||
var _ Scrollable = (*AlbumPage)(nil)
|
var _ Scrollable = (*AlbumPage)(nil)
|
||||||
|
|
||||||
func (a *AlbumPage) Scroll(scrollAmt float32) {
|
func (a *AlbumPage) Scroll(scrollAmt float32) {
|
||||||
a.tracklist.Scroll(scrollAmt)
|
a.tracklist.ScrollBy(scrollAmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be called asynchronously
|
// should be called asynchronously
|
||||||
@@ -188,6 +192,10 @@ func (a *AlbumPage) load() {
|
|||||||
a.tracks = album.Tracks
|
a.tracks = album.Tracks
|
||||||
a.tracklist.SetTracks(album.Tracks)
|
a.tracklist.SetTracks(album.Tracks)
|
||||||
a.tracklist.SetNowPlaying(a.nowPlayingID)
|
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 {
|
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
|
grid = a.artistGrid
|
||||||
default:
|
default:
|
||||||
if tr := a.tracklistOrNil(); tr != nil {
|
if tr := a.tracklistOrNil(); tr != nil {
|
||||||
tr.Scroll(amount)
|
tr.ScrollBy(amount)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ type playlistPageState struct {
|
|||||||
pm *backend.PlaybackManager
|
pm *backend.PlaybackManager
|
||||||
im *backend.ImageManager
|
im *backend.ImageManager
|
||||||
trackSort widgets.TracklistSort
|
trackSort widgets.TracklistSort
|
||||||
|
scroll float32
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPlaylistPage(
|
func NewPlaylistPage(
|
||||||
@@ -57,7 +58,7 @@ func NewPlaylistPage(
|
|||||||
pm *backend.PlaybackManager,
|
pm *backend.PlaybackManager,
|
||||||
im *backend.ImageManager,
|
im *backend.ImageManager,
|
||||||
) *PlaylistPage {
|
) *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(
|
func newPlaylistPage(
|
||||||
@@ -69,8 +70,9 @@ func newPlaylistPage(
|
|||||||
pm *backend.PlaybackManager,
|
pm *backend.PlaybackManager,
|
||||||
im *backend.ImageManager,
|
im *backend.ImageManager,
|
||||||
trackSort widgets.TracklistSort,
|
trackSort widgets.TracklistSort,
|
||||||
|
scroll float32,
|
||||||
) *PlaylistPage {
|
) *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)
|
a.ExtendBaseWidget(a)
|
||||||
if h := a.widgetPool.Obtain(util.WidgetTypePlaylistPageHeader); h != nil {
|
if h := a.widgetPool.Obtain(util.WidgetTypePlaylistPageHeader); h != nil {
|
||||||
a.header = h.(*PlaylistPageHeader)
|
a.header = h.(*PlaylistPageHeader)
|
||||||
@@ -123,6 +125,7 @@ func (a *PlaylistPage) Save() SavedPage {
|
|||||||
a.tracklist.SetLoading(false)
|
a.tracklist.SetLoading(false)
|
||||||
p := a.playlistPageState
|
p := a.playlistPageState
|
||||||
p.trackSort = a.tracklist.Sorting()
|
p.trackSort = a.tracklist.Sorting()
|
||||||
|
p.scroll = a.tracklist.GetScrollOffset()
|
||||||
p.widgetPool.Release(util.WidgetTypePlaylistPageHeader, a.header)
|
p.widgetPool.Release(util.WidgetTypePlaylistPageHeader, a.header)
|
||||||
a.tracklist.Clear()
|
a.tracklist.Clear()
|
||||||
a.tracklist.OnReorderTracks = nil
|
a.tracklist.OnReorderTracks = nil
|
||||||
@@ -160,7 +163,7 @@ func (a *PlaylistPage) UnselectAll() {
|
|||||||
var _ Scrollable = (*PlaylistPage)(nil)
|
var _ Scrollable = (*PlaylistPage)(nil)
|
||||||
|
|
||||||
func (a *PlaylistPage) Scroll(scrollAmt float32) {
|
func (a *PlaylistPage) Scroll(scrollAmt float32) {
|
||||||
a.tracklist.Scroll(scrollAmt)
|
a.tracklist.ScrollBy(scrollAmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// should be called asynchronously
|
// should be called asynchronously
|
||||||
@@ -188,6 +191,10 @@ func (a *PlaylistPage) load() {
|
|||||||
a.tracks = playlist.Tracks
|
a.tracks = playlist.Tracks
|
||||||
a.tracklist.SetTracks(playlist.Tracks)
|
a.tracklist.SetTracks(playlist.Tracks)
|
||||||
a.tracklist.SetNowPlaying(a.nowPlayingID)
|
a.tracklist.SetNowPlaying(a.nowPlayingID)
|
||||||
|
if a.scroll != 0 {
|
||||||
|
a.tracklist.ScrollToOffset(a.scroll)
|
||||||
|
a.scroll = 0
|
||||||
|
}
|
||||||
a.header.Update(playlist)
|
a.header.Update(playlist)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -495,5 +502,5 @@ func (a *PlaylistPageHeader) formatPlaylistTrackTimeStr(p *mediaprovider.Playlis
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *playlistPageState) Restore() Page {
|
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)
|
var _ Scrollable = (*TracksPage)(nil)
|
||||||
|
|
||||||
func (g *TracksPage) Scroll(scrollAmt float32) {
|
func (g *TracksPage) Scroll(scrollAmt float32) {
|
||||||
g.tracklist.Scroll(scrollAmt)
|
g.tracklist.ScrollBy(scrollAmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Searchable = (*TracksPage)(nil)
|
var _ Searchable = (*TracksPage)(nil)
|
||||||
|
|||||||
@@ -215,10 +215,18 @@ func (t *Tracklist) SetLoading(loading bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracklist) Scroll(amount float32) {
|
func (t *Tracklist) ScrollBy(amount float32) {
|
||||||
t.list.ScrollToOffset(t.list.GetScrollOffset() + amount)
|
t.list.ScrollToOffset(t.list.GetScrollOffset() + amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) GetScrollOffset() float32 {
|
||||||
|
return t.list.GetScrollOffset()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Tracklist) ScrollToOffset(offset float32) {
|
||||||
|
t.list.ScrollToOffset(offset)
|
||||||
|
}
|
||||||
|
|
||||||
// Gets the track at the given index.
|
// Gets the track at the given index.
|
||||||
func (t *Tracklist) TrackAt(idx int) *mediaprovider.Track {
|
func (t *Tracklist) TrackAt(idx int) *mediaprovider.Track {
|
||||||
if idx >= len(t.tracks) {
|
if idx >= len(t.tracks) {
|
||||||
|
|||||||
Reference in New Issue
Block a user