Better error handling for errors on home page rows (#1128)

## Description
Adds better error handling when loading home page rows. For example,
this fixes loading errors if a playlist row is configured, but the
playlist is deleted.

Also fixes an issue from #1116 where changing users doesn't go the home
page.

### Related issues
Related to #1124

### Testing
Emulator

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Ray 2026-03-21 19:17:43 -04:00 committed by GitHub
parent dac0b7208c
commit 920733075b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 33 deletions

View file

@ -438,10 +438,7 @@ class HomeSettingsService
): HomeRowConfigDisplay =
when (config) {
is HomeRowConfig.ByParent -> {
val name =
api.userLibraryApi
.getItem(itemId = config.parentId)
.content.name ?: ""
val name = getItemName(config.parentId) ?: ""
HomeRowConfigDisplay(
id,
name,
@ -466,10 +463,7 @@ class HomeSettingsService
}
is HomeRowConfig.Genres -> {
val name =
api.userLibraryApi
.getItem(itemId = config.parentId)
.content.name ?: ""
val name = getItemName(config.parentId) ?: ""
HomeRowConfigDisplay(
id,
context.getString(R.string.genres_in, name),
@ -490,10 +484,7 @@ class HomeSettingsService
}
is HomeRowConfig.RecentlyAdded -> {
val name =
api.userLibraryApi
.getItem(itemId = config.parentId)
.content.name ?: ""
val name = getItemName(config.parentId) ?: ""
HomeRowConfigDisplay(
id,
context.getString(R.string.recently_added_in, name),
@ -502,10 +493,7 @@ class HomeSettingsService
}
is HomeRowConfig.RecentlyReleased -> {
val name =
api.userLibraryApi
.getItem(itemId = config.parentId)
.content.name ?: ""
val name = getItemName(config.parentId) ?: ""
HomeRowConfigDisplay(
id,
context.getString(R.string.recently_released_in, name),
@ -547,10 +535,7 @@ class HomeSettingsService
}
is HomeRowConfig.Suggestions -> {
val name =
api.userLibraryApi
.getItem(itemId = config.parentId)
.content.name ?: ""
val name = getItemName(config.parentId) ?: ""
HomeRowConfigDisplay(
id = id,
title = context.getString(R.string.suggestions_for, name),
@ -559,6 +544,16 @@ class HomeSettingsService
}
}
private suspend fun getItemName(itemId: UUID): String? =
try {
api.userLibraryApi
.getItem(itemId = itemId)
.content.name
} catch (ex: Exception) {
Timber.e(ex, "Could not get name for %s", itemId)
context.getString(R.string.unknown)
}
/**
* Fetch the data from the server for a given [HomeRowConfig]
*/

View file

@ -1,5 +1,6 @@
package com.github.damontecres.wholphin.services
import androidx.navigation3.runtime.NavBackStack
import com.github.damontecres.wholphin.ui.nav.Destination
import org.acra.ACRA
import timber.log.Timber
@ -13,7 +14,7 @@ import javax.inject.Singleton
class NavigationManager
@Inject
constructor() {
var backStack: MutableList<Destination> = mutableListOf()
var backStack: MutableList<Destination> = NavBackStack(Destination.Home())
/**
* Go to the specified [com.github.damontecres.wholphin.ui.nav.Destination]

View file

@ -16,7 +16,9 @@ import javax.inject.Singleton
@Singleton
class SetupNavigationManager
@Inject
constructor() {
constructor(
private val navigationManager: NavigationManager,
) {
var backStack: MutableList<SetupDestination> = mutableStateListOf(SetupDestination.Loading)
/**
@ -25,6 +27,9 @@ class SetupNavigationManager
fun navigateTo(destination: SetupDestination) {
backStack[0] = destination
log()
if (destination !is SetupDestination.AppContent) {
navigationManager.reloadHome()
}
}
private fun log() {

View file

@ -122,12 +122,12 @@ class HomeSettingsViewModel
state.value
.let { state ->
state.rows
.map { it.config }
.map { row ->
viewModelScope.async(Dispatchers.IO) {
semaphore.withPermit {
try {
homeSettingsService.fetchDataForRow(
row = row,
row = row.config,
scope = viewModelScope,
prefs = prefs,
userDto = userDto,
@ -135,6 +135,10 @@ class HomeSettingsViewModel
limit = limit,
isRefresh = false,
)
} catch (ex: Exception) {
Timber.e(ex, "Error on row %s", row)
HomeRowLoadingState.Error(row.title, exception = ex)
}
}
}
}
@ -195,7 +199,12 @@ class HomeSettingsViewModel
viewModelScope.launchIO {
updateState {
val rows = it.rows.toMutableList().apply { removeAt(index) }
val rowData = it.rowData.toMutableList().apply { removeAt(index) }
val rowData =
if (index in it.rowData.indices) {
it.rowData.toMutableList().apply { removeAt(index) }
} else {
it.rowData
}
it.copy(
rows = rows,
rowData = rowData,