From 3101fa5302d6da7e5e0dac5b1014402b26c075c8 Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Mon, 25 Nov 2019 21:39:10 +0100 Subject: [PATCH] Fixed a bug where lists would crash if a second page was loaded. --- .../apognu/otter/fragments/AlbumsGridFragment.kt | 13 +++++-------- .../apognu/otter/fragments/FunkwhaleFragment.kt | 15 ++++++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt b/app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt index e0c56ed..592853a 100644 --- a/app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt +++ b/app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt @@ -13,7 +13,6 @@ import com.github.apognu.otter.adapters.AlbumsGridAdapter import com.github.apognu.otter.repositories.AlbumsRepository import com.github.apognu.otter.utils.Album import com.github.apognu.otter.utils.AppContext -import com.github.apognu.otter.utils.onViewPager import kotlinx.android.synthetic.main.fragment_albums_grid.* class AlbumsGridFragment : FunkwhaleFragment() { @@ -31,14 +30,12 @@ class AlbumsGridFragment : FunkwhaleFragment() { inner class OnAlbumClickListener : AlbumsGridAdapter.OnAlbumClickListener { override fun onClick(view: View?, album: Album) { (context as? MainActivity)?.let { activity -> - onViewPager { - exitTransition = Fade().apply { - duration = AppContext.TRANSITION_DURATION - interpolator = AccelerateDecelerateInterpolator() + exitTransition = Fade().apply { + duration = AppContext.TRANSITION_DURATION + interpolator = AccelerateDecelerateInterpolator() - view?.let { - addTarget(it) - } + view?.let { + addTarget(it) } } diff --git a/app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt b/app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt index 95040a1..ff358b3 100644 --- a/app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt +++ b/app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt @@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView import com.github.apognu.otter.repositories.HttpUpstream import com.github.apognu.otter.repositories.Repository import com.github.apognu.otter.utils.Cache +import com.github.apognu.otter.utils.log import com.github.apognu.otter.utils.untilNetwork import com.google.gson.Gson import kotlinx.android.synthetic.main.fragment_artists.* @@ -52,7 +53,11 @@ abstract class FunkwhaleFragment> : Fragment } } - fetch() + fetch(Repository.Origin.Cache.origin) + + if (adapter.data.isEmpty()) { + fetch(Repository.Origin.Network.origin) + } } override fun onResume() { @@ -65,10 +70,12 @@ abstract class FunkwhaleFragment> : Fragment open fun onDataFetched(data: List) {} - private fun fetch(upstreams: Int = (Repository.Origin.Network.origin and Repository.Origin.Cache.origin), size: Int = 0) { + private fun fetch(upstreams: Int = Repository.Origin.Network.origin, size: Int = 0) { var first = size == 0 - swiper?.isRefreshing = true + if (upstreams == Repository.Origin.Network.origin) { + swiper?.isRefreshing = true + } repository.fetch(upstreams, size).untilNetwork(IO) { data, isCache, hasMore -> GlobalScope.launch(Main) { @@ -80,8 +87,6 @@ abstract class FunkwhaleFragment> : Fragment } if (first && data.isNotEmpty()) { - first = false - adapter.data.clear() }