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),
) + Dispatchers.IO,
) {
super.itemId = itemId
itemId.toUUIDOrNull()?.let {
fetchItem(it)
}
@ -206,7 +207,7 @@ class CollectionFolderViewModel
) {
if (collectionFilter.useSavedLibraryDisplayInfo) {
serverRepository.currentUser.value?.let { user ->
viewModelScope.launch(Dispatchers.IO) {
viewModelScope.launchIO {
val libraryDisplayInfo =
LibraryDisplayInfo(
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) }
Row(
// horizontalArrangement = Arrangement.spacedBy(8.dp),
@ -403,6 +416,7 @@ fun <T : CardGridItem> CardGrid(
}
}
}
}
@Composable
fun JumpButtons(

View file

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

View file

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