Skip to content

Commit

Permalink
refactor: Move content lambdas out of functions parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Oct 25, 2024
1 parent 26aa2ea commit 05fd222
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun EmailAddressChip(
modifier: Modifier = Modifier,
) {
SuggestionChip(
onClick = { },
onClick = {},
label = {
Text(
text = text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,33 @@ fun FileItem(
onRemove: (() -> Unit)? = null,
) {
FileItemContent(
content = {
FilePreview(
file = file,
circleColor = SwissTransferTheme.materialColors.surface,
circleSize = 64.dp,
)
},
onClick = onClick,
isCheckboxVisible = isCheckboxVisible,
isChecked = isChecked,
isRemoveButtonVisible = isRemoveButtonVisible,
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -123,7 +123,7 @@ private fun BottomSheetDefaultsPreview() {
modifier = Modifier
.size(200.dp)
.background(Color.Gray),
) {}
)
},
topButton = {
LargeButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
},
)
}
}
}

Expand Down

0 comments on commit 05fd222

Please sign in to comment.