From 1f02343b588fd1eabf9a08743989ab3c2be65679 Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Thu, 7 Nov 2024 09:37:03 +0100 Subject: [PATCH 1/2] refactor: Handle TODO about missing String when transfer is expired --- .../ui/components/transfer/TransferItem.kt | 17 ++++------------- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt index 299f4462b..e3c0352c2 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt @@ -27,7 +27,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.PreviewParameter -import com.infomaniak.core2.FORMAT_DATE_SIMPLE import com.infomaniak.core2.FORMAT_DATE_TITLE import com.infomaniak.core2.format import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi @@ -53,23 +52,15 @@ fun TransferItem( ) { val createdDate = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE) - val expirationDate = Date(transfer.expirationDateTimestamp) val remainingDays = transfer.expiresInDays val remainingDownloads = transfer.downloadLeft val uploadedSize = HumanReadableSizeUtils.getHumanReadableSize(LocalContext.current, transfer.sizeUploaded) val files = transfer.files val filesCount = files.count() - val (expiryText, expiryColor) = when { - remainingDays < 0 -> { - stringResource(R.string.expiredThe, expirationDate.format(FORMAT_DATE_SIMPLE)) to - SwissTransferTheme.materialColors.error - } - remainingDownloads == 0 -> { - "Transfert expiré (TODO)" to SwissTransferTheme.materialColors.error - } - else -> { - stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor - } + val (expiryText, expiryColor) = if (remainingDays < 0 || remainingDownloads == 0) { + stringResource(R.string.transferExpired) to SwissTransferTheme.materialColors.error + } else { + stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor } val border = if (isSelected()) { BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.colors.transferListStroke) diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9fdec06ed..73b607938 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -31,7 +31,6 @@ Passwort anzeigen Neuer Transfer Heruntergeladene Übertragung : %d/%d - Abgelaufen am %s Verfällt in %d Tagen %d Datei @@ -93,6 +92,7 @@ Es wurde keine Anwendung gefunden, die diese Aktion bearbeitet (Fakultativ) Inhalt der Übertragung : + Transfer abgelaufen Aus dem Verlauf löschen Tut mir leid, diese Übertragung ist am %s abgelaufen. Du kannst die Dateien nicht mehr herunterladen oder ansehen. Entschuldigung, diese Übertragung hat die Grenze der %d möglichen Downloads erreicht. diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 66fdffeef..43122de78 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -31,7 +31,6 @@ Mostrar contraseña Nueva transferencia Transferencia descargada : %d/%d - Expirado el %s Caduca en %d días %d archivo @@ -93,6 +92,7 @@ No se ha encontrado ninguna aplicación que gestione esta acción (Opcional) Contenido de la transferencia : + Transferencia caducada Borrar del historial Lo sentimos, esta transferencia expiró el %s. Ya no puede descargar ni ver los archivos. Lo sentimos, esta transferencia ha alcanzado el límite de %d descargas posibles. diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 9cf536f16..dd8b723c5 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -31,7 +31,6 @@ Afficher le mot de passe Nouveau transfert Transfert téléchargé : %d/%d\u0020 - Expiré le %s Expire dans %d jours %d fichier @@ -94,6 +93,7 @@ Aucune application n’a été trouvée pour gérer cette action (Facultatif) Contenu du transfert : + Transfert expiré Supprimer de l’historique Désolé, ce transfert a expiré le %s. Tu ne peux plus télécharger ni consulter les fichiers. Désolé, ce transfert a atteint la limite de %d téléchargements possibles. diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 2dd76ed9f..4d2927a82 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -31,7 +31,6 @@ Mostra password Nuovo trasferimento Trasferimento scaricato : %d/%d - Scaduto il %s Scade tra %d giorni %d file @@ -93,6 +92,7 @@ Non è stata trovata alcuna applicazione in grado di gestire questa azione (Opzionale) Contenuto del trasferimento : + Trasferimento scaduto Cancellare dalla cronologia Spiacente, questo trasferimento è scaduto il %s. Non è più possibile scaricare o visualizzare i file. Spiacente, questo trasferimento ha raggiunto il limite di %d download possibili. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aac9772f1..e240f0d4e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -36,7 +36,6 @@ Show password New transfer Downloaded transfer: %d/%d\u0020 - Expired on %s Expires in %d days %d file @@ -98,6 +97,7 @@ No application has been found to handle this action (Optional) Transfer content: + Transfer expired Delete from history Sorry, this transfer expired on %s. You can no longer download or view the files. Sorry, this transfer has reached the limit of %d possible downloads. From 5d76fb7cf2aa15ed8cfceadb45a6312a2efc71fc Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Thu, 7 Nov 2024 09:43:22 +0100 Subject: [PATCH 2/2] refactor: Move expiry check to `TransferUiExt` --- .../ui/components/transfer/TransferItem.kt | 10 ++++----- .../utils/{FileUiItemExt.kt => FileUiExt.kt} | 0 .../swisstransfer/ui/utils/TransferUiExt.kt | 22 +++++++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) rename app/src/main/java/com/infomaniak/swisstransfer/ui/utils/{FileUiItemExt.kt => FileUiExt.kt} (100%) create mode 100644 app/src/main/java/com/infomaniak/swisstransfer/ui/utils/TransferUiExt.kt diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt index e3c0352c2..0027192a4 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/components/transfer/TransferItem.kt @@ -41,6 +41,7 @@ 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 +import com.infomaniak.swisstransfer.ui.utils.isExpired import java.util.Date @OptIn(ExperimentalLayoutApi::class) @@ -52,15 +53,12 @@ fun TransferItem( ) { val createdDate = Date(transfer.createdDateTimestamp).format(FORMAT_DATE_TITLE) - val remainingDays = transfer.expiresInDays - val remainingDownloads = transfer.downloadLeft val uploadedSize = HumanReadableSizeUtils.getHumanReadableSize(LocalContext.current, transfer.sizeUploaded) val files = transfer.files - val filesCount = files.count() - val (expiryText, expiryColor) = if (remainingDays < 0 || remainingDownloads == 0) { + val (expiryText, expiryColor) = if (transfer.isExpired) { stringResource(R.string.transferExpired) to SwissTransferTheme.materialColors.error } else { - stringResource(R.string.expiresIn, remainingDays) to SwissTransferTheme.colors.secondaryTextColor + stringResource(R.string.expiresIn, transfer.expiresInDays) to SwissTransferTheme.colors.secondaryTextColor } val border = if (isSelected()) { BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.colors.transferListStroke) @@ -98,7 +96,7 @@ fun TransferItem( Spacer(modifier = Modifier.height(Margin.Mini)) ContextualFlowRow( - itemCount = filesCount, + itemCount = files.count(), maxLines = 1, horizontalArrangement = Arrangement.spacedBy(Margin.Mini), overflow = ContextualFlowRowOverflow.expandIndicator { TransferFilePreview(remainingFilesCount = totalItemCount - shownItemCount) }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiItemExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt similarity index 100% rename from app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiItemExt.kt rename to app/src/main/java/com/infomaniak/swisstransfer/ui/utils/FileUiExt.kt diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/TransferUiExt.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/TransferUiExt.kt new file mode 100644 index 000000000..5ef5d1457 --- /dev/null +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/utils/TransferUiExt.kt @@ -0,0 +1,22 @@ +/* + * Infomaniak SwissTransfer - Android + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.swisstransfer.ui.utils + +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi + +val TransferUi.isExpired: Boolean get() = expiresInDays < 0 || downloadLeft <= 0