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

feat: Require recipients and display real data to success screen #281

Merged
merged 4 commits into from
Dec 23, 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 @@ -99,9 +99,17 @@ sealed class NewTransferNavigation : NavigationDestination() {
@Serializable
data object ValidateUserEmailDestination : NewTransferNavigation()
@Serializable
data class UploadProgressDestination(val transferType: TransferTypeUi, val totalSize: Long) : NewTransferNavigation()
data class UploadProgressDestination(
val transferType: TransferTypeUi,
val totalSize: Long,
val recipients: List<String>,
) : NewTransferNavigation()
@Serializable
data class UploadSuccessDestination(val transferType: TransferTypeUi, val transferUrl: String) : NewTransferNavigation()
data class UploadSuccessDestination(
val transferType: TransferTypeUi,
val transferUrl: String,
val recipients: List<String>,
) : NewTransferNavigation()
@Serializable
data object UploadErrorDestination : NewTransferNavigation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class ImportFilesViewModel @Inject constructor(
isRecipientEmailInvalid = { isRecipientEmailInvalid },
validatedRecipientsEmails = GetSetCallbacks(
get = { validatedRecipientsEmails },
set = { validatedRecipientsEmails = it }
set = { validatedRecipientsEmails = it },
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
composable<ImportFilesDestination> {
ImportFilesScreen(
closeActivity = closeActivity,
navigateToUploadProgress = { transferType, totalSize ->
navController.navigate(UploadProgressDestination(transferType, totalSize))
navigateToUploadProgress = { transferType, totalSize, recipients ->
navController.navigate(UploadProgressDestination(transferType, totalSize, recipients))
},
)
}
Expand All @@ -50,7 +50,7 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
UploadProgressScreen(
totalSizeInBytes = args.totalSize,
navigateToUploadSuccess = { transferUrl ->
navController.navigate(UploadSuccessDestination(args.transferType, transferUrl))
navController.navigate(UploadSuccessDestination(args.transferType, transferUrl, args.recipients))
},
navigateToUploadError = { navController.navigate(UploadErrorDestination) },
navigateBackToImportFiles = { navController.popBackStack(route = ImportFilesDestination, inclusive = false) },
Expand All @@ -61,6 +61,7 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
UploadSuccessScreen(
transferType = args.transferType,
transferUrl = args.transferUrl,
recipients = args.recipients,
closeActivity = closeActivity,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private val HORIZONTAL_PADDING = Margin.Medium
fun ImportFilesScreen(
importFilesViewModel: ImportFilesViewModel = hiltViewModel<ImportFilesViewModel>(),
closeActivity: () -> Unit,
navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit,
navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long, recipients: List<String>) -> Unit,
) {

val files by importFilesViewModel.importedFilesDebounced.collectAsStateWithLifecycle()
Expand All @@ -78,11 +78,18 @@ fun ImportFilesScreen(

val snackbarHostState = remember { SnackbarHostState() }

val emailTextFieldCallbacks = importFilesViewModel.getEmailTextFieldCallbacks()

HandleSendActionResult(
snackbarHostState = snackbarHostState,
sendStatus = { sendStatus },
transferType = { selectedTransferType },
navigateToUploadProgress = navigateToUploadProgress,
navigateToUploadProgress = { totalSize ->
navigateToUploadProgress(
selectedTransferType,
totalSize,
emailTextFieldCallbacks.validatedRecipientsEmails.get().toList(),
)
},
resetSendActionResult = importFilesViewModel::resetSendActionResult,
)

Expand Down Expand Up @@ -126,7 +133,7 @@ fun ImportFilesScreen(
files = { files },
filesToImportCount = { filesToImportCount },
currentSessionFilesCount = { currentSessionFilesCount },
emailTextFieldCallbacks = importFilesViewModel.getEmailTextFieldCallbacks(),
emailTextFieldCallbacks = emailTextFieldCallbacks,
transferMessageCallbacks = importFilesViewModel.transferMessageCallbacks,
selectedTransferType = GetSetCallbacks(
get = { selectedTransferType },
Expand All @@ -146,8 +153,7 @@ fun ImportFilesScreen(
private fun HandleSendActionResult(
snackbarHostState: SnackbarHostState,
sendStatus: () -> SendStatus,
transferType: () -> TransferTypeUi,
navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit,
navigateToUploadProgress: (totalSize: Long) -> Unit,
resetSendActionResult: () -> Unit,
) {
val context = LocalContext.current
Expand All @@ -159,7 +165,7 @@ private fun HandleSendActionResult(
// If we don't reset the ImportFiles state machine, we'll automatically navigate-back to UploadProgress again.
// So, before leaving ImportFiles to go to UploadProgress, we need to reset the ImportFiles state machine.
resetSendActionResult()
navigateToUploadProgress(transferType(), actionResult.totalSize)
navigateToUploadProgress(actionResult.totalSize)
}
is SendStatus.Refused -> {
snackbarHostState.showSnackbar(context.getString(R.string.errorAppIntegrity))
Expand Down Expand Up @@ -192,6 +198,15 @@ private fun ImportFilesScreen(
) {

val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } }
val areEmailsCorrects by remember {
derivedStateOf {
with(emailTextFieldCallbacks) {
val areAuthorAndRecipientsCorrects = transferAuthorEmail.get().isNotEmpty() && !isAuthorEmailInvalid()
&& validatedRecipientsEmails.get().isNotEmpty()
!shouldShowEmailAddressesFields || areAuthorAndRecipientsCorrects
}
}
}

BottomStickyButtonScaffold(
topBar = {
Expand All @@ -207,8 +222,7 @@ private fun ImportFilesScreen(
filesToImportCount = filesToImportCount,
currentSessionFilesCount = currentSessionFilesCount,
importedFiles = files,
shouldShowEmailAddressesFields = { shouldShowEmailAddressesFields },
isAuthorEmailInvalid = emailTextFieldCallbacks.isAuthorEmailInvalid,
areEmailsCorrects = { areEmailsCorrects },
sendStatus = sendStatus,
sendTransfer = sendTransfer,
)
Expand Down Expand Up @@ -398,8 +412,7 @@ private fun SendButton(
filesToImportCount: () -> Int,
currentSessionFilesCount: () -> Int,
importedFiles: () -> List<FileUi>,
shouldShowEmailAddressesFields: () -> Boolean,
isAuthorEmailInvalid: () -> Boolean,
areEmailsCorrects: () -> Boolean,
sendStatus: () -> SendStatus,
sendTransfer: () -> Unit,
) {
Expand All @@ -414,16 +427,12 @@ private fun SendButton(
null
}

val isSenderEmailCorrect by remember {
derivedStateOf { !shouldShowEmailAddressesFields() || !isAuthorEmailInvalid() }
}

LargeButton(
modifier = modifier,
title = stringResource(R.string.transferSendButton),
style = ButtonType.PRIMARY,
showIndeterminateProgress = { sendStatus() == SendStatus.Pending },
enabled = { importedFiles().isNotEmpty() && !isImporting && isSenderEmailCorrect && sendStatus().canEnableButton() },
enabled = { importedFiles().isNotEmpty() && !isImporting && areEmailsCorrects() && sendStatus().canEnableButton() },
progress = progress,
onClick = { sendTransfer() },
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,20 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
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.previewparameter.emailsPreviewData
import com.infomaniak.swisstransfer.ui.previewparameter.EmailsPreviewParameter
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

@Composable
fun UploadSuccessEmailScreen(
emails: List<String> = emailsPreviewData, // TODO: Use real data
closeActivity: () -> Unit,
) {
fun UploadSuccessEmailScreen(emails: List<String>, closeActivity: () -> Unit) {
BottomStickyButtonScaffold(
topBar = { BrandTopAppBar() },
bottomButton = {
Expand Down Expand Up @@ -80,10 +78,10 @@ fun UploadSuccessEmailScreen(

@PreviewAllWindows
@Composable
private fun UploadSuccessEmailScreenPreview() {
private fun UploadSuccessEmailScreenPreview(@PreviewParameter(EmailsPreviewParameter::class) emails: List<String>) {
SwissTransferTheme {
Surface {
UploadSuccessEmailScreen(closeActivity = {})
UploadSuccessEmailScreen(emails) {}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import com.infomaniak.swisstransfer.ui.utils.PreviewAllWindows
fun UploadSuccessScreen(
transferType: TransferTypeUi,
transferUrl: String,
recipients: List<String>,
closeActivity: () -> Unit,
) {
BackHandler(onBack = closeActivity)

if (transferType == TransferTypeUi.MAIL) {
UploadSuccessEmailScreen(closeActivity = closeActivity)
UploadSuccessEmailScreen(emails = recipients, closeActivity = closeActivity)
} else {
UploadSuccessQrScreen(transferType, transferUrl, closeActivity)
}
Expand All @@ -47,7 +48,8 @@ private fun UploadSuccessScreenPreview() {
UploadSuccessScreen(
transferType = TransferTypeUi.QR_CODE,
transferUrl = "https://chk.me/83azQOl",
closeActivity = {}
recipients = emptyList(),
closeActivity = {},
)
}
}
Expand Down
Loading