mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
itch.io browse: let a failed page be retried instead of ending the list
This commit is contained in:
3 files changed
+13
-6
No files matched your search
@@ -151,8 +151,9 @@ internal object ItchBrowseState {
|
||||
if (active) more(context)
|
||||
}
|
||||
|
||||
fun more(context: Context) {
|
||||
if (loading || ended || !active) return
|
||||
/** Asks for the next page. A page that failed is only asked for again when [retry] is set, so scrolling can't loop on it. */
|
||||
fun more(context: Context, retry: Boolean = false) {
|
||||
if (loading || ended || !active || (failed && !retry)) return
|
||||
loading = true
|
||||
failed = false
|
||||
val app = context.applicationContext
|
||||
@@ -164,13 +165,12 @@ internal object ItchBrowseState {
|
||||
StoresState.post {
|
||||
if (mine != generation) return@post
|
||||
loading = false
|
||||
if (answer == null) {
|
||||
failed = items.isEmpty()
|
||||
ended = items.isNotEmpty()
|
||||
// A thrown or non-2xx fetch leaves the list open so the same page can be asked for again.
|
||||
if (answer == null || answer.code !in 200..299) {
|
||||
failed = true
|
||||
return@post
|
||||
}
|
||||
if (answer.items.isEmpty()) {
|
||||
failed = items.isEmpty() && answer.code !in 200..299
|
||||
ended = true
|
||||
return@post
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ internal fun ItchLoadMore() {
|
||||
val count = ItchBrowseState.items.size
|
||||
LaunchedEffect(count) { ItchBrowseState.more(ctx) }
|
||||
if (ItchBrowseState.loading) LinearProgressIndicator(Modifier.fillMaxWidth().padding(vertical = 12.dp))
|
||||
else if (ItchBrowseState.failed) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
|
||||
BrowseChip(stringResource(R.string.stores_dl_retry), false) { ItchBrowseState.more(ctx, retry = true) }
|
||||
}
|
||||
else if (!ItchBrowseState.ended && count > 0) Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {
|
||||
BrowseChip(stringResource(R.string.stores_itch_load_more), false) { ItchBrowseState.more(ctx) }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user