diff --git a/CHANGELOG.md b/CHANGELOG.md
index 933ef9e..21b75e5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,9 @@ The changes documented here do not include those from the original repository.
## [Unreleased]
+### 13-11-2023
+Android - Implement AlertDialog to settings (https://outsystemsrd.atlassian.net/browse/RMET-2764)
+
### 13-11-2023
Android - Select Camera (Back or Front) (https://outsystemsrd.atlassian.net/browse/RMET-2764)
diff --git a/pom.xml b/pom.xml
index ecaadcf..c59e8ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,5 +7,5 @@
4.0.0
com.github.outsystems
osbarcode-android
- 0.0.12
+ 0.0.14
diff --git a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt
new file mode 100644
index 0000000..4e31b4a
--- /dev/null
+++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCCameraPermissionDialog.kt
@@ -0,0 +1,53 @@
+package com.outsystems.plugins.barcode.view
+
+import androidx.compose.material3.AlertDialog
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextButton
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.unit.sp
+
+@Composable
+fun CameraPermissionRequiredDialog(
+ onDismissRequest: () -> Unit,
+ onConfirmation: () -> Unit,
+ shouldShowDialog: Boolean,
+ dialogTitle: String,
+ dialogText: String,
+ confirmButtonText: String,
+ dismissButtonText: String
+) {
+ if (shouldShowDialog) {
+ AlertDialog(
+ title = {
+ Text(
+ text = dialogTitle,
+ fontSize = 20.sp
+ )
+ },
+ text = {
+ Text(text = dialogText)
+ },
+ onDismissRequest = {
+ onDismissRequest()
+ },
+ confirmButton = {
+ TextButton(
+ onClick = {
+ onConfirmation()
+ }
+ ) {
+ Text(confirmButtonText)
+ }
+ },
+ dismissButton = {
+ TextButton(
+ onClick = {
+ onDismissRequest()
+ }
+ ) {
+ Text(dismissButtonText)
+ }
+ }
+ )
+ }
+}
\ 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 31298c2..ec5d34c 100644
--- a/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt
+++ b/src/main/kotlin/com/outsystems/plugins/barcode/view/OSBARCScannerActivity.kt
@@ -1,8 +1,12 @@
package com.outsystems.plugins.barcode.view
import android.Manifest
+import android.content.Context
import android.content.Intent
+import android.content.pm.PackageManager
+import android.net.Uri
import android.os.Bundle
+import android.provider.Settings
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
@@ -43,6 +47,9 @@ import java.lang.Exception
*/
class OSBARCScannerActivity : ComponentActivity() {
+ private var permissionRequestCount = 0
+ private var showDialog by mutableStateOf(false)
+
companion object {
private const val SCAN_SUCCESS_RESULT_CODE = -1
private const val SCAN_RESULT = "scanResult"
@@ -64,6 +71,11 @@ class OSBARCScannerActivity : ComponentActivity() {
}
}
+ override fun onResume() {
+ super.onResume()
+ showDialog = !hasCameraPermission(this.applicationContext)
+ }
+
/**
* Composable function, responsible for declaring the UI of the screen,
* as well as creating an instance of OSBARCBarcodeAnalyzer for image analysis.
@@ -72,29 +84,52 @@ class OSBARCScannerActivity : ComponentActivity() {
fun ScanScreen(parameters: OSBARCScanParameters) {
val lifecycleOwner = LocalLifecycleOwner.current
val context = LocalContext.current
+ var permissionGiven by remember { mutableStateOf(true) }
// permissions
val requestPermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
- // do nothing, continue
+ permissionGiven = true
+ showDialog = false
} else {
- this.setResult(OSBARCError.CAMERA_PERMISSION_DENIED_ERROR.code)
- this.finish()
+ permissionGiven = false
+ showDialog = true
}
}
SideEffect {
- requestPermissionLauncher.launch(Manifest.permission.CAMERA)
+ if (permissionRequestCount == 0) {
+ permissionRequestCount++
+ requestPermissionLauncher.launch(Manifest.permission.CAMERA)
+ }
+ }
+
+ 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"
+ )
}
// rest of the UI
val cameraProviderFuture = remember {
ProcessCameraProvider.getInstance(context)
}
- var barcode by remember {
- mutableStateOf("")
- }
Column (
modifier = Modifier.fillMaxSize()
@@ -117,9 +152,8 @@ class OSBARCScannerActivity : ComponentActivity() {
parameters.androidScanningLibrary ?: "",
OSBARCZXingHelper(),
OSBARCMLKitHelper()
- ), // temporary
+ ),
{ result ->
- barcode = result
val resultIntent = Intent()
resultIntent.putExtra(SCAN_RESULT, result)
setResult(SCAN_SUCCESS_RESULT_CODE, resultIntent)
@@ -150,4 +184,11 @@ class OSBARCScannerActivity : ComponentActivity() {
}
}
+ private fun hasCameraPermission(context: Context): Boolean {
+ return ContextCompat.checkSelfPermission(
+ context,
+ Manifest.permission.CAMERA
+ ) == PackageManager.PERMISSION_GRANTED
+ }
+
}
\ No newline at end of file