From 05fd222595f7e129d4722ee590eb34ea4b54792a Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Fri, 25 Oct 2024 10:52:36 +0200 Subject: [PATCH] refactor: Move `content` lambdas out of functions parameters --- .../ui/components/EmailAddressChip.kt | 2 +- .../swisstransfer/ui/components/FileItem.kt | 20 +++--- .../ui/components/SwissTransferBottomSheet.kt | 4 +- .../importfiles/ImportFilesScreen.kt | 29 ++++---- .../UploadSourceChoiceBottomSheet.kt | 70 +++++++++---------- 5 files changed, 62 insertions(+), 63 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/EmailAddressChip.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/EmailAddressChip.kt index 59751fce3..c568c68ce 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/EmailAddressChip.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/EmailAddressChip.kt @@ -34,7 +34,7 @@ fun EmailAddressChip( modifier: Modifier = Modifier, ) { SuggestionChip( - onClick = { }, + onClick = {}, label = { Text( text = text, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt index c58df4890..3fc5b980c 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/FileItem.kt @@ -54,13 +54,6 @@ fun FileItem( onRemove: (() -> Unit)? = null, ) { FileItemContent( - content = { - FilePreview( - file = file, - circleColor = SwissTransferTheme.materialColors.surface, - circleSize = 64.dp, - ) - }, onClick = onClick, isCheckboxVisible = isCheckboxVisible, isChecked = isChecked, @@ -68,19 +61,26 @@ fun FileItem( onRemove = onRemove, title = file.fileName, description = Formatter.formatShortFileSize(LocalContext.current, file.fileSizeInBytes), - ) + ) { + FilePreview( + file = file, + circleColor = SwissTransferTheme.materialColors.surface, + circleSize = 64.dp, + ) + } + } @Composable private fun FileItemContent( - content: @Composable () -> Unit, onClick: () -> Unit, isCheckboxVisible: Boolean, isChecked: () -> Boolean, isRemoveButtonVisible: Boolean, onRemove: (() -> Unit)?, title: String, - description: String + description: String, + content: @Composable () -> Unit, ) { Card( onClick = onClick, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferBottomSheet.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferBottomSheet.kt index 6a834f021..664d81405 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferBottomSheet.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/SwissTransferBottomSheet.kt @@ -46,9 +46,9 @@ fun SwissTransferBottomSheet( imageVector: ImageVector? = null, @StringRes titleRes: Int, @StringRes descriptionRes: Int? = null, - content: @Composable (() -> Unit)? = null, topButton: @Composable ((Modifier) -> Unit)? = null, bottomButton: @Composable ((Modifier) -> Unit)? = null, + content: @Composable (() -> Unit)? = null, ) { ModalBottomSheet( modifier = modifier, @@ -123,7 +123,7 @@ private fun BottomSheetDefaultsPreview() { modifier = Modifier .size(200.dp) .background(Color.Gray), - ) {} + ) }, topButton = { LargeButton( diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt index 25136c366..4306bcce2 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt @@ -99,22 +99,21 @@ private fun ImportFilesScreen( onClick = { /*TODO*/ }, ) }, - content = { - ImportedFilesCard( - modifier = Modifier.padding(Margin.Medium), - files = files, - humanReadableSize = { humanReadableSize }, - showUploadSourceChoiceBottomSheet = { showUploadSourceChoiceBottomSheet = true }, - removeFileByUid = removeFileByUid, - ) + ) { + ImportedFilesCard( + modifier = Modifier.padding(Margin.Medium), + files = files, + humanReadableSize = { humanReadableSize }, + showUploadSourceChoiceBottomSheet = { showUploadSourceChoiceBottomSheet = true }, + removeFileByUid = removeFileByUid, + ) - UploadSourceChoiceBottomSheet( - isBottomSheetVisible = { showUploadSourceChoiceBottomSheet }, - onFilePickerClicked = { filePickerLauncher.launch(arrayOf("*/*")) }, - closeBottomSheet = { showUploadSourceChoiceBottomSheet = false }, - ) - }, - ) + UploadSourceChoiceBottomSheet( + isBottomSheetVisible = { showUploadSourceChoiceBottomSheet }, + onFilePickerClicked = { filePickerLauncher.launch(arrayOf("*/*")) }, + closeBottomSheet = { showUploadSourceChoiceBottomSheet = false }, + ) + } } enum class PasswordTransferOption(override val title: @Composable () -> String) : TransferAdvancedOptionsEnum { diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt index f250c329f..0351074a2 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/UploadSourceChoiceBottomSheet.kt @@ -40,41 +40,41 @@ fun UploadSourceChoiceBottomSheet( onFilePickerClicked: () -> Unit, closeBottomSheet: () -> Unit, ) { - if (isBottomSheetVisible()) { - SwissTransferBottomSheet( - onDismissRequest = closeBottomSheet, - titleRes = R.string.transferUploadSourceChoiceTitle, - content = { - Column { - BottomSheetItem( - imageVector = AppIcons.Camera, - titleRes = R.string.transferUploadSourceChoiceCamera, - onClick = { - closeBottomSheet() - /* TODO */ - }, - ) - HorizontalDivider(Modifier.padding(horizontal = Margin.Medium)) - BottomSheetItem( - imageVector = AppIcons.PolaroidLandscape, - titleRes = R.string.transferUploadSourceChoiceGallery, - onClick = { - closeBottomSheet() - /* TODO */ - }, - ) - HorizontalDivider(Modifier.padding(horizontal = Margin.Medium)) - BottomSheetItem( - imageVector = AppIcons.Folder, - titleRes = R.string.transferUploadSourceChoiceFiles, - onClick = { - closeBottomSheet() - onFilePickerClicked() - }, - ) - } - }, - ) + + if (!isBottomSheetVisible()) return + + SwissTransferBottomSheet( + onDismissRequest = closeBottomSheet, + titleRes = R.string.transferUploadSourceChoiceTitle, + ) { + Column { + BottomSheetItem( + imageVector = AppIcons.Camera, + titleRes = R.string.transferUploadSourceChoiceCamera, + onClick = { + closeBottomSheet() + /* TODO */ + }, + ) + HorizontalDivider(Modifier.padding(horizontal = Margin.Medium)) + BottomSheetItem( + imageVector = AppIcons.PolaroidLandscape, + titleRes = R.string.transferUploadSourceChoiceGallery, + onClick = { + closeBottomSheet() + /* TODO */ + }, + ) + HorizontalDivider(Modifier.padding(horizontal = Margin.Medium)) + BottomSheetItem( + imageVector = AppIcons.Folder, + titleRes = R.string.transferUploadSourceChoiceFiles, + onClick = { + closeBottomSheet() + onFilePickerClicked() + }, + ) + } } }