Skip to content

Commit

Permalink
fix: Reset transfer status when we received an error when creating th…
Browse files Browse the repository at this point in the history
…e upload container
  • Loading branch information
tevincent committed Dec 17, 2024
1 parent 291901f commit bffd9ac
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ class ImportFilesViewModel @Inject constructor(
}
}

fun resetSendActionResult() {
_sendActionResult.value = SendActionResult.NotStarted
}

private suspend fun removeOldData() {
importationFilesManager.removeLocalCopyFolder()
uploadManager.removeAllUploadSession()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.PreviewParameter
Expand Down Expand Up @@ -73,7 +75,9 @@ fun ImportFilesScreen(

val sendActionResult by importFilesViewModel.sendActionResult.collectAsStateWithLifecycle()

HandleSendActionResult({ sendActionResult }, { selectedTransferType }, navigateToUploadProgress)
val snackbarHostState = remember { SnackbarHostState() }

HandleSendActionResult(snackbarHostState, { sendActionResult }, { selectedTransferType }, navigateToUploadProgress)

LaunchedEffect(Unit) { importFilesViewModel.initTransferOptionsValues() }

Expand Down Expand Up @@ -126,20 +130,24 @@ fun ImportFilesScreen(
closeActivity = closeActivity,
shouldStartByPromptingUserForFiles = true,
sendTransfer = importFilesViewModel::sendTransfer,
isTransferStarted = { sendActionResult != SendActionResult.NotStarted },
isTransferStarted = { sendActionResult != SendActionResult.NotStarted && sendActionResult != SendActionResult.Failure },
snackbarHostState = snackbarHostState,
)
}

@Composable
private fun HandleSendActionResult(
snackbarHostState: SnackbarHostState,
getSendActionResult: () -> SendActionResult?,
transferType: () -> TransferTypeUi,
navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit,
) {
val context = LocalContext.current

LaunchedEffect(getSendActionResult()) {
when (val actionResult = getSendActionResult()) {
is SendActionResult.Success -> navigateToUploadProgress(transferType(), actionResult.totalSize)
is SendActionResult.Failure -> Unit // TODO: Show error
is SendActionResult.Failure -> snackbarHostState.showSnackbar(context.getString(R.string.errorUnknown))
else -> Unit
}
}
Expand All @@ -159,6 +167,7 @@ private fun ImportFilesScreen(
shouldStartByPromptingUserForFiles: Boolean,
sendTransfer: () -> Unit,
isTransferStarted: () -> Boolean,
snackbarHostState: SnackbarHostState? = null,
) {

val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } }
Expand Down Expand Up @@ -197,7 +206,8 @@ private fun ImportFilesScreen(
)
TransferOptions(modifier, transferOptionsCallbacks)
}
}
},
snackbarHostState = snackbarHostState,
)
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="contentDescriptionCreateNewTransferButton">Neuer Transfer</string>
<string name="downloadedTransferLabel">Heruntergeladene Übertragung: %d/%d</string>
<string name="errorTransferPasswordLength">Das Passwort muss zwischen 6 und 25 Zeichen lang sein</string>
<string name="errorUnknown">Ein Fehler ist aufgetreten</string>
<string name="expiresIn">Verfällt in %d Tagen</string>
<plurals name="filesCount">
<item quantity="one">%d Datei</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="contentDescriptionCreateNewTransferButton">Nueva transferencia</string>
<string name="downloadedTransferLabel">Transferencia descargada: %d/%d</string>
<string name="errorTransferPasswordLength">La contraseña debe tener entre 6 y 25 caracteres</string>
<string name="errorUnknown">Se ha producido un error</string>
<string name="expiresIn">Caduca en %d días</string>
<plurals name="filesCount">
<item quantity="one">%d archivo</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="contentDescriptionCreateNewTransferButton">Nouveau transfert</string>
<string name="downloadedTransferLabel">Transfert téléchargé : %d/%d\u0020</string>
<string name="errorTransferPasswordLength">Le mot de passe doit comporter entre 6 et 25 caractères</string>
<string name="errorUnknown">Une erreur est survenue</string>
<string name="expiresIn">Expire dans %d jours</string>
<plurals name="filesCount">
<item quantity="one">%d fichier</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<string name="contentDescriptionCreateNewTransferButton">Nuovo trasferimento</string>
<string name="downloadedTransferLabel">Trasferimento scaricato: %d/%d</string>
<string name="errorTransferPasswordLength">La password deve essere compresa tra 6 e 24 caratteri</string>
<string name="errorUnknown">Si è verificato un errore</string>
<string name="expiresIn">Scade tra %d giorni</string>
<plurals name="filesCount">
<item quantity="one">%d file</item>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<string name="contentDescriptionCreateNewTransferButton">New transfer</string>
<string name="downloadedTransferLabel">Downloaded transfer: %d/%d\u0020</string>
<string name="errorTransferPasswordLength">The password must be between 6 and 25 characters</string>
<string name="errorUnknown">An error has occurred</string>
<string name="expiresIn">Expires in %d days</string>
<plurals name="filesCount">
<item quantity="one">%d file</item>
Expand Down

0 comments on commit bffd9ac

Please sign in to comment.