android, desktop: gaurd crashes when item is absent in the list (#6140)

This commit is contained in:
Evgeny
2025-08-01 16:18:55 +01:00
committed by GitHub
parent 9a8ed40082
commit d3a5936d17
6 changed files with 13 additions and 10 deletions
@@ -159,11 +159,11 @@ fun AppearanceScope.AppearanceLayout(
}
}
private fun findEnabledIcon(): AppIcon = AppIcon.values().first { icon ->
private fun findEnabledIcon(): AppIcon = AppIcon.values().firstOrNull { icon ->
androidAppContext.packageManager.getComponentEnabledSetting(
ComponentName(APPLICATION_ID, "chat.simplex.app.MainActivity_${icon.name.lowercase()}")
).let { it == COMPONENT_ENABLED_STATE_DEFAULT || it == COMPONENT_ENABLED_STATE_ENABLED }
}
} ?: AppIcon.DEFAULT
@Preview
@Composable
@@ -46,7 +46,7 @@ fun <T> ExposedDropDownSetting(
horizontalArrangement = Arrangement.End
) {
Text(
values.first { it.first == selection.value }.second + (if (label != null) " $label" else ""),
(values.firstOrNull { it.first == selection.value }?.second ?: "") + (if (label != null) " $label" else ""),
Modifier.widthIn(max = maxWidth),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
@@ -120,8 +120,10 @@ fun <T> ExposedDropDownSettingWithIcon(
),
contentAlignment = Alignment.Center
) {
val choice = values.first { it.first == selection.value }
Icon(painterResource(choice.second), choice.third, Modifier.padding(boxSize * iconPaddingPercent).fillMaxSize(), tint = iconColor)
val choice = values.firstOrNull { it.first == selection.value }
if (choice != null) {
Icon(painterResource(choice.second), choice.third, Modifier.padding(boxSize * iconPaddingPercent).fillMaxSize(), tint = iconColor)
}
}
DefaultExposedDropdownMenu(
modifier = Modifier.widthIn(min = minWidth),
@@ -91,7 +91,7 @@ fun <T> SectionViewSelectable(
}
}
}
SectionTextFooter(values.first { it.value == currentValue.value }.description)
SectionTextFooter(values.firstOrNull { it.value == currentValue.value }?.description ?: AnnotatedString(""))
}
@Composable
@@ -221,7 +221,7 @@ fun <T> SectionItemWithValue(
horizontalArrangement = Arrangement.End
) {
Text(
values.first { it.value == currentValue.value }.title + (if (label != null) " $label" else ""),
(values.firstOrNull { it.value == currentValue.value }?.title ?: "") + (if (label != null) " $label" else ""),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colors.secondary
@@ -62,7 +62,7 @@ fun NotificationsSettingsLayout(
if (appPlatform == AppPlatform.ANDROID) {
SettingsActionItemWithContent(null, stringResource(MR.strings.settings_notifications_mode_title), { showPage(CurrentPage.NOTIFICATIONS_MODE) }) {
Text(
modes.first { it.value == notificationsMode.value }.title,
modes.firstOrNull { it.value == notificationsMode.value }?.title ?: "",
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colors.secondary
@@ -71,7 +71,7 @@ fun NotificationsSettingsLayout(
}
SettingsActionItemWithContent(null, stringResource(MR.strings.settings_notification_preview_mode_title), { showPage(CurrentPage.NOTIFICATION_PREVIEW_MODE) }) {
Text(
previewModes.first { it.value == notificationPreviewMode.value }.title,
previewModes.firstOrNull { it.value == notificationPreviewMode.value }?.title ?: "",
maxLines = 1,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colors.secondary
@@ -594,7 +594,7 @@ fun UseOnionHosts(
onSelected = {}
)
}
SectionTextFooter(values.first { it.value == onionHosts.value }.description)
SectionTextFooter(values.firstOrNull { it.value == onionHosts.value }?.description ?: AnnotatedString(""))
}
}
@@ -31,6 +31,7 @@ actual fun CustomTimePicker(
mutableStateOf(res)
}
val values = remember(unit.value) {
// TODO replace with firstOrNull
val limit = timeUnitsLimits.first { it.timeUnit == unit.value }
val res = ArrayList<Pair<Int, String>>()
for (i in limit.minValue..limit.maxValue) {