Skip to content

Commit

Permalink
feat: Correctly display today/tomorrow for almost expired Transfers (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne authored Jan 2, 2025
2 parents 9b1255c + 8096132 commit be6f357
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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.getFormattedExpiry
import com.infomaniak.swisstransfer.ui.utils.isExpired

@OptIn(ExperimentalLayoutApi::class)
Expand All @@ -60,7 +61,7 @@ fun TransferItem(
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
transfer.getFormattedExpiry() to SwissTransferTheme.colors.secondaryTextColor
}
val border = if (isSelected()) {
BorderStroke(width = Dimens.BorderWidth, color = SwissTransferTheme.colors.transferListStroke)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ 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.getFormattedExpiry

@Composable
fun TransferInfo(getTransfer: () -> TransferUi) {

val filesCount by remember { derivedStateOf { getTransfer().files.count() } }
val downloadedCount by remember { derivedStateOf { getTransfer().downloadLimit - getTransfer().downloadLeft } }
val expiresInDays by remember { derivedStateOf { getTransfer().expiresInDays } }
val downloadLimit by remember { derivedStateOf { getTransfer().downloadLimit } }
val sizeUploaded by remember { derivedStateOf { getTransfer().sizeUploaded } }

Expand All @@ -74,7 +74,7 @@ fun TransferInfo(getTransfer: () -> TransferUi) {

IconText(
icon = AppIcons.Clock,
text = stringResource(R.string.expiresIn, expiresInDays),
text = getTransfer().getFormattedExpiry(),
)

HorizontalDivider(modifier = Modifier.padding(vertical = Margin.Medium))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
*/
package com.infomaniak.swisstransfer.ui.utils

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.swisstransfer.R

val TransferUi.isExpired: Boolean get() = expiresInDays < 0 || downloadLeft <= 0

@Composable
fun TransferUi.getFormattedExpiry(): String = when (expiresInDays) {
0 -> stringResource(R.string.expiresToday)
1 -> stringResource(R.string.expiresTomorrow)
else -> stringResource(R.string.expiresIn, expiresInDays)
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<string name="errorTransferPasswordLength">Das Passwort muss zwischen 6 und 25 Zeichen lang sein</string>
<string name="errorUnknown">Ein Fehler ist aufgetreten</string>
<string name="expiresIn">Verfällt in %d Tagen</string>
<string name="expiresToday">Läuft heute ab</string>
<string name="expiresTomorrow">Läuft morgen ab</string>
<plurals name="filesCount">
<item quantity="one">%d Datei</item>
<item quantity="other">%d Dateien</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<string name="errorTransferPasswordLength">La contraseña debe tener entre 6 y 25 caracteres</string>
<string name="errorUnknown">Se ha producido un error</string>
<string name="expiresIn">Caduca en %d días</string>
<string name="expiresToday">Caduca hoy</string>
<string name="expiresTomorrow">Expira mañana</string>
<plurals name="filesCount">
<item quantity="one">%d archivo</item>
<item quantity="other">%d archivos</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<string name="errorTransferPasswordLength">Le mot de passe doit comporter entre 6 et 25 caractères</string>
<string name="errorUnknown">Une erreur est survenue</string>
<string name="expiresIn">Expire dans %d jours</string>
<string name="expiresToday">Expire aujourd’hui</string>
<string name="expiresTomorrow">Expire demain</string>
<plurals name="filesCount">
<item quantity="one">%d fichier</item>
<item quantity="other">%d fichiers</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<string name="errorTransferPasswordLength">La password deve essere compresa tra 6 e 24 caratteri</string>
<string name="errorUnknown">Si è verificato un errore</string>
<string name="expiresIn">Scade tra %d giorni</string>
<string name="expiresToday">Scade oggi</string>
<string name="expiresTomorrow">Scade domani</string>
<plurals name="filesCount">
<item quantity="one">%d file</item>
<item quantity="other">%d file</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<string name="errorTransferPasswordLength">The password must be between 6 and 25 characters</string>
<string name="errorUnknown">An error has occurred</string>
<string name="expiresIn">Expires in %d days</string>
<string name="expiresToday">Expires today</string>
<string name="expiresTomorrow">Expires tomorrow</string>
<plurals name="filesCount">
<item quantity="one">%d file</item>
<item quantity="other">%d files</item>
Expand Down

0 comments on commit be6f357

Please sign in to comment.