Skip to content

Commit

Permalink
Make isSelected a lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Aug 21, 2024
1 parent 510abee commit e5d87f6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
@Composable
fun SharpRippleButton(
modifier: Modifier = Modifier,
isSelected: Boolean = false,
isSelected: () -> Boolean = { false },
onClick: () -> Unit,
content: @Composable RowScope.() -> Unit,
) {
val colors = if (isSelected) {
val colors = if (isSelected()) {
ButtonDefaults.textButtonColors(
contentColor = SwissTransferTheme.colors.primaryTextColor,
containerColor = SwissTransferTheme.colors.selectedSettingItem,
Expand All @@ -46,7 +46,7 @@ fun SharpRippleButton(
}
Button(
modifier = modifier.selectable(
selected = isSelected,
selected = isSelected(),
onClick = onClick,
),
colors = colors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ private fun SettingsScreen(onItemClick: (SettingsOptionScreens) -> Unit, getSele

SettingTitle(R.string.settingsCategoryGeneral)
// TODO: Use correct icon
SettingItem(R.string.settingsOptionTheme, selectedMenu == THEME, AppIcons.Add, "TODO", CHEVRON) { onItemClick(THEME) }
SettingItem(R.string.settingsOptionTheme, { selectedMenu == THEME }, AppIcons.Add, "TODO", CHEVRON) { onItemClick(THEME) }
SettingItem(
R.string.settingsOptionNotifications,
selectedMenu == NOTIFICATIONS,
AppIcons.Bell,
"TODO",
titleRes = R.string.settingsOptionNotifications,
isSelected = { selectedMenu == NOTIFICATIONS },
icon = AppIcons.Bell,
description = "TODO",
endIcon = OPEN_OUTSIDE,
) {
onItemClick(NOTIFICATIONS)
Expand All @@ -127,29 +127,29 @@ private fun SettingsScreen(onItemClick: (SettingsOptionScreens) -> Unit, getSele
SettingTitle(R.string.settingsCategoryDefaultSettings)
// TODO: Use correct icon
SettingItem(
R.string.settingsOptionValidityPeriod,
selectedMenu == VALIDITY_PERIOD,
AppIcons.Add,
"TODO",
titleRes = R.string.settingsOptionValidityPeriod,
isSelected = { selectedMenu == VALIDITY_PERIOD },
icon = AppIcons.Add,
description = "TODO",
endIcon = CHEVRON,
) {
onItemClick(VALIDITY_PERIOD)
}
// TODO: Use correct icon
SettingItem(
R.string.settingsOptionDownloadLimit,
selectedMenu == DOWNLOAD_LIMIT,
AppIcons.Add,
"TODO",
titleRes = R.string.settingsOptionDownloadLimit,
isSelected = { selectedMenu == DOWNLOAD_LIMIT },
icon = AppIcons.Add,
description = "TODO",
endIcon = CHEVRON,
) {
onItemClick(DOWNLOAD_LIMIT)
}
SettingItem(
R.string.settingsOptionEmailLanguage,
selectedMenu == EMAIL_LANGUAGE,
AppIcons.SpeechBubble,
"TODO",
titleRes = R.string.settingsOptionEmailLanguage,
isSelected = { selectedMenu == EMAIL_LANGUAGE },
icon = AppIcons.SpeechBubble,
description = "TODO",
endIcon = CHEVRON,
) {
onItemClick(EMAIL_LANGUAGE)
Expand All @@ -158,16 +158,16 @@ private fun SettingsScreen(onItemClick: (SettingsOptionScreens) -> Unit, getSele
SettingDivider()

SettingTitle(R.string.settingsCategoryAbout)
SettingItem(R.string.settingsOptionDiscoverInfomaniak, selectedMenu == DISCOVER_INFOMANIAK, endIcon = OPEN_OUTSIDE) {
SettingItem(R.string.settingsOptionDiscoverInfomaniak, { selectedMenu == DISCOVER_INFOMANIAK }, endIcon = OPEN_OUTSIDE) {
onItemClick(DISCOVER_INFOMANIAK)
}
SettingItem(R.string.settingsOptionShareIdeas, selectedMenu == SHARE_IDEAS, endIcon = OPEN_OUTSIDE) {
SettingItem(R.string.settingsOptionShareIdeas, { selectedMenu == SHARE_IDEAS }, endIcon = OPEN_OUTSIDE) {
onItemClick(SHARE_IDEAS)
}
SettingItem(R.string.settingsOptionGiveFeedback, selectedMenu == GIVE_FEEDBACK, endIcon = OPEN_OUTSIDE) {
SettingItem(R.string.settingsOptionGiveFeedback, { selectedMenu == GIVE_FEEDBACK }, endIcon = OPEN_OUTSIDE) {
onItemClick(GIVE_FEEDBACK)
}
SettingItem(R.string.version, isSelected = false, description = "0.0.1", onClick = null)
SettingItem(R.string.version, isSelected = { false }, description = "0.0.1", onClick = null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private val ITEM_MIN_HEIGHT = 56.dp
@Composable
fun SettingItem(
@StringRes titleRes: Int,
isSelected: Boolean,
isSelected: () -> Boolean,
icon: ImageVector? = null,
description: String? = null,
endIcon: EndIconType? = null,
Expand Down Expand Up @@ -119,15 +119,15 @@ private fun SettingItemPreview() {
Surface {
Column(modifier = Modifier.selectableGroup()) {
SettingTitle(R.string.appName)
SettingItem(R.string.appName, true, AppIcons.Add, "Clair", EndIconType.CHEVRON) {}
SettingItem(R.string.appName, false, AppIcons.Folder, endIcon = EndIconType.OPEN_OUTSIDE) {}
SettingItem(R.string.appName, false, description = "1.1.2") {}
SettingItem(R.string.appName, false) {}
SettingItem(R.string.appName, { true }, AppIcons.Add, "Clair", EndIconType.CHEVRON) {}
SettingItem(R.string.appName, { false }, AppIcons.Folder, endIcon = EndIconType.OPEN_OUTSIDE) {}
SettingItem(R.string.appName, { false }, description = "1.1.2") {}
SettingItem(R.string.appName, { false }) {}
SettingDivider()
SettingTitle(R.string.appName)
SettingItem(R.string.appName, false, endIcon = EndIconType.OPEN_OUTSIDE) {}
SettingItem(R.string.appName, false, endIcon = EndIconType.OPEN_OUTSIDE) {}
SettingItem(R.string.appName, false, description = "0.0.1", onClick = null)
SettingItem(R.string.appName, { false }, endIcon = EndIconType.OPEN_OUTSIDE) {}
SettingItem(R.string.appName, { false }, endIcon = EndIconType.OPEN_OUTSIDE) {}
SettingItem(R.string.appName, { false }, description = "0.0.1", onClick = null)
}
}
}
Expand Down

0 comments on commit e5d87f6

Please sign in to comment.