Fix index error on home page refresh with empty rows (#1318)

## Description
Fixes an bug caused when the home page has an empty row before the last
row and there are non-empty rows later, an `IndexOutOfBoundsException`
would be thrown.

Also removes the loading indicator if an unknown error occurs during a
refresh.

### Related issues
Fixes #1314

### Testing
Emulator & shield

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Damontecres 2026-04-26 16:09:19 -04:00 committed by GitHub
parent edb37f5d69
commit 8cf99900e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -151,10 +151,6 @@ class HomeViewModel
}
Timber.v("Got row data index=%s", rowIndex)
remaining.removeIf { it.index == rowIndex }
// Include only errors & non-empty successes
if (rowData is HomeRowLoadingState.Error ||
(rowData is HomeRowLoadingState.Success && rowData.items.isNotEmpty())
) {
_state.update { state ->
val newRows =
state.homeRows.toMutableList().apply {
@ -164,9 +160,6 @@ class HomeViewModel
homeRows = newRows,
)
}
} else {
Timber.d("Skipping invalid row %s: %s", rowIndex, rowData)
}
}
_state.update {
it.copy(
@ -175,14 +168,7 @@ class HomeViewModel
)
}
} else {
val rows =
deferred
.awaitAll()
.filter {
// Include only errors & non-empty successes
it is HomeRowLoadingState.Error ||
(it is HomeRowLoadingState.Success && it.items.isNotEmpty())
}
val rows = deferred.awaitAll()
Timber.v("Got all rows")
_state.update {
it.copy(
@ -198,6 +184,7 @@ class HomeViewModel
Timber.e(ex, "Exception during home page loading")
if (state.value.loadingState == LoadingState.Success) {
showToast(context, "Error refreshing home: ${ex.localizedMessage}")
_state.update { it.copy(refreshState = LoadingState.Error(ex)) }
} else {
_state.update {
it.copy(loadingState = LoadingState.Error(ex))