|
1 | 1 | package com.w2sv.wifiwidget.ui.screens.widgetconfiguration.components.configuration |
2 | 2 |
|
| 3 | +import androidx.annotation.StringRes |
3 | 4 | import androidx.compose.animation.AnimatedVisibility |
4 | | -import androidx.compose.animation.animateContentSize |
5 | 5 | import androidx.compose.foundation.layout.Box |
6 | 6 | import androidx.compose.foundation.layout.Column |
7 | 7 | import androidx.compose.foundation.layout.Row |
| 8 | +import androidx.compose.foundation.layout.RowScope |
8 | 9 | import androidx.compose.foundation.layout.Spacer |
9 | 10 | import androidx.compose.foundation.layout.fillMaxWidth |
10 | 11 | import androidx.compose.foundation.layout.heightIn |
@@ -51,6 +52,7 @@ import com.w2sv.wifiwidget.ui.designsystem.KeyboardArrowRightIcon |
51 | 52 | import com.w2sv.wifiwidget.ui.designsystem.SubPropertyKeyboardArrowRightIcon |
52 | 53 | import com.w2sv.wifiwidget.ui.designsystem.nestedContentBackground |
53 | 54 | import com.w2sv.wifiwidget.ui.theme.onSurfaceVariantLowAlpha |
| 55 | +import com.w2sv.wifiwidget.ui.utils.ShakeController |
54 | 56 | import com.w2sv.wifiwidget.ui.utils.alphaDecreased |
55 | 57 | import com.w2sv.wifiwidget.ui.utils.contentDescription |
56 | 58 | import com.w2sv.wifiwidget.ui.utils.offsetClip |
@@ -223,7 +225,6 @@ private fun SubPropertyColumn(elements: ImmutableList<ConfigurationColumnElement |
223 | 225 | .padding(start = 24.dp) // Make background start at the indentation of CheckRowBase label |
224 | 226 | .nestedContentBackground() |
225 | 227 | .padding(start = SubPropertyColumnDefaults.startPadding) |
226 | | - .animateContentSize() |
227 | 228 | ) { |
228 | 229 | elements.forEach { element -> |
229 | 230 | when (element) { |
@@ -266,46 +267,68 @@ private fun CheckRowBase( |
266 | 267 | leadingIcon: (@Composable () -> Unit)? = null |
267 | 268 | ) { |
268 | 269 | val label = stringResource(id = data.property.labelRes) |
269 | | - val checkBoxCD = stringResource(id = R.string.set_unset, label) |
| 270 | + PropertyConfigurationRow( |
| 271 | + data.property.labelRes, |
| 272 | + modifier = modifier.then(data.modifier), |
| 273 | + fontSize = fontSize, |
| 274 | + labelColor = labelColor, |
| 275 | + shakeController = data.shakeController, |
| 276 | + explanationRes = data.explanation, |
| 277 | + leadingIcon = leadingIcon |
| 278 | + ) { |
| 279 | + data.showInfoDialog?.let { |
| 280 | + InfoIconButton( |
| 281 | + onClick = it, |
| 282 | + contentDescription = stringResource(id = R.string.info_icon_cd, label) |
| 283 | + ) |
| 284 | + } |
| 285 | + Checkbox( |
| 286 | + checked = data.isChecked(), |
| 287 | + onCheckedChange = { data.onCheckedChange(it) }, |
| 288 | + modifier = Modifier.contentDescription(stringResource(id = R.string.set_unset, label)) |
| 289 | + ) |
| 290 | + } |
| 291 | +} |
270 | 292 |
|
271 | | - Column { |
| 293 | +@Composable |
| 294 | +fun PropertyConfigurationRow( |
| 295 | + @StringRes labelRes: Int, |
| 296 | + modifier: Modifier = Modifier, |
| 297 | + fontSize: TextUnit = TextUnit.Unspecified, |
| 298 | + labelColor: Color = MaterialTheme.colorScheme.onBackground, |
| 299 | + shakeController: ShakeController? = null, |
| 300 | + @StringRes explanationRes: Int? = null, |
| 301 | + leadingIcon: (@Composable () -> Unit)? = null, |
| 302 | + endContent: @Composable RowScope.() -> Unit |
| 303 | +) { |
| 304 | + Column( |
| 305 | + modifier = modifier |
| 306 | + .fillMaxWidth() |
| 307 | + .padding(start = CheckRowDefaults.startPadding) |
| 308 | + .thenIfNotNull(shakeController) { shake(it) }) { |
272 | 309 | Row( |
273 | 310 | verticalAlignment = Alignment.CenterVertically, |
274 | | - modifier = modifier |
275 | | - .fillMaxWidth() |
276 | | - .padding(start = CheckRowDefaults.startPadding) |
277 | | - .then(data.modifier) |
278 | | - .thenIfNotNull(data.shakeController) { shake(it) } |
| 311 | + modifier = Modifier.fillMaxWidth() |
279 | 312 | ) { |
280 | 313 | leadingIcon?.run { |
281 | 314 | invoke() |
282 | 315 | Spacer(Modifier.width(CheckRowDefaults.leadingIconLabelGap)) |
283 | 316 | } |
284 | 317 | Text( |
285 | | - text = label, |
| 318 | + text = stringResource(id = labelRes), |
286 | 319 | modifier = Modifier.weight(1.0f), |
287 | 320 | fontSize = fontSize, |
288 | 321 | color = labelColor |
289 | 322 | ) |
290 | | - data.showInfoDialog?.let { |
291 | | - InfoIconButton( |
292 | | - onClick = it, |
293 | | - contentDescription = stringResource(id = R.string.info_icon_cd, label) |
294 | | - ) |
295 | | - } |
296 | | - Checkbox( |
297 | | - checked = data.isChecked(), |
298 | | - onCheckedChange = { data.onCheckedChange(it) }, |
299 | | - modifier = Modifier.contentDescription(checkBoxCD) |
300 | | - ) |
| 323 | + endContent() |
301 | 324 | } |
302 | | - data.explanation?.let { |
| 325 | + explanationRes?.let { |
303 | 326 | Text( |
304 | 327 | stringResource(it), |
305 | 328 | color = MaterialTheme.colorScheme.onSurfaceVariantLowAlpha, |
306 | 329 | fontSize = 13.sp, |
307 | 330 | modifier = Modifier |
308 | | - .padding(start = 56.dp) |
| 331 | + .padding(start = 52.dp) // Align with label above |
309 | 332 | .offsetClip(dy = (-10).dp) // Shift explanation up a bit to increase its visual coherence with the main row |
310 | 333 | ) |
311 | 334 | } |
|
0 commit comments