1
0
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:
Austin Huang 2021-06-13 11:46:17 -04:00 committed by GitHub
commit 0d7db5237f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,11 +46,20 @@ class FavoritesFragment : Fragment() {
shouldRefresh = false
}
override fun onPause() {
super.onPause()
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT)
}
override fun onResume() {
super.onResume()
if (!this::adapter.isInitialized) return
// 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() {