Avoid potential crash when opening library settings sheet (#9415)

This commit is contained in:
AntsyLich 2023-04-28 19:08:17 +06:00 committed by GitHub
parent 058ee4c86b
commit 2cb08e6bb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -530,7 +530,10 @@ class LibraryScreenModel(
}
fun showSettingsDialog() {
mutableState.update { it.copy(dialog = Dialog.SettingsSheet) }
mutableState.update {
val category = it.categories.getOrNull(activeCategoryIndex) ?: return@update it
it.copy(dialog = Dialog.SettingsSheet(category))
}
}
fun clearSelection() {
@ -651,7 +654,7 @@ class LibraryScreenModel(
}
sealed class Dialog {
object SettingsSheet : Dialog()
data class SettingsSheet(val category: Category) : Dialog()
data class ChangeCategory(val manga: List<Manga>, val initialSelection: List<CheckboxState<Category>>) : Dialog()
data class DeleteManga(val manga: List<Manga>) : Dialog()
}

View File

@ -205,11 +205,13 @@ object LibraryTab : Tab {
val onDismissRequest = screenModel::closeDialog
when (val dialog = state.dialog) {
is LibraryScreenModel.Dialog.SettingsSheet -> LibrarySettingsDialog(
is LibraryScreenModel.Dialog.SettingsSheet -> {
LibrarySettingsDialog(
onDismissRequest = onDismissRequest,
screenModel = settingsScreenModel,
category = state.categories[screenModel.activeCategoryIndex],
category = dialog.category,
)
}
is LibraryScreenModel.Dialog.ChangeCategory -> {
ChangeCategoryDialog(
initialSelection = dialog.initialSelection,