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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
10 additions and
1 deletions
-
app/src/main/java/awais/instagrabber/fragments/FavoritesFragment.kt
|
|
@ -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() { |
|
|
|