From dda6fbb5dd3bf0b84bdac531168906f7f729318a Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 15 Nov 2023 10:29:42 +0000 Subject: [PATCH 01/14] feat: show scan instructions if they exist Context: If there are scan instructions in the scan parameters, we present them in a Text composable (https://developer.android.com/jetpack/compose/text). References: https://outsystemsrd.atlassian.net/browse/RMET-2761 --- pom.xml | 2 +- .../plugins/barcode/view/OSBARCScannerActivity.kt | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e0e1c63..a1e5a64 100644 --- a/pom.xml +++ b/pom.xml @@ -7,5 +7,5 @@ 4.0.0 com.github.outsystems osbarcode-android - 0.0.20 + 0.0.21 diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 7dc815c..dc96f01 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -25,12 +25,14 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.shape.CircleShape import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext @@ -205,6 +207,14 @@ class OSBARCScannerActivity : ComponentActivity() { if (camera.cameraInfo.hasFlashUnit()) { TorchButton() } + + if (!parameters.scanInstructions.isNullOrEmpty()) { + Text( + text = parameters.scanInstructions, + modifier = Modifier.align(Alignment.Center), + color = Color.White + ) + } } } From cdfc854f59217a218f9388a28c3ead517f8efbe4 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 15 Nov 2023 10:52:01 +0000 Subject: [PATCH 02/14] chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-2761 --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ad77c6..e42cbbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository. ## [Unreleased] +### 14-11-2023 +Android - Implement Scan Instructions (https://outsystemsrd.atlassian.net/browse/RMET-2761) + ### 14-11-2023 Android - Implement Torch Button to settings (https://outsystemsrd.atlassian.net/browse/RMET-2759) From b983a4efb45f131047b967da8bb55b761ff9b313 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 15 Nov 2023 12:59:06 +0000 Subject: [PATCH 03/14] fix: align text to the center Context: This way, when the text has to be presented in more than 1 line, it is centered. References: https://outsystemsrd.atlassian.net/browse/RMET-2761 --- .../outsystems/plugins/barcode/view/OSBARCScannerActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index dc96f01..1c6b828 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -38,6 +38,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.painterResource +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.viewinterop.AndroidView import androidx.core.content.ContextCompat import com.outsystems.plugins.barcode.R @@ -212,7 +213,8 @@ class OSBARCScannerActivity : ComponentActivity() { Text( text = parameters.scanInstructions, modifier = Modifier.align(Alignment.Center), - color = Color.White + color = Color.White, + textAlign = TextAlign.Center ) } } From cc12910a91e139ac2843815331a1a7b2096f899c Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 15 Nov 2023 13:02:32 +0000 Subject: [PATCH 04/14] chore: update changelog References: https://outsystemsrd.atlassian.net/browse/RMET-2761 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a1e5a64..f984167 100644 --- a/pom.xml +++ b/pom.xml @@ -7,5 +7,5 @@ 4.0.0 com.github.outsystems osbarcode-android - 0.0.21 + 0.0.22 From c0e7bf9f84a6445ceb0149a0876ad6e3d9917625 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 15 Nov 2023 13:41:30 +0000 Subject: [PATCH 05/14] feat: add scan button and close button References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../barcode/model/OSBARCScanParameters.kt | 4 +- .../barcode/view/OSBARCScannerActivity.kt | 47 +++++++++++++++++++ .../plugins/barcode/view/ui.theme/Color.kt | 4 +- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/model/OSBARCScanParameters.kt b/src/main/kotlin/com/outsystems/plugins/barcode/model/OSBARCScanParameters.kt index ed0244d..3219f0b 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/model/OSBARCScanParameters.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/model/OSBARCScanParameters.kt @@ -9,8 +9,8 @@ data class OSBARCScanParameters( val scanInstructions: String?, val cameraDirection: Int?, val scanOrientation: Int?, - val scanButton: Boolean?, - val scanText: String?, + val scanButton: Boolean, + val scanText: String, val hint: Int?, val androidScanningLibrary: String? ) : Serializable \ No newline at end of file diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 1c6b828..13a9d93 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -23,8 +23,11 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Clear import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.SideEffect @@ -35,6 +38,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.res.painterResource @@ -49,6 +53,7 @@ import com.outsystems.plugins.barcode.controller.helper.OSBARCZXingHelper import com.outsystems.plugins.barcode.model.OSBARCError import com.outsystems.plugins.barcode.model.OSBARCScanParameters import com.outsystems.plugins.barcode.view.ui.theme.BarcodeScannerTheme +import com.outsystems.plugins.barcode.view.ui.theme.CustomGray /** * This class is responsible for implementing the UI of the scanning screen using Jetpack Compose. @@ -205,10 +210,30 @@ class OSBARCScannerActivity : ComponentActivity() { modifier = Modifier.fillMaxSize() ) + // close button + Button( + onClick = { + //setResult(OSBARCError.SCAN_CANCELLED_ERROR.code) + //finish() + }, + colors = ButtonDefaults.buttonColors( + containerColor = Color.Transparent + ), + modifier = Modifier.align(Alignment.TopEnd) + ) { + Icon( + imageVector = Icons.Default.Clear, + contentDescription = null, + tint = CustomGray + ) + } + + // flashlight button if (camera.cameraInfo.hasFlashUnit()) { TorchButton() } + // text with scan instructions if (!parameters.scanInstructions.isNullOrEmpty()) { Text( text = parameters.scanInstructions, @@ -217,6 +242,28 @@ class OSBARCScannerActivity : ComponentActivity() { textAlign = TextAlign.Center ) } + + // scan button to turn on scanning when used + if (parameters.scanButton) { + Button( + onClick = { + // turn on scanning, which should be disabled + }, + colors = ButtonDefaults.buttonColors( + containerColor = Color.DarkGray + ), + shape = RectangleShape, + modifier = Modifier.align(Alignment.BottomCenter) + ) { + Text( + text = parameters.scanText, + color = Color.White, + textAlign = TextAlign.Center + + ) + } + } + } } diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/ui.theme/Color.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/ui.theme/Color.kt index 12c1a50..546ed22 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/ui.theme/Color.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/ui.theme/Color.kt @@ -8,4 +8,6 @@ val Pink80 = Color(0xFFEFB8C8) val Purple40 = Color(0xFF6650a4) val PurpleGrey40 = Color(0xFF625b71) -val Pink40 = Color(0xFF7D5260) \ No newline at end of file +val Pink40 = Color(0xFF7D5260) + +val CustomGray = Color(0xFFB3BAC4) \ No newline at end of file From c72512432f8446975c89529b6e18204f555c492c Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 16 Nov 2023 09:50:13 +0000 Subject: [PATCH 06/14] feat: finish activity with SCAN_CANCELLED_ERROR on close button click References: https://outsystemsrd.atlassian.net/browse/RMET-2761 --- .../outsystems/plugins/barcode/view/OSBARCScannerActivity.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 13a9d93..457eeda 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -213,8 +213,8 @@ class OSBARCScannerActivity : ComponentActivity() { // close button Button( onClick = { - //setResult(OSBARCError.SCAN_CANCELLED_ERROR.code) - //finish() + setResult(OSBARCError.SCAN_CANCELLED_ERROR.code) + finish() }, colors = ButtonDefaults.buttonColors( containerColor = Color.Transparent From b9245ebbb1d1bcf31a82011f7e32ef13193a645f Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 16 Nov 2023 10:08:56 +0000 Subject: [PATCH 07/14] feat: only send barcode result when scanning Context: When there's a scan button, we only want to start scanning when the button in clicked. For now, this behaviour is "faked" by us only sending the barcode result when the button in clicked. References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../barcode/view/OSBARCScannerActivity.kt | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 457eeda..e2ce0ff 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -45,7 +45,6 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.viewinterop.AndroidView import androidx.core.content.ContextCompat -import com.outsystems.plugins.barcode.R import com.outsystems.plugins.barcode.controller.OSBARCBarcodeAnalyzer import com.outsystems.plugins.barcode.controller.OSBARCScanLibraryFactory import com.outsystems.plugins.barcode.controller.helper.OSBARCMLKitHelper @@ -53,6 +52,7 @@ import com.outsystems.plugins.barcode.controller.helper.OSBARCZXingHelper import com.outsystems.plugins.barcode.model.OSBARCError import com.outsystems.plugins.barcode.model.OSBARCScanParameters import com.outsystems.plugins.barcode.view.ui.theme.BarcodeScannerTheme +import com.outsystems.plugins.barcode.R import com.outsystems.plugins.barcode.view.ui.theme.CustomGray /** @@ -65,6 +65,7 @@ class OSBARCScannerActivity : ComponentActivity() { private lateinit var selector: CameraSelector private var permissionRequestCount = 0 private var showDialog by mutableStateOf(false) + private var scanning = true companion object { private const val SCAN_SUCCESS_RESULT_CODE = -1 @@ -82,6 +83,9 @@ class OSBARCScannerActivity : ComponentActivity() { actionBar?.hide() val parameters = intent.extras?.getSerializable(SCAN_PARAMETERS) as OSBARCScanParameters + + scanning = !parameters.scanButton + selector = CameraSelector.Builder() .requireLensFacing(if (parameters.cameraDirection == CAM_DIRECTION_FRONT) CameraSelector.LENS_FACING_FRONT else CameraSelector.LENS_FACING_BACK) .build() @@ -182,14 +186,18 @@ class OSBARCScannerActivity : ComponentActivity() { OSBARCMLKitHelper() ), { result -> - val resultIntent = Intent() - resultIntent.putExtra(SCAN_RESULT, result) - setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent) - finish() + if (scanning) { + val resultIntent = Intent() + resultIntent.putExtra(SCAN_RESULT, result) + setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent) + finish() + } }, { - setResult(it.code) - finish() + if (scanning) { + setResult(it.code) + finish() + } } ) ) @@ -247,7 +255,7 @@ class OSBARCScannerActivity : ComponentActivity() { if (parameters.scanButton) { Button( onClick = { - // turn on scanning, which should be disabled + scanning = true }, colors = ButtonDefaults.buttonColors( containerColor = Color.DarkGray From 64d8bb0fc255685c82c76ceb3180ff03d62c84cb Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 16 Nov 2023 11:41:45 +0000 Subject: [PATCH 08/14] refactor: add comments for context References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../outsystems/plugins/barcode/view/OSBARCScannerActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index e2ce0ff..4e197ef 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -186,6 +186,7 @@ class OSBARCScannerActivity : ComponentActivity() { OSBARCMLKitHelper() ), { result -> + // we only want to process the scan result if scanning is active if (scanning) { val resultIntent = Intent() resultIntent.putExtra(SCAN_RESULT, result) @@ -194,6 +195,7 @@ class OSBARCScannerActivity : ComponentActivity() { } }, { + // we only want to process the scan result if scanning is active if (scanning) { setResult(it.code) finish() From 4c74aa9eb958ff58d526274750e9279383bc2709 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 16 Nov 2023 12:02:12 +0000 Subject: [PATCH 09/14] refactor: remove extra line References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 4e197ef..c48e7b7 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -269,7 +269,6 @@ class OSBARCScannerActivity : ComponentActivity() { text = parameters.scanText, color = Color.White, textAlign = TextAlign.Center - ) } } From 1537623818a1c1946dd885275a8c789826ed87cd Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 16 Nov 2023 12:05:56 +0000 Subject: [PATCH 10/14] chore: udpate changelog References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- CHANGELOG.md | 5 ++++- pom.xml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e42cbbc..2bf8243 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,10 @@ The changes documented here do not include those from the original repository. ## [Unreleased] -### 14-11-2023 +### 16-11-2023 +Android - Implement Scan Button (https://outsystemsrd.atlassian.net/browse/RMET-2762) + +### 15-11-2023 Android - Implement Scan Instructions (https://outsystemsrd.atlassian.net/browse/RMET-2761) ### 14-11-2023 diff --git a/pom.xml b/pom.xml index f984167..121f322 100644 --- a/pom.xml +++ b/pom.xml @@ -7,5 +7,5 @@ 4.0.0 com.github.outsystems osbarcode-android - 0.0.22 + 0.0.23 From ccc1ea3603447b7a3e2db49619c74c2f0d8e7d8b Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Thu, 16 Nov 2023 12:09:38 +0000 Subject: [PATCH 11/14] refactor: remove extra lines References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../outsystems/plugins/barcode/view/OSBARCScannerActivity.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index c48e7b7..17c1a1d 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -83,9 +83,7 @@ class OSBARCScannerActivity : ComponentActivity() { actionBar?.hide() val parameters = intent.extras?.getSerializable(SCAN_PARAMETERS) as OSBARCScanParameters - scanning = !parameters.scanButton - selector = CameraSelector.Builder() .requireLensFacing(if (parameters.cameraDirection == CAM_DIRECTION_FRONT) CameraSelector.LENS_FACING_FRONT else CameraSelector.LENS_FACING_BACK) .build() From ecc9feaed1a152809cfa351ee215b4e0f969bea1 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 17 Nov 2023 09:28:08 +0000 Subject: [PATCH 12/14] refactor: use helper methods to process scan result References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../barcode/view/OSBARCScannerActivity.kt | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 17c1a1d..5c9487f 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -52,8 +52,8 @@ import com.outsystems.plugins.barcode.controller.helper.OSBARCZXingHelper import com.outsystems.plugins.barcode.model.OSBARCError import com.outsystems.plugins.barcode.model.OSBARCScanParameters import com.outsystems.plugins.barcode.view.ui.theme.BarcodeScannerTheme -import com.outsystems.plugins.barcode.R import com.outsystems.plugins.barcode.view.ui.theme.CustomGray +import com.outsystems.plugins.barcode.R /** * This class is responsible for implementing the UI of the scanning screen using Jetpack Compose. @@ -184,20 +184,10 @@ class OSBARCScannerActivity : ComponentActivity() { OSBARCMLKitHelper() ), { result -> - // we only want to process the scan result if scanning is active - if (scanning) { - val resultIntent = Intent() - resultIntent.putExtra(SCAN_RESULT, result) - setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent) - finish() - } + processReadSuccess(result) }, { - // we only want to process the scan result if scanning is active - if (scanning) { - setResult(it.code) - finish() - } + processReadError(it) } ) ) @@ -309,4 +299,22 @@ class OSBARCScannerActivity : ComponentActivity() { ) == PackageManager.PERMISSION_GRANTED } + private fun processReadSuccess(result: String) { + // we only want to process the scan result if scanning is active + if (scanning) { + val resultIntent = Intent() + resultIntent.putExtra(SCAN_RESULT, result) + setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent) + finish() + } + } + + private fun processReadError(error: OSBARCError) { + // we only want to process the scan result if scanning is active + if (scanning) { + setResult(error.code) + finish() + } + } + } \ No newline at end of file From 22c1b22ceb47ef0ef0acd8aad3716255e8e63938 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 17 Nov 2023 09:58:53 +0000 Subject: [PATCH 13/14] refactor: handle all conditions to show dialog in the dialog component 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 --- .../view/OSBARCCameraPermissionDialog.kt | 3 +- .../barcode/view/OSBARCScannerActivity.kt | 39 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt index 4e31b4a..b18aee6 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt @@ -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( diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index 5c9487f..babd712 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -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 { From 5b073c7667562e935773c68d71f455faed62e96f Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Fri, 17 Nov 2023 12:00:41 +0000 Subject: [PATCH 14/14] refactor: use correct term for comment References: https://outsystemsrd.atlassian.net/browse/RMET-2762 --- .../outsystems/plugins/barcode/view/OSBARCScannerActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt index babd712..d6eb15d 100644 --- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt +++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt @@ -309,7 +309,7 @@ class OSBARCScannerActivity : ComponentActivity() { } private fun processReadError(error: OSBARCError) { - // we only want to process the scan result if scanning is active + // we only want to process the scan error if scanning is active if (scanning) { setResult(error.code) finish()