Skip to content

Commit

Permalink
refactor: handle all conditions to show dialog in the dialog component
Browse files Browse the repository at this point in the history
Context: This refactor was necessary to reduce the cognitive complexity of the ScanScreen method, as pointed out by SonarCloud.

References: https://outsystemsrd.atlassian.net/browse/RMET-2762
  • Loading branch information
alexgerardojacinto committed Nov 17, 2023
1 parent ecc9fea commit 22c1b22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import androidx.compose.ui.unit.sp
fun CameraPermissionRequiredDialog(
onDismissRequest: () -> Unit,
onConfirmation: () -> Unit,
permissionGiven: Boolean,
shouldShowDialog: Boolean,
dialogTitle: String,
dialogText: String,
confirmButtonText: String,
dismissButtonText: String
) {
if (shouldShowDialog) {
if (!permissionGiven && shouldShowDialog) {
AlertDialog(
title = {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,25 @@ class OSBARCScannerActivity : ComponentActivity() {
}
}

if (!permissionGiven) {
CameraPermissionRequiredDialog(
onDismissRequest = {
this.setResult(OSBARCError.CAMERA_PERMISSION_DENIED_ERROR.code)
this.finish()
},
onConfirmation = {
val intent = Intent().apply {
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
data = Uri.fromParts("package", context.packageName, null)
}
context.startActivity(intent)
},
shouldShowDialog = showDialog,
dialogTitle = "Camera Access Not Enabled",
dialogText = "To continue, please go to the Settings app and enable it.",
confirmButtonText = "Settings",
dismissButtonText = "Ok"
)
}
CameraPermissionRequiredDialog(
onDismissRequest = {
this.setResult(OSBARCError.CAMERA_PERMISSION_DENIED_ERROR.code)
this.finish()
},
onConfirmation = {
val intent = Intent().apply {
action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
data = Uri.fromParts("package", context.packageName, null)
}
context.startActivity(intent)
},
permissionGiven = permissionGiven,
shouldShowDialog = showDialog,
dialogTitle = "Camera Access Not Enabled",
dialogText = "To continue, please go to the Settings app and enable it.",
confirmButtonText = "Settings",
dismissButtonText = "Ok"
)

// rest of the UI
val cameraProviderFuture = remember {
Expand Down

0 comments on commit 22c1b22

Please sign in to comment.