Skip to content

Commit

Permalink
feat: Use FormatterFileSize
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Dec 19, 2024
1 parent 50cadfd commit 7df2021
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ object FormatterFileSize {
isGroupingUsed = false
// We do this only for DecimalFormat, since in the general NumberFormat case,
// calling setRoundingMode may throw an exception.
@Suppress("DEPRECATION")
if (this is DecimalFormat) setRoundingMode(BigDecimal.ROUND_HALF_UP)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components

import android.text.format.Formatter
import androidx.compose.foundation.layout.*
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
Expand Down Expand Up @@ -45,6 +44,7 @@ import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewPar
import com.infomaniak.swisstransfer.ui.theme.Dimens
import com.infomaniak.swisstransfer.ui.theme.Margin
import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme
import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark

@Composable
Expand All @@ -65,7 +65,7 @@ fun TransferInfo(getTransfer: () -> TransferUi) {
Spacer(Modifier.width(Margin.Mini))
TextDotText(
firstText = { pluralStringResource(R.plurals.filesCount, filesCount, filesCount) },
secondText = { Formatter.formatShortFileSize(LocalContext.current, sizeUploaded) },
secondText = { HumanReadableSizeUtils.getHumanReadableSize(LocalContext.current, sizeUploaded) },
color = SwissTransferTheme.colors.primaryTextColor,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ImportFilesViewModel @Inject constructor(
message = _transferMessage,
numberOfDownload = selectedDownloadLimitOption.value.apiValue,
language = selectedLanguageOption.value.apiValue,
recipientsEmails = emptyList(),
recipientsEmails = emptySet(),
files = importationFilesManager.importedFiles.value.mapToList { fileUi ->
object : UploadFileSession {
override val path: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi
import com.infomaniak.multiplatform_swisstransfer.utils.FileUtils
import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.SmallFileItem
import com.infomaniak.swisstransfer.ui.components.SmallFileTileSize
Expand All @@ -52,8 +53,6 @@ import com.infomaniak.swisstransfer.ui.utils.HumanReadableSizeUtils.getHumanRead
import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark
import kotlinx.parcelize.Parcelize

private const val TOTAL_FILE_SIZE: Long = 50_000_000_000L

@Composable
fun ImportedFilesCard(
modifier: Modifier = Modifier,
Expand All @@ -67,7 +66,7 @@ fun ImportedFilesCard(
val humanReadableSize by remember {
derivedStateOf {
val usedSpace = files().sumOf { it.fileSize }
val spaceLeft = (TOTAL_FILE_SIZE - usedSpace).coerceAtLeast(0)
val spaceLeft = (FileUtils.MAX_FILES_SIZE - usedSpace).coerceAtLeast(0)
getHumanReadableSize(context, spaceLeft)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,15 @@ package com.infomaniak.swisstransfer.ui.utils

import android.content.Context
import android.icu.text.NumberFormat
import android.text.format.Formatter
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import com.infomaniak.core2.FormatterFileSize.formatShortFileSize
import com.infomaniak.swisstransfer.R

object HumanReadableSizeUtils {

fun getHumanReadableSize(context: Context, sizeInBytes: Long): String {
return Formatter.formatShortFileSize(context, sizeInBytes)
}
fun getHumanReadableSize(context: Context, sizeInBytes: Long): String = context.formatShortFileSize(sizeInBytes)

@Composable
fun formatSpaceLeft(humanReadableSize: () -> String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class FileChunkSizeManager(
class AllowedFileSizeExceededException : Exception()

companion object {
private const val CHUNK_MIN_SIZE = 1L * 1024 * 1024 // 1Mo
private const val CHUNK_MAX_SIZE = 50L * 1024 * 1024 // 50Mo
private const val CHUNK_MIN_SIZE = 1L * 1_024 * 1_024 // 1 MB
private const val CHUNK_MAX_SIZE = 50L * 1_024 * 1_024 // 50 MB
private const val OPTIMAL_TOTAL_CHUNKS = 200
private const val MAX_CHUNK_COUNT = 10_000
private const val MAX_PARALLEL_CHUNKS = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.work.*
import androidx.work.WorkInfo.State
import com.infomaniak.multiplatform_swisstransfer.SharedApiUrlCreator
import com.infomaniak.multiplatform_swisstransfer.managers.UploadManager
import com.infomaniak.multiplatform_swisstransfer.utils.FileUtils
import com.infomaniak.sentry.SentryLog
import com.infomaniak.swisstransfer.ui.screen.newtransfer.ImportLocalStorage
import dagger.assisted.Assisted
Expand Down Expand Up @@ -163,9 +164,8 @@ class UploadWorker @AssistedInject constructor(

companion object {
private const val TAG = "UploadWorker"
private const val EXPECTED_CHUNK_SIZE = 50L * 1024 * 1024 // 50Mo
private const val TOTAL_FILE_SIZE = 50L * 1024 * 1024 * 1024 // 50Go
private const val MAX_CHUNK_COUNT = (TOTAL_FILE_SIZE / EXPECTED_CHUNK_SIZE).toInt()
private const val EXPECTED_CHUNK_SIZE = 50L * 1_024 * 1_024 // 50 MB
private const val MAX_CHUNK_COUNT = (FileUtils.MAX_FILES_SIZE / EXPECTED_CHUNK_SIZE).toInt()

private const val UPLOADED_BYTES_TAG = "uploaded_bytes_tag"
private const val TRANSFER_UUID_TAG = "transfer_uuid_tag"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ qrose = "1.0.1"
recaptcha = "18.6.1"
sentry = "4.12.0"
serialization = "1.7.3"
swisstransfer = "0.10.0"
swisstransfer = "0.10.1"
workmanager = "2.10.0"

[libraries]
Expand Down

0 comments on commit 7df2021

Please sign in to comment.