Fixed caching of metadata.
This commit is contained in:
parent
37d5c7b7be
commit
f3bbca9c27
|
@ -10,7 +10,10 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.apognu.otter.repositories.HttpUpstream
|
import com.github.apognu.otter.repositories.HttpUpstream
|
||||||
import com.github.apognu.otter.repositories.Repository
|
import com.github.apognu.otter.repositories.Repository
|
||||||
import com.github.apognu.otter.utils.*
|
import com.github.apognu.otter.utils.Cache
|
||||||
|
import com.github.apognu.otter.utils.Event
|
||||||
|
import com.github.apognu.otter.utils.EventBus
|
||||||
|
import com.github.apognu.otter.utils.untilNetwork
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import kotlinx.android.synthetic.main.fragment_artists.*
|
import kotlinx.android.synthetic.main.fragment_artists.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
@ -103,7 +106,7 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
|
||||||
|
|
||||||
repository.fetch(upstreams, size).untilNetwork(lifecycleScope, IO) { data, isCache, page, hasMore ->
|
repository.fetch(upstreams, size).untilNetwork(lifecycleScope, IO) { data, isCache, page, hasMore ->
|
||||||
if (isCache && data.isEmpty()) {
|
if (isCache && data.isEmpty()) {
|
||||||
fetch(Repository.Origin.Network.origin)
|
return@untilNetwork fetch(Repository.Origin.Network.origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
lifecycleScope.launch(Main) {
|
lifecycleScope.launch(Main) {
|
||||||
|
@ -130,33 +133,31 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when (hasMore) {
|
withContext(IO) {
|
||||||
false -> withContext(IO) {
|
if (adapter.data.isNotEmpty()) {
|
||||||
if (adapter.data.isNotEmpty()) {
|
try {
|
||||||
try {
|
repository.cacheId?.let { cacheId ->
|
||||||
repository.cacheId?.let { cacheId ->
|
Cache.set(
|
||||||
Cache.set(
|
context,
|
||||||
context,
|
cacheId,
|
||||||
cacheId,
|
Gson().toJson(repository.cache(adapter.data)).toByteArray()
|
||||||
Gson().toJson(repository.cache(adapter.data)).toByteArray()
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
} catch (e: ConcurrentModificationException) {
|
|
||||||
}
|
}
|
||||||
|
} catch (e: ConcurrentModificationException) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
true -> {
|
if (hasMore) {
|
||||||
moreLoading = false
|
moreLoading = false
|
||||||
|
|
||||||
(repository.upstream as? HttpUpstream<*, *>)?.let { upstream ->
|
(repository.upstream as? HttpUpstream<*, *>)?.let { upstream ->
|
||||||
if (upstream.behavior == HttpUpstream.Behavior.Progressive) {
|
if (!isCache && upstream.behavior == HttpUpstream.Behavior.Progressive) {
|
||||||
if (page < INITIAL_PAGES) {
|
if (page < INITIAL_PAGES) {
|
||||||
moreLoading = true
|
moreLoading = true
|
||||||
fetch(Repository.Origin.Network.origin, adapter.data.size)
|
fetch(Repository.Origin.Network.origin, adapter.data.size)
|
||||||
} else {
|
} else {
|
||||||
initialFetched = true
|
initialFetched = true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue