From cb2975e37618a4cb64b8bf1de3c5c7d59f5b8b15 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Wed, 13 Nov 2024 16:03:41 +0100 Subject: [PATCH] feat(TransferType): Keep transfer type in the DB when at user's choice --- .../ui/navigation/NavigationDestination.kt | 6 +-- .../newtransfer/ImportFilesViewModel.kt | 9 +++-- .../importfiles/ImportFilesScreen.kt | 16 ++++---- .../components/TransferTypeButton.kt | 4 +- .../components/TransferTypeButtons.kt | 37 +++++++++++++------ .../upload/UploadSuccessEmailScreen.kt | 6 +-- .../upload/UploadSuccessQrScreen.kt | 8 ++-- .../newtransfer/upload/UploadSuccessScreen.kt | 8 ++-- 8 files changed, 56 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt index 4d6ff6e40..61903c115 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/navigation/NavigationDestination.kt @@ -19,7 +19,7 @@ package com.infomaniak.swisstransfer.ui.navigation import android.os.Bundle import androidx.navigation.NavBackStackEntry -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi import kotlinx.serialization.Serializable import kotlin.reflect.KClass import kotlin.reflect.full.primaryConstructor @@ -60,9 +60,9 @@ sealed class NewTransferNavigation : NavigationDestination() { data object ValidateUserEmailDestination : NewTransferNavigation() @Serializable - data class UploadProgressDestination(val transferType: TransferType, val totalSize: Long) : NewTransferNavigation() + data class UploadProgressDestination(val transferType: TransferTypeUi, val totalSize: Long) : NewTransferNavigation() @Serializable - data class UploadSuccessDestination(val transferType: TransferType, val transferUrl: String) : NewTransferNavigation() + data class UploadSuccessDestination(val transferType: TransferTypeUi, val transferUrl: String) : NewTransferNavigation() @Serializable data object UploadErrorDestination : NewTransferNavigation() diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt index aa9ff04a3..31dd5f00c 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/ImportFilesViewModel.kt @@ -43,7 +43,8 @@ import com.infomaniak.swisstransfer.ui.screen.main.settings.components.SettingOp import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.PasswordTransferOption import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.TransferOptionState import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.TransferOptionsCallbacks -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi.Companion.toTransferTypeUi import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks import com.infomaniak.swisstransfer.workers.UploadWorker import dagger.hilt.android.lifecycle.HiltViewModel @@ -155,10 +156,11 @@ class ImportFilesViewModel @Inject constructor( } //region Transfer Type - val selectedTransferType = savedStateHandle.getStateFlow(SELECTED_TRANSFER_TYPE, TransferType.LINK) + val selectedTransferType = savedStateHandle.getStateFlow(SELECTED_TRANSFER_TYPE, TransferTypeUi.QR_CODE) - fun selectTransferType(type: TransferType) { + fun selectTransferType(type: TransferTypeUi) { savedStateHandle[SELECTED_TRANSFER_TYPE] = type + viewModelScope.launch(ioDispatcher) { appSettingsManager.setLastTransferType(type.dbValue) } } //endregion @@ -205,6 +207,7 @@ class ImportFilesViewModel @Inject constructor( selectTransferValidityPeriod(it.validityPeriod.toTransferOption()) selectTransferDownloadLimit(it.downloadLimit.toTransferOption()) selectTransferLanguage(it.emailLanguage.toTransferOption()) + selectTransferType(it.lastTransferType.toTransferTypeUi()) } ?: run { SentryLog.e(TAG, "AppSettings is null in ImportFilesScreen, it should not happened") selectTransferValidityPeriod(ValidityPeriodOption.THIRTY) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt index c8133bbc3..ed0b95a5a 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/ImportFilesScreen.kt @@ -58,7 +58,7 @@ private const val TOTAL_FILE_SIZE: Long = 50_000_000_000L fun ImportFilesScreen( importFilesViewModel: ImportFilesViewModel = hiltViewModel(), closeActivity: () -> Unit, - navigateToUploadProgress: (transferType: TransferType, totalSize: Long) -> Unit, + navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit, ) { val files by importFilesViewModel.importedFilesDebounced.collectAsStateWithLifecycle() val filesToImportCount by importFilesViewModel.filesToImportCount.collectAsStateWithLifecycle() @@ -120,8 +120,8 @@ fun ImportFilesScreen( @Composable private fun HandleSendActionResult( getSendActionResult: () -> SendActionResult?, - transferType: () -> TransferType, - navigateToUploadProgress: (transferType: TransferType, totalSize: Long) -> Unit, + transferType: () -> TransferTypeUi, + navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit, ) { LaunchedEffect(getSendActionResult()) { when (val actionResult = getSendActionResult()) { @@ -137,7 +137,7 @@ private fun ImportFilesScreen( files: () -> List, filesToImportCount: () -> Int, currentSessionFilesCount: () -> Int, - selectedTransferType: GetSetCallbacks, + selectedTransferType: GetSetCallbacks, transferOptionsCallbacks: TransferOptionsCallbacks, removeFileByUid: (uid: String) -> Unit, addFiles: (List) -> Unit, @@ -213,7 +213,7 @@ private fun ImportFilesScreen( } @Composable -private fun ColumnScope.ImportTextFields(selectedTransferType: () -> TransferType) { +private fun ColumnScope.ImportTextFields(selectedTransferType: () -> TransferTypeUi) { EmailAddressesTextFields(selectedTransferType) @@ -226,9 +226,9 @@ private fun ColumnScope.ImportTextFields(selectedTransferType: () -> TransferTyp } @Composable -private fun ColumnScope.EmailAddressesTextFields(selectedTransferType: () -> TransferType) { +private fun ColumnScope.EmailAddressesTextFields(selectedTransferType: () -> TransferTypeUi) { - val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType() == TransferType.MAIL } } + val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType() == TransferTypeUi.MAIL } } AnimatedVisibility(visible = shouldShowEmailAddressesFields) { Column { @@ -375,7 +375,7 @@ private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files: files = { files }, filesToImportCount = { 0 }, currentSessionFilesCount = { 0 }, - selectedTransferType = GetSetCallbacks(get = { TransferType.QR_CODE }, set = {}), + selectedTransferType = GetSetCallbacks(get = { TransferTypeUi.QR_CODE }, set = {}), transferOptionsCallbacks = transferOptionsCallbacks, removeFileByUid = {}, addFiles = {}, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButton.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButton.kt index 8f80f0559..a99933d5d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButton.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButton.kt @@ -32,7 +32,7 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark @Composable fun TransferTypeButton( - transferType: TransferType, + transferType: TransferTypeUi, isActive: () -> Boolean, onClick: () -> Unit, ) { @@ -63,7 +63,7 @@ private fun TransferTypeButtonPreview() { SwissTransferTheme { Surface { Column { - TransferType.entries.forEach { entry -> + TransferTypeUi.entries.forEach { entry -> TransferTypeButton( transferType = entry, isActive = { entry.ordinal == 0 }, diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButtons.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButtons.kt index bfb04fe9c..0a1c27e3d 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButtons.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/importfiles/components/TransferTypeButtons.kt @@ -27,6 +27,7 @@ import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.ImageVector +import com.infomaniak.multiplatform_swisstransfer.common.models.TransferType import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.images.AppImages.AppIcons import com.infomaniak.swisstransfer.ui.images.icons.Chain @@ -39,12 +40,12 @@ import com.infomaniak.swisstransfer.ui.utils.GetSetCallbacks import com.infomaniak.swisstransfer.ui.utils.PreviewLightAndDark @Composable -fun TransferTypeButtons(transferType: GetSetCallbacks) { +fun TransferTypeButtons(transferType: GetSetCallbacks) { Row( modifier = Modifier.horizontalScroll(rememberScrollState()), horizontalArrangement = Arrangement.spacedBy(Margin.Mini), ) { - for (transferTypeEntry in TransferType.entries) { + for (transferTypeEntry in TransferTypeUi.entries) { TransferTypeButton( transferType = transferTypeEntry, isActive = { transferTypeEntry == transferType.get() }, @@ -54,36 +55,50 @@ fun TransferTypeButtons(transferType: GetSetCallbacks) { } } -enum class TransferType( +enum class TransferTypeUi( val buttonIcon: ImageVector, @StringRes val buttonTextRes: Int, @StringRes val titleRes: Int, @StringRes @PluralsRes val descriptionRes: Int?, + val dbValue: TransferType, ) { - LINK( - buttonIcon = AppIcons.Chain, - buttonTextRes = R.string.transferTypeLink, - titleRes = R.string.uploadSuccessLinkTitle, - descriptionRes = R.string.uploadSuccessLinkDescription, - ), QR_CODE( buttonIcon = AppIcons.QrCode, buttonTextRes = R.string.transferTypeQrCode, titleRes = R.string.uploadSuccessQrTitle, descriptionRes = null, + dbValue = TransferType.QR_CODE, + ), + LINK( + buttonIcon = AppIcons.Chain, + buttonTextRes = R.string.transferTypeLink, + titleRes = R.string.uploadSuccessLinkTitle, + descriptionRes = R.string.uploadSuccessLinkDescription, + dbValue = TransferType.LINK, ), PROXIMITY( buttonIcon = AppIcons.WifiWave, buttonTextRes = R.string.transferTypeProximity, titleRes = R.string.uploadSuccessLinkTitle, descriptionRes = R.string.uploadSuccessLinkDescription, + dbValue = TransferType.PROXIMITY, ), MAIL( buttonIcon = AppIcons.Envelope, buttonTextRes = R.string.transferTypeEmail, titleRes = R.string.uploadSuccessEmailTitle, descriptionRes = R.plurals.uploadSuccessEmailDescription, - ), + dbValue = TransferType.MAIL, + ); + + companion object { + fun TransferType.toTransferTypeUi() = when(this) { + TransferType.LINK -> LINK + TransferType.QR_CODE -> QR_CODE + TransferType.PROXIMITY -> PROXIMITY + TransferType.MAIL -> MAIL + } + } } @PreviewLightAndDark @@ -91,7 +106,7 @@ enum class TransferType( private fun TransferTypeButtonsPreview() { SwissTransferTheme { Surface { - TransferTypeButtons(GetSetCallbacks(get = { TransferType.QR_CODE }, set = {})) + TransferTypeButtons(GetSetCallbacks(get = { TransferTypeUi.QR_CODE }, set = {})) } } } diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt index 0e442f7b9..2b0050e23 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessEmailScreen.kt @@ -31,7 +31,7 @@ import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus import com.infomaniak.swisstransfer.ui.images.illus.beers.Beers import com.infomaniak.swisstransfer.ui.previewparameter.emailsPreviewData -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi import com.infomaniak.swisstransfer.ui.theme.Margin import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @@ -62,8 +62,8 @@ fun UploadSuccessEmailScreen( IllustratedMessageBlock( icon = AppIllus.Beers.image(), - title = TransferType.MAIL.titleRes, - description = pluralStringResource(TransferType.MAIL.descriptionRes!!, emails.count()), + title = TransferTypeUi.MAIL.titleRes, + description = pluralStringResource(TransferTypeUi.MAIL.descriptionRes!!, emails.count()), ) Spacer(modifier = Modifier.height(Margin.Medium)) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessQrScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessQrScreen.kt index 7b289a82e..927295f82 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessQrScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessQrScreen.kt @@ -34,7 +34,7 @@ import com.infomaniak.swisstransfer.R import com.infomaniak.swisstransfer.ui.components.* import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus import com.infomaniak.swisstransfer.ui.images.illus.beers.Beers -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.components.ShareAndCopyButtons import com.infomaniak.swisstransfer.ui.theme.Dimens import com.infomaniak.swisstransfer.ui.theme.Margin @@ -42,7 +42,7 @@ import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable -fun UploadSuccessQrScreen(transferType: TransferType, transferUrl: String, closeActivity: () -> Unit) { +fun UploadSuccessQrScreen(transferType: TransferTypeUi, transferUrl: String, closeActivity: () -> Unit) { val snackbarHostState = remember { SnackbarHostState() } BottomStickyButtonScaffold( @@ -70,7 +70,7 @@ fun UploadSuccessQrScreen(transferType: TransferType, transferUrl: String, close } @Composable -private fun ColumnScope.SuccessMessage(transferType: TransferType, transferUrl: String) { +private fun ColumnScope.SuccessMessage(transferType: TransferTypeUi, transferUrl: String) { Column( modifier = Modifier .fillMaxWidth() @@ -115,7 +115,7 @@ private fun UploadSuccessQrScreenPreview() { SwissTransferTheme { Surface { UploadSuccessQrScreen( - transferType = TransferType.LINK, + transferType = TransferTypeUi.QR_CODE, transferUrl = "https://chk.me/83azQOl", closeActivity = {} ) diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt index 54d498050..e13f36aca 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/upload/UploadSuccessScreen.kt @@ -20,19 +20,19 @@ package com.infomaniak.swisstransfer.ui.screen.newtransfer.upload import androidx.activity.compose.BackHandler import androidx.compose.material3.Surface import androidx.compose.runtime.Composable -import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType +import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferTypeUi import com.infomaniak.swisstransfer.ui.theme.SwissTransferTheme import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows @Composable fun UploadSuccessScreen( - transferType: TransferType, + transferType: TransferTypeUi, transferUrl: String, closeActivity: () -> Unit, ) { BackHandler(onBack = closeActivity) - if (transferType == TransferType.MAIL) { + if (transferType == TransferTypeUi.MAIL) { UploadSuccessEmailScreen(closeActivity = closeActivity) } else { UploadSuccessQrScreen(transferType, transferUrl, closeActivity) @@ -45,7 +45,7 @@ private fun UploadSuccessScreenPreview() { SwissTransferTheme { Surface { UploadSuccessScreen( - transferType = TransferType.QR_CODE, + transferType = TransferTypeUi.QR_CODE, transferUrl = "https://chk.me/83azQOl", closeActivity = {} )