Fix some crashes due to bad UI state (#617)

## Description
Fixes two possible crashes:
- When saving view options for a favorite page tab
- When there are no results on a grid page/tab
This commit is contained in:
Ray 2026-01-02 00:24:17 -05:00 committed by GitHub
parent 0958578082
commit 83a543ad7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 203 additions and 186 deletions

View file

@ -169,6 +169,7 @@ class CollectionFolderViewModel
context.getString(R.string.error_loading_collection, itemId), context.getString(R.string.error_loading_collection, itemId),
) + Dispatchers.IO, ) + Dispatchers.IO,
) { ) {
super.itemId = itemId
itemId.toUUIDOrNull()?.let { itemId.toUUIDOrNull()?.let {
fetchItem(it) fetchItem(it)
} }
@ -206,7 +207,7 @@ class CollectionFolderViewModel
) { ) {
if (collectionFilter.useSavedLibraryDisplayInfo) { if (collectionFilter.useSavedLibraryDisplayInfo) {
serverRepository.currentUser.value?.let { user -> serverRepository.currentUser.value?.let { user ->
viewModelScope.launch(Dispatchers.IO) { viewModelScope.launchIO {
val libraryDisplayInfo = val libraryDisplayInfo =
LibraryDisplayInfo( LibraryDisplayInfo(
userId = user.rowId, userId = user.rowId,

View file

@ -196,6 +196,19 @@ fun <T : CardGridItem> CardGrid(
} }
} }
if (pager.isEmpty()) {
Box(
contentAlignment = Alignment.Center,
modifier = modifier.fillMaxSize(),
) {
Text(
text = stringResource(R.string.no_results),
style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
)
}
} else {
var longPressing by remember { mutableStateOf(false) } var longPressing by remember { mutableStateOf(false) }
Row( Row(
// horizontalArrangement = Arrangement.spacedBy(8.dp), // horizontalArrangement = Arrangement.spacedBy(8.dp),
@ -402,6 +415,7 @@ fun <T : CardGridItem> CardGrid(
) )
} }
} }
}
} }
@Composable @Composable

View file

@ -27,7 +27,7 @@ abstract class ItemViewModel(
) : ViewModel() { ) : ViewModel() {
val item = MutableLiveData<BaseItem?>(null) val item = MutableLiveData<BaseItem?>(null)
lateinit var itemId: String lateinit var itemId: String
lateinit var itemUuid: UUID var itemUuid: UUID? = null
suspend fun fetchItem(itemId: UUID): BaseItem = suspend fun fetchItem(itemId: UUID): BaseItem =
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {

View file

@ -155,8 +155,10 @@ class PersonViewModel
fun setFavorite(favorite: Boolean) { fun setFavorite(favorite: Boolean) {
viewModelScope.launchIO { viewModelScope.launchIO {
favoriteWatchManager.setFavorite(itemUuid, favorite) itemUuid?.let {
fetchAndSetItem(itemUuid) favoriteWatchManager.setFavorite(it, favorite)
fetchAndSetItem(it)
}
} }
} }
} }