mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
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:
parent
0958578082
commit
83a543ad7d
4 changed files with 203 additions and 186 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue