mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Merge pull request #1374 from Vonter/restore_scroll_favorites
Save and Restore scroll position on Favorites Tab - Issue #1359
This commit is contained in:
commit
0d7db5237f
@ -46,11 +46,20 @@ class FavoritesFragment : Fragment() {
|
|||||||
shouldRefresh = false
|
shouldRefresh = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPause() {
|
||||||
|
super.onPause()
|
||||||
|
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
if (!this::adapter.isInitialized) return
|
if (!this::adapter.isInitialized) return
|
||||||
// refresh list every time in onViewStateRestored since it is cheaper than implementing pull down to refresh
|
// refresh list every time in onViewStateRestored since it is cheaper than implementing pull down to refresh
|
||||||
favoritesViewModel.list.observe(viewLifecycleOwner, { list: List<Favorite?>? -> adapter.submitList(list) })
|
favoritesViewModel.list.observe(viewLifecycleOwner, {
|
||||||
|
list: List<Favorite?>? -> adapter.submitList(list, Runnable {
|
||||||
|
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.ALLOW)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun init() {
|
private fun init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user