Browse Source

Fixed a bug where lists would crash if a second page was loaded.

housekeeping/remove-warnings
Antoine POPINEAU 5 years ago
parent
commit
3101fa5302
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 13
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt
  2. 15
      app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt

13
app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt

@ -13,7 +13,6 @@ import com.github.apognu.otter.adapters.AlbumsGridAdapter @@ -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<Album, AlbumsGridAdapter>() {
@ -31,14 +30,12 @@ class AlbumsGridFragment : FunkwhaleFragment<Album, AlbumsGridAdapter>() { @@ -31,14 +30,12 @@ class AlbumsGridFragment : FunkwhaleFragment<Album, AlbumsGridAdapter>() {
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)
}
}

15
app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt

@ -10,6 +10,7 @@ import androidx.recyclerview.widget.RecyclerView @@ -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<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment @@ -52,7 +53,11 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : 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<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment @@ -65,10 +70,12 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
open fun onDataFetched(data: List<D>) {}
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<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment @@ -80,8 +87,6 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
}
if (first && data.isNotEmpty()) {
first = false
adapter.data.clear()
}

Loading…
Cancel
Save