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 28e814e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 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 Down Expand Up @@ -82,6 +81,7 @@ fun ImportFilesScreen(
val snackbarHostState = remember { SnackbarHostState() }

HandleIntegrityCheckResult(
snackbarHostState = snackbarHostState,
integrityCheckResult = { integrityCheckResult },
resetResult = { importFilesViewModel.resetIntegrityCheckResult() },
)
Expand Down Expand Up @@ -176,14 +176,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 28e814e

Please sign in to comment.