Browse Source

Merge pull request #1374 from Vonter/restore_scroll_favorites

Save and Restore scroll position on Favorites Tab - Issue #1359
renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
committed by GitHub
parent
commit
0d7db5237f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt

11
app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt

@ -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…
Cancel
Save