Skip to content

Commit

Permalink
refactor(AppIntegrity): Use a snackbar instead of a toast to display …
Browse files Browse the repository at this point in the history
…error message
  • Loading branch information
FabianDevel committed Dec 17, 2024
1 parent 6d405c0 commit fba120f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@ class ImportFilesViewModel @Inject constructor(
_sendActionResult.value = SendActionResult.NotStarted
}

fun startTransfer(appIntegrityManager: AppIntegrityManager) {
runCatching {
checkAppIntegrity(appIntegrityManager)
}.onFailure { exception ->
SentryLog.e(TAG, "Failed to start the upload", exception)
_sendActionResult.update { SendActionResult.Failure }
}
}

//region App Integrity
fun checkAppIntegrity() {
_integrityCheckResult.value = AppIntegrityResult.Ongoing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles

import android.net.Uri
import android.widget.Toast
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
Expand All @@ -32,7 +31,6 @@ 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 @@ -82,6 +80,7 @@ fun ImportFilesScreen(
val snackbarHostState = remember { SnackbarHostState() }

HandleIntegrityCheckResult(
snackbarHostState = snackbarHostState,
integrityCheckResult = { integrityCheckResult },
resetResult = { importFilesViewModel.resetIntegrityCheckResult() },
)
Expand Down Expand Up @@ -160,13 +159,12 @@ private fun HandleSendActionResult(
navigateToUploadProgress: (transferType: TransferTypeUi, totalSize: Long) -> Unit,
resetSendActionResult: () -> Unit,
) {
val context = LocalContext.current

val errorMessage = stringResource(R.string.errorUnknown)
LaunchedEffect(getSendActionResult()) {
when (val actionResult = getSendActionResult()) {
is SendActionResult.Success -> navigateToUploadProgress(transferType(), actionResult.totalSize)
is SendActionResult.Failure -> {
snackbarHostState.showSnackbar(context.getString(R.string.errorUnknown))
snackbarHostState.showSnackbar(errorMessage)
resetSendActionResult()
}
else -> Unit
Expand All @@ -176,14 +174,16 @@ private fun HandleSendActionResult(

@Composable
private fun HandleIntegrityCheckResult(
snackbarHostState: SnackbarHostState,
integrityCheckResult: () -> AppIntegrityResult,
resetResult: () -> Unit,
) {
val result = integrityCheckResult()
val context = LocalContext.current
val errorMessage = stringResource(R.string.errorAppIntegrity)

LaunchedEffect(result == AppIntegrityResult.Success || result == AppIntegrityResult.Fail) {
if (integrityCheckResult() == AppIntegrityResult.Fail) { // TODO: Better error management
Toast.makeText(context, R.string.errorAppIntegrity, Toast.LENGTH_LONG).show()
snackbarHostState.showSnackbar(errorMessage)
}
resetResult()
}
Expand Down

0 comments on commit fba120f

Please sign in to comment.