Skip to content

Commit

Permalink
refactor: Reduce TransferDetailsScreen complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Nov 13, 2024
1 parent f5c7090 commit 9a2361e
Showing 1 changed file with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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,
Expand Down Expand Up @@ -147,6 +124,41 @@ fun TransferDetailsScreen(
}
}

@Composable
private fun ColumnScope.FilesList(
transfer: TransferUi,
recipients: List<String>,
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<String>) {
Text(
Expand Down

0 comments on commit 9a2361e

Please sign in to comment.