Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connect first advanced settings to upload api call #172

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -45,14 +45,16 @@ fun SettingsValidityPeriodScreen(
}

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(apiValue = ValidityPeriod.THIRTY),
FIFTEEN(apiValue = ValidityPeriod.FIFTEEN),
SEVEN(apiValue = ValidityPeriod.SEVEN),
ONE(apiValue = ValidityPeriod.ONE);

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

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 @@ -136,12 +135,13 @@ class ImportFilesViewModel @Inject constructor(

private fun generateNewUploadSession(): NewUploadSession {
return NewUploadSession(
duration = "30",
duration = selectedValidityPeriodOption.value.apiValue.value,
authorEmail = "",
password = "",
password = if (selectedPasswordOption.value == PasswordTransferOption.ACTIVATED) transferPassword else NO_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 Expand Up @@ -260,5 +260,7 @@ class ImportFilesViewModel @Inject constructor(
private const val SELECTED_DOWNLOAD_LIMIT_KEY = "SELECTED_DOWNLOAD_LIMIT_KEY"
private const val SELECTED_PASSWORD_OPTION_KEY = "SELECTED_PASSWORD_OPTION_KEY"
private const val SELECTED_LANGUAGE_KEY = "SELECTED_TRANSFER_LANGUAGE_KEY"

private const val NO_PASSWORD = ""
}
}
Loading