mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 06:37:30 +00:00
Change favorites tab scroll position restore to use StateRestorationPolicy
This commit is contained in:
parent
caa71faab1
commit
257d707c14
@ -2,7 +2,6 @@ package awais.instagrabber.fragments
|
|||||||
|
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -24,8 +23,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|||||||
class FavoritesFragment : Fragment() {
|
class FavoritesFragment : Fragment() {
|
||||||
private var shouldRefresh = true
|
private var shouldRefresh = true
|
||||||
|
|
||||||
private var scrollPosition = 0
|
|
||||||
|
|
||||||
private lateinit var binding: FragmentFavoritesBinding
|
private lateinit var binding: FragmentFavoritesBinding
|
||||||
private lateinit var root: RecyclerView
|
private lateinit var root: RecyclerView
|
||||||
private lateinit var adapter: FavoritesAdapter
|
private lateinit var adapter: FavoritesAdapter
|
||||||
@ -51,7 +48,7 @@ class FavoritesFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
scrollPosition = (root.getLayoutManager() as LinearLayoutManager).findLastVisibleItemPosition()
|
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
@ -60,8 +57,9 @@ class FavoritesFragment : Fragment() {
|
|||||||
// 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, {
|
favoritesViewModel.list.observe(viewLifecycleOwner, {
|
||||||
list: List<Favorite?>? -> adapter.submitList(list, Runnable {
|
list: List<Favorite?>? -> adapter.submitList(list, Runnable {
|
||||||
root.scrollToPosition(scrollPosition)})
|
adapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.ALLOW)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun init() {
|
private fun init() {
|
||||||
|
Loading…
Reference in New Issue
Block a user