From 7d18520e59126399989a9195e0b45b80a9d60da7 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Tue, 12 Nov 2024 17:15:14 +0100 Subject: [PATCH] refactor: Reduce `TransferDetailsScreen` complexity --- .../transferdetails/TransferDetailsScreen.kt | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt index 50ddbfec3..1d2c88fe1 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/transferdetails/TransferDetailsScreen.kt @@ -72,9 +72,6 @@ fun TransferDetailsScreen( // val transferUrl = transferDetailsViewModel.getTransferUrl(transferUuid) val transferPassword = "toto42" // TODO: Use real data - val shouldDisplayRecipients = recipients.isNotEmpty() - val shouldDisplayMessage = transfer.message != null - var isMultiselectOn: Boolean by rememberSaveable { mutableStateOf(false) } var isQrCodeVisible: Boolean by rememberSaveable { mutableStateOf(false) } var isPasswordVisible: Boolean by rememberSaveable { mutableStateOf(false) } @@ -90,27 +87,7 @@ fun TransferDetailsScreen( ) { Column { - FileItemList( - modifier = Modifier - .weight(1.0f) - .padding(horizontal = Margin.Medium), - files = transfer.files, - isRemoveButtonVisible = false, - isCheckboxVisible = { isMultiselectOn }, - isUidChecked = { fileUid -> transferDetailsViewModel.checkedFiles[fileUid] ?: false }, - setUidCheckStatus = { fileUid, isChecked -> transferDetailsViewModel.checkedFiles[fileUid] = isChecked }, - ) { - Column { - Spacer(modifier = Modifier.height(Margin.Large)) - TransferInfo(transfer) - Spacer(modifier = Modifier.height(Margin.Large)) - if (shouldDisplayRecipients) TransferRecipients(recipients) - if (shouldDisplayRecipients && shouldDisplayMessage) Spacer(modifier = Modifier.height(Margin.Mini)) - if (shouldDisplayMessage) TransferMessage(transfer) - if (shouldDisplayRecipients || shouldDisplayMessage) Spacer(modifier = Modifier.height(Margin.Large)) - TransferContentHeader() - } - } + FilesList(transfer, recipients, isMultiselectOn, transferDetailsViewModel) BottomBar( direction = direction, @@ -147,6 +124,41 @@ fun TransferDetailsScreen( } } +@Composable +private fun ColumnScope.FilesList( + transfer: TransferUi, + recipients: List, + isMultiselectOn: Boolean, + transferDetailsViewModel: TransferDetailsViewModel, +) { + + val shouldDisplayRecipients = recipients.isNotEmpty() + val shouldDisplayMessage = transfer.message != null + + FileItemList( + modifier = Modifier + .weight(1.0f) + .padding(horizontal = Margin.Medium), + files = transfer.files, + isRemoveButtonVisible = false, + isCheckboxVisible = { isMultiselectOn }, + isUidChecked = { fileUid -> transferDetailsViewModel.checkedFiles[fileUid] ?: false }, + setUidCheckStatus = { fileUid, isChecked -> transferDetailsViewModel.checkedFiles[fileUid] = isChecked }, + header = { + Column { + Spacer(modifier = Modifier.height(Margin.Large)) + TransferInfo(transfer) + Spacer(modifier = Modifier.height(Margin.Large)) + if (shouldDisplayRecipients) TransferRecipients(recipients) + if (shouldDisplayRecipients && shouldDisplayMessage) Spacer(modifier = Modifier.height(Margin.Mini)) + if (shouldDisplayMessage) TransferMessage(transfer) + if (shouldDisplayRecipients || shouldDisplayMessage) Spacer(modifier = Modifier.height(Margin.Large)) + TransferContentHeader() + } + }, + ) +} + @Composable private fun TransferRecipients(recipients: List) { Text(