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 d6bf94639..ac49958fd 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 @@ -57,10 +57,10 @@ private fun ImportFilesScreen( ) { val context = LocalContext.current var showUploadSourceChoiceBottomSheet by rememberSaveable { mutableStateOf(true) } - val formattedSizeWithUnits by remember { + val humanReadableSize by remember { derivedStateOf { val totalFileSize = files().sumOf { it.fileSizeInBytes } - getFormattedSizeWithUnits(totalFileSize, context) + getHumanReadableSize(totalFileSize, context) } } val isSendButtonEnabled by remember { derivedStateOf { files().isNotEmpty() } } @@ -92,7 +92,7 @@ private fun ImportFilesScreen( SelectedFilesCard( modifier = Modifier.padding(Margin.Medium), files = files, - formattedSizeWithUnits = { formattedSizeWithUnits }, + humanReadableSize = { humanReadableSize }, showUploadSourceChoiceBottomSheet = { showUploadSourceChoiceBottomSheet = true }, removeFileByUid = removeFileByUid, ) @@ -106,7 +106,7 @@ private fun ImportFilesScreen( ) } -private fun getFormattedSizeWithUnits(usedSpace: Long, context: Context): String { +private fun getHumanReadableSize(usedSpace: Long, context: Context): String { val spaceLeft = (TOTAL_FILE_SIZE - usedSpace).coerceAtLeast(0) return Formatter.formatShortFileSize(context, spaceLeft) } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/SelectedFilesCard.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/SelectedFilesCard.kt index bb362063f..a04dc74f8 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/SelectedFilesCard.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/SelectedFilesCard.kt @@ -51,7 +51,7 @@ import kotlinx.parcelize.Parcelize fun SelectedFilesCard( modifier: Modifier = Modifier, files: () -> List, - formattedSizeWithUnits: () -> String, + humanReadableSize: () -> String, showUploadSourceChoiceBottomSheet: () -> Unit, removeFileByUid: (uid: String) -> Unit, ) { @@ -72,7 +72,7 @@ fun SelectedFilesCard( style = SwissTransferTheme.typography.bodySmallRegular, ) Text( - formatSpaceLeft(formattedSizeWithUnits), + formatSpaceLeft(humanReadableSize), color = SwissTransferTheme.colors.secondaryTextColor, style = SwissTransferTheme.typography.bodySmallRegular, ) @@ -110,14 +110,15 @@ fun SelectedFilesCard( } @Composable -private fun formatSpaceLeft(formattedSizeWithUnits: () -> String): String { - val formattedSize = formattedSizeWithUnits() - val quantity = LocalContext.current.getQuantityFromFormattedSizeWithUnits(formattedSize) +private fun formatSpaceLeft(humanReadableSize: () -> String): String { + val formattedSize = humanReadableSize() + val quantity = LocalContext.current.getQuantityFromHumanReadableSize(formattedSize) return pluralStringResource(R.plurals.transferSpaceLeft, quantity, formattedSize) } -private fun Context.getQuantityFromFormattedSizeWithUnits(formattedSize: String): Int { - val sizeParts = formattedSize.split(' ', Typography.nbsp) // Space for languages such as EN and NBSP for languages such as FR +private fun Context.getQuantityFromHumanReadableSize(humanReadableSize: String): Int { + // Space character for languages such as EN and NBSP character for languages such as FR + val sizeParts = humanReadableSize.split(' ', Typography.nbsp) return if (sizeParts.size == 2) { val local = resources.configuration.getLocales().get(0) @@ -176,7 +177,7 @@ private fun SelectedFilesCardPreview() { } ) }, - formattedSizeWithUnits = { "20 GB" }, + humanReadableSize = { "20 GB" }, showUploadSourceChoiceBottomSheet = {}, removeFileByUid = {} )