Skip to content

Commit

Permalink
Merge pull request #153 from Infomaniak/transfer-expired-string
Browse files Browse the repository at this point in the history
refactor: Handle TODO about missing String when transfer is expired
  • Loading branch information
KevinBoulongne authored Nov 8, 2024
2 parents 492973a + 5d76fb7 commit c809b93
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,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)
Expand All @@ -53,23 +53,12 @@ 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 (transfer.isExpired) {
stringResource(R.string.transferExpired) to SwissTransferTheme.materialColors.error
} else {
stringResource(R.string.expiresIn, transfer.expiresInDays) to SwissTransferTheme.colors.secondaryTextColor
}
val border = if (isSelected()) {
BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.colors.transferListStroke)
Expand Down Expand Up @@ -107,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) },
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package com.infomaniak.swisstransfer.ui.utils

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi

val TransferUi.isExpired: Boolean get() = expiresInDays < 0 || downloadLeft <= 0
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<string name="contentDescriptionButtonShowPassword">Passwort anzeigen</string>
<string name="contentDescriptionCreateNewTransferButton">Neuer Transfer</string>
<string name="downloadedTransferLabel">Heruntergeladene Übertragung : %d/%d</string>
<string name="expiredThe">Abgelaufen am %s</string>
<string name="expiresIn">Verfällt in %d Tagen</string>
<plurals name="filesCount">
<item quantity="one">%d Datei</item>
Expand Down Expand Up @@ -93,6 +92,7 @@
<string name="startActivityCantHandleAction">Es wurde keine Anwendung gefunden, die diese Aktion bearbeitet</string>
<string name="textFieldOptional">(Fakultativ)</string>
<string name="transferContentHeader">Inhalt der Übertragung :</string>
<string name="transferExpired">Transfer abgelaufen</string>
<string name="transferExpiredButton">Aus dem Verlauf löschen</string>
<string name="transferExpiredDateReachedDescription">Tut mir leid, diese Übertragung ist am %s abgelaufen. Du kannst die Dateien nicht mehr herunterladen oder ansehen.</string>
<string name="transferExpiredLimitReachedDescription">Entschuldigung, diese Übertragung hat die Grenze der %d möglichen Downloads erreicht.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<string name="contentDescriptionButtonShowPassword">Mostrar contraseña</string>
<string name="contentDescriptionCreateNewTransferButton">Nueva transferencia</string>
<string name="downloadedTransferLabel">Transferencia descargada : %d/%d</string>
<string name="expiredThe">Expirado el %s</string>
<string name="expiresIn">Caduca en %d días</string>
<plurals name="filesCount">
<item quantity="one">%d archivo</item>
Expand Down Expand Up @@ -93,6 +92,7 @@
<string name="startActivityCantHandleAction">No se ha encontrado ninguna aplicación que gestione esta acción</string>
<string name="textFieldOptional">(Opcional)</string>
<string name="transferContentHeader">Contenido de la transferencia :</string>
<string name="transferExpired">Transferencia caducada</string>
<string name="transferExpiredButton">Borrar del historial</string>
<string name="transferExpiredDateReachedDescription">Lo sentimos, esta transferencia expiró el %s. Ya no puede descargar ni ver los archivos.</string>
<string name="transferExpiredLimitReachedDescription">Lo sentimos, esta transferencia ha alcanzado el límite de %d descargas posibles.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<string name="contentDescriptionButtonShowPassword">Afficher le mot de passe</string>
<string name="contentDescriptionCreateNewTransferButton">Nouveau transfert</string>
<string name="downloadedTransferLabel">Transfert téléchargé : %d/%d\u0020</string>
<string name="expiredThe">Expiré le %s</string>
<string name="expiresIn">Expire dans %d jours</string>
<plurals name="filesCount">
<item quantity="one">%d fichier</item>
Expand Down Expand Up @@ -94,6 +93,7 @@
<string name="startActivityCantHandleAction">Aucune application n’a été trouvée pour gérer cette action</string>
<string name="textFieldOptional">(Facultatif)</string>
<string name="transferContentHeader">Contenu du transfert :</string>
<string name="transferExpired">Transfert expiré</string>
<string name="transferExpiredButton">Supprimer de l’historique</string>
<string name="transferExpiredDateReachedDescription">Désolé, ce transfert a expiré le %s. Tu ne peux plus télécharger ni consulter les fichiers.</string>
<string name="transferExpiredLimitReachedDescription">Désolé, ce transfert a atteint la limite de %d téléchargements possibles.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<string name="contentDescriptionButtonShowPassword">Mostra password</string>
<string name="contentDescriptionCreateNewTransferButton">Nuovo trasferimento</string>
<string name="downloadedTransferLabel">Trasferimento scaricato : %d/%d</string>
<string name="expiredThe">Scaduto il %s</string>
<string name="expiresIn">Scade tra %d giorni</string>
<plurals name="filesCount">
<item quantity="one">%d file</item>
Expand Down Expand Up @@ -93,6 +92,7 @@
<string name="startActivityCantHandleAction">Non è stata trovata alcuna applicazione in grado di gestire questa azione</string>
<string name="textFieldOptional">(Opzionale)</string>
<string name="transferContentHeader">Contenuto del trasferimento :</string>
<string name="transferExpired">Trasferimento scaduto</string>
<string name="transferExpiredButton">Cancellare dalla cronologia</string>
<string name="transferExpiredDateReachedDescription">Spiacente, questo trasferimento è scaduto il %s. Non è più possibile scaricare o visualizzare i file.</string>
<string name="transferExpiredLimitReachedDescription">Spiacente, questo trasferimento ha raggiunto il limite di %d download possibili.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
<string name="contentDescriptionButtonShowPassword">Show password</string>
<string name="contentDescriptionCreateNewTransferButton">New transfer</string>
<string name="downloadedTransferLabel">Downloaded transfer: %d/%d\u0020</string>
<string name="expiredThe">Expired on %s</string>
<string name="expiresIn">Expires in %d days</string>
<plurals name="filesCount">
<item quantity="one">%d file</item>
Expand Down Expand Up @@ -98,6 +97,7 @@
<string name="startActivityCantHandleAction">No application has been found to handle this action</string>
<string name="textFieldOptional">(Optional)</string>
<string name="transferContentHeader">Transfer content:</string>
<string name="transferExpired">Transfer expired</string>
<string name="transferExpiredButton">Delete from history</string>
<string name="transferExpiredDateReachedDescription">Sorry, this transfer expired on %s. You can no longer download or view the files.</string>
<string name="transferExpiredLimitReachedDescription">Sorry, this transfer has reached the limit of %d possible downloads.</string>
Expand Down

0 comments on commit c809b93

Please sign in to comment.