Skip to content

Commit

Permalink
Add apiValue to advanced settings enum and use the for the api call
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Nov 12, 2024
1 parent 531b2aa commit d1f396e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ fun SettingsDownloadsLimitScreen(
}

enum class DownloadLimitOption(
override val title: @Composable () -> String,
override val imageVector: ImageVector? = null,
override val imageVectorResId: Int? = null,
val apiValue: DownloadLimit,
) : SettingOption {
TWO_HUNDRED_FIFTY({ DownloadLimit.TWO_HUNDRED_FIFTY.value }),
ONE_HUNDRED({ DownloadLimit.ONE_HUNDRED.value }),
TWENTY({ DownloadLimit.TWENTY.value }),
ONE({ DownloadLimit.ONE.value });
TWO_HUNDRED_FIFTY(apiValue = DownloadLimit.TWO_HUNDRED_FIFTY),
ONE_HUNDRED(apiValue = DownloadLimit.ONE_HUNDRED),
TWENTY(apiValue = DownloadLimit.TWENTY),
ONE(apiValue = DownloadLimit.ONE);

override val title: @Composable () -> String = { apiValue.value }

companion object {
fun DownloadLimit.toTransferOption() = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,33 @@ enum class EmailLanguageOption(
override val title: @Composable () -> String,
override val imageVector: ImageVector? = null,
override val imageVectorResId: Int? = null,
val apiValue: EmailLanguage,
) : SettingOption {
ENGLISH({ stringResource(R.string.settingsEmailLanguageValueEnglish) }, imageVectorResId = R.drawable.flag_gb),
FRENCH({ stringResource(R.string.settingsEmailLanguageValueFrench) }, imageVectorResId = R.drawable.flag_fr),
GERMAN({ stringResource(R.string.settingsEmailLanguageValueGerman) }, imageVectorResId = R.drawable.flag_ge),
ITALIAN({ stringResource(R.string.settingsEmailLanguageValueItalian) }, imageVectorResId = R.drawable.flag_it),
SPANISH({ stringResource(R.string.settingsEmailLanguageValueSpanish) }, imageVectorResId = R.drawable.flag_es);
ENGLISH(
{ stringResource(R.string.settingsEmailLanguageValueEnglish) },
imageVectorResId = R.drawable.flag_gb,
apiValue = EmailLanguage.ENGLISH,
),
FRENCH(
{ stringResource(R.string.settingsEmailLanguageValueFrench) },
imageVectorResId = R.drawable.flag_fr,
apiValue = EmailLanguage.FRENCH,
),
GERMAN(
{ stringResource(R.string.settingsEmailLanguageValueGerman) },
imageVectorResId = R.drawable.flag_ge,
apiValue = EmailLanguage.GERMAN,
),
ITALIAN(
{ stringResource(R.string.settingsEmailLanguageValueItalian) },
imageVectorResId = R.drawable.flag_it,
apiValue = EmailLanguage.ITALIAN,
),
SPANISH(
{ stringResource(R.string.settingsEmailLanguageValueSpanish) },
imageVectorResId = R.drawable.flag_es,
apiValue = EmailLanguage.SPANISH,
);

companion object {
fun EmailLanguage.toTransferOption() = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ enum class ValidityPeriodOption(
override val title: @Composable () -> String,
override val imageVector: ImageVector? = null,
override val imageVectorResId: Int? = null,
val apiValue: ValidityPeriod,
) : SettingOption {
THIRTY({ getValidityPeriodTitle(ValidityPeriod.THIRTY) }),
FIFTEEN({ getValidityPeriodTitle(ValidityPeriod.FIFTEEN) }),
SEVEN({ getValidityPeriodTitle(ValidityPeriod.SEVEN) }),
ONE({ getValidityPeriodTitle(ValidityPeriod.ONE) });
THIRTY({ getValidityPeriodTitle(ValidityPeriod.THIRTY) }, apiValue = ValidityPeriod.THIRTY),
FIFTEEN({ getValidityPeriodTitle(ValidityPeriod.FIFTEEN) }, apiValue = ValidityPeriod.FIFTEEN),
SEVEN({ getValidityPeriodTitle(ValidityPeriod.SEVEN) }, apiValue = ValidityPeriod.SEVEN),
ONE({ getValidityPeriodTitle(ValidityPeriod.ONE) }, apiValue = ValidityPeriod.ONE);

companion object {
fun ValidityPeriod.toTransferOption() = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.RemoteUploadFile
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession
import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList
import com.infomaniak.multiplatform_swisstransfer.data.NewUploadSession
import com.infomaniak.multiplatform_swisstransfer.managers.AppSettingsManager
Expand Down Expand Up @@ -131,12 +130,13 @@ class ImportFilesViewModel @Inject constructor(

private fun generateNewUploadSession(): NewUploadSession {
return NewUploadSession(
duration = "30",
duration = selectedValidityPeriodOption.value.apiValue.value,
authorEmail = "",
password = "",
message = "sisi test",
numberOfDownload = 20,
language = EmailLanguage.ENGLISH,
// TODO: Accept enum in kmp instead of parsing toInt()
numberOfDownload = selectedDownloadLimitOption.value.apiValue.value.toInt(),
language = selectedLanguageOption.value.apiValue,
recipientsEmails = emptyList(),
files = importationFilesManager.importedFiles.value.mapToList { fileUi ->
object : UploadFileSession {
Expand Down

0 comments on commit d1f396e

Please sign in to comment.