From 44be74d1c1d94275015cad3d0a759b16362b1af4 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Tue, 22 Oct 2024 10:16:42 +0200 Subject: [PATCH] refactor(TransferSettings): Use multiplatform enum values instead of hardcoded ones --- .../main/settings/SettingsDownloadsLimitScreen.kt | 8 ++++---- .../main/settings/SettingsValidityPeriodScreen.kt | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt index 68c42b695..836e1be83 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsDownloadsLimitScreen.kt @@ -48,10 +48,10 @@ enum class DownloadLimitOption( override val imageVector: ImageVector? = null, override val imageVectorResId: Int? = null, ) : SettingOption { - TWO_HUNDRED_FIFTY({ "250" }), - ONE_HUNDRED({ "100" }), - TWENTY({ "20" }), - ONE({ "1" }), + TWO_HUNDRED_FIFTY({ DownloadLimit.TWO_HUNDRED_FIFTY.value }), + ONE_HUNDRED({ DownloadLimit.ONE_HUNDRED.value }), + TWENTY({ DownloadLimit.TWENTY.value }), + ONE({ DownloadLimit.ONE.value }), } @PreviewAllWindows diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt index 07880b583..c79b1c8af 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/main/settings/SettingsValidityPeriodScreen.kt @@ -49,10 +49,16 @@ enum class ValidityPeriodOption( override val imageVector: ImageVector? = null, override val imageVectorResId: Int? = null, ) : SettingOption { - THIRTY({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 30, 30) }), - FIFTEEN({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 15, 15) }), - SEVEN({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 7, 7) }), - ONE({ pluralStringResource(R.plurals.settingsValidityPeriodValue, 1, 1) }), + THIRTY({ getValidityPeriodTitle(ValidityPeriod.THIRTY) }), + FIFTEEN({ getValidityPeriodTitle(ValidityPeriod.FIFTEEN) }), + SEVEN({ getValidityPeriodTitle(ValidityPeriod.SEVEN) }), + ONE({ getValidityPeriodTitle(ValidityPeriod.ONE) }); +} + +@Composable +private fun getValidityPeriodTitle(validityPeriod: ValidityPeriod): String { + val count = validityPeriod.value.toInt() + return pluralStringResource(R.plurals.settingsValidityPeriodValue, count, count) } @PreviewAllWindows