|
@ -2,6 +2,7 @@ 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 |
|
@ -23,6 +24,8 @@ 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 |
|
@ -46,11 +49,19 @@ class FavoritesFragment : Fragment() { |
|
|
shouldRefresh = false |
|
|
shouldRefresh = false |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onPause() { |
|
|
|
|
|
super.onPause() |
|
|
|
|
|
scrollPosition = (root.getLayoutManager() as LinearLayoutManager).findLastVisibleItemPosition() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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 { |
|
|
|
|
|
root.scrollToPosition(scrollPosition)}) |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private fun init() { |
|
|
private fun init() { |
|
|