diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ba96e..8806b8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The changes documented here do not include those from the original repository. +## [2.0.0] + +### 01-09-2025 + +- Feature: Android - provide `hint` and return `format`. + +**BREAKING CHANGES**: The `scanBarcode` now returns an object instead of a string. + ## [1.2.1] ### 20-08-2025 diff --git a/package.json b/package.json index 7c4d225..01c9bee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.outsystems.plugins.barcode", - "version": "1.2.1", + "version": "2.0.0", "description": "Cordova Bridge for the OutSystems Officially Supported Barcode Plugin.", "keywords": [ "ecosystem:cordova", diff --git a/plugin.xml b/plugin.xml index e3328c2..64d8e80 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + OSBarcode Cordova Bridge for the OutSystems Officially Supported Barcode Plugin. OutSystems Inc @@ -26,6 +26,7 @@ + @@ -42,16 +43,16 @@ - - + + - + diff --git a/src/android/com/outsystems/plugins/barcode/OSBarcode.kt b/src/android/com/outsystems/plugins/barcode/OSBarcode.kt index a54ba31..50736d1 100755 --- a/src/android/com/outsystems/plugins/barcode/OSBarcode.kt +++ b/src/android/com/outsystems/plugins/barcode/OSBarcode.kt @@ -2,25 +2,35 @@ package com.outsystems.plugins.barcode import android.content.Intent import com.google.gson.Gson +import com.google.gson.GsonBuilder +import com.google.gson.JsonDeserializationContext +import com.google.gson.JsonDeserializer +import com.google.gson.JsonElement import com.outsystems.plugins.barcode.controller.OSBARCController import com.outsystems.plugins.barcode.model.OSBARCError import com.outsystems.plugins.barcode.model.OSBARCScanParameters +import com.outsystems.plugins.barcode.model.OSBARCScanResult +import com.outsystems.plugins.barcode.model.OSBARCScannerHint import com.outsystems.plugins.oscordova.CordovaImplementation -import kotlinx.coroutines.runBlocking import org.apache.cordova.CallbackContext import org.apache.cordova.CordovaInterface import org.apache.cordova.CordovaWebView import org.json.JSONArray +import org.json.JSONObject +import java.lang.reflect.Type class OSBarcode : CordovaImplementation() { - companion object { private const val ERROR_FORMAT_PREFIX = "OS-PLUG-BARC-" } override var callbackContext: CallbackContext? = null private lateinit var barcodeController: OSBARCController - val gson by lazy { Gson() } + val gson: Gson by lazy { + GsonBuilder() + .registerTypeAdapter(OSBARCScannerHint::class.java, OSBARCScannerHintAdapter()) + .create() + } override fun execute( action: String, @@ -45,8 +55,12 @@ class OSBarcode : CordovaImplementation() { override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) { super.onActivityResult(requestCode, resultCode, intent) barcodeController.handleActivityResult(requestCode, resultCode, intent, - { result -> - sendPluginResult(result, null) + { result: OSBARCScanResult -> + val jsonObject = JSONObject().apply { + put("ScanResult", result.text) + put("format", result.format.ordinal) + } + sendPluginResult(jsonObject, null) }, { error -> sendPluginResult(null, Pair(formatErrorCode(error.code), error.description)) @@ -98,4 +112,16 @@ class OSBarcode : CordovaImplementation() { return ERROR_FORMAT_PREFIX + code.toString().padStart(4, '0') } + private class OSBARCScannerHintAdapter : JsonDeserializer { + override fun deserialize( + json: JsonElement?, + typeOfT: Type?, + context: JsonDeserializationContext? + ): OSBARCScannerHint { + return json?.asInt?.let { + OSBARCScannerHint.entries.getOrNull(it) + } ?: OSBARCScannerHint.UNKNOWN + } + } + } \ No newline at end of file diff --git a/src/android/com/outsystems/plugins/barcode/build.gradle b/src/android/com/outsystems/plugins/barcode/build.gradle index 89e5311..5753792 100644 --- a/src/android/com/outsystems/plugins/barcode/build.gradle +++ b/src/android/com/outsystems/plugins/barcode/build.gradle @@ -26,7 +26,7 @@ repositories{ dependencies { implementation("com.github.outsystems:oscore-android:1.2.0@aar") implementation("com.github.outsystems:oscordova-android:2.0.1@aar") - implementation("io.ionic.libs:ionbarcode-android:1.2.1@aar") + implementation("io.ionic.libs:ionbarcode-android:2.0.0@aar") implementation 'androidx.appcompat:appcompat:1.7.0' implementation "androidx.activity:activity-ktx:1.9.3" diff --git a/src/ios/OSBarcodeScanArgumentsModel.swift b/src/ios/OSBARCScanParameters+Decodable.swift similarity index 61% rename from src/ios/OSBarcodeScanArgumentsModel.swift rename to src/ios/OSBARCScanParameters+Decodable.swift index 2e9bb15..873cbbf 100644 --- a/src/ios/OSBarcodeScanArgumentsModel.swift +++ b/src/ios/OSBARCScanParameters+Decodable.swift @@ -1,10 +1,6 @@ import OSBarcodeLib -struct OSBarcodeScanArgumentsModel: Decodable { - let scanInstructions: String - let scanButtonText: String? - let cameraDirection: OSBARCCameraModel - let scanOrientation: OSBARCOrientationModel +extension OSBARCScanParameters: Decodable { enum CodingKeys: CodingKey { case scanButton @@ -12,9 +8,10 @@ struct OSBarcodeScanArgumentsModel: Decodable { case scanText case cameraDirection case scanOrientation + case hint } - init(from decoder: Decoder) throws { + public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) let scanInstructions = try container.decode(String.self, forKey: .scanInstructions) @@ -31,13 +28,15 @@ struct OSBarcodeScanArgumentsModel: Decodable { let scanOrientationInt = try container.decode(Int.self, forKey: .scanOrientation) let scanOrientation = OSBARCOrientationModel(value: scanOrientationInt) - self.init(scanInstructions, scanButtonText, cameraDirection, scanOrientation) - } - - private init(_ scanInstructions: String, _ scanButtonText: String?, _ cameraDirection: OSBARCCameraModel, _ scanOrientation: OSBARCOrientationModel) { - self.scanInstructions = scanInstructions - self.scanButtonText = scanButtonText - self.cameraDirection = cameraDirection - self.scanOrientation = scanOrientation + let hintInt = try container.decode(Int.self, forKey: .hint) + let hint = OSBARCScannerHint(rawValue: hintInt) + + self.init( + scanInstructions: scanInstructions, + scanButtonText: scanButtonText, + cameraDirection: cameraDirection, + scanOrientation: scanOrientation, + hint: hint + ) } } diff --git a/src/ios/OSBarcode.swift b/src/ios/OSBarcode.swift index 03a6578..ac078a2 100644 --- a/src/ios/OSBarcode.swift +++ b/src/ios/OSBarcode.swift @@ -17,15 +17,15 @@ class OSBarcode: CDVPlugin { guard let argumentsDictionary = command.argument(at: 0) as? [String: Any], let argumentsData = try? JSONSerialization.data(withJSONObject: argumentsDictionary), - let argumentsModel = try? JSONDecoder().decode(OSBarcodeScanArgumentsModel.self, from: argumentsData) + let parameters = try? JSONDecoder().decode(OSBARCScanParameters.self, from: argumentsData) else { return self.send(error: .scanInputArgumentsIssue, for: command.callbackId) } Task { do { - guard let scannedBarcode = try await self.plugin?.scanBarcode(with: argumentsModel.scanInstructions, argumentsModel.scanButtonText, argumentsModel.cameraDirection, and: argumentsModel.scanOrientation) else { + guard let scanResult = try await self.plugin?.scanBarcode(with: parameters) else { return self.send(error: .scanningError, for: command.callbackId) } - self.send(successfulResult: scannedBarcode, for: command.callbackId) + self.send(successfulResult: scanResult, for: command.callbackId) } catch OSBARCManagerError.cameraAccessDenied { self.send(error: .cameraAccessDenied, for: command.callbackId) } catch OSBARCManagerError.scanningCancelled { @@ -37,8 +37,9 @@ class OSBarcode: CDVPlugin { } private extension OSBarcode { - func send(successfulResult: String, for callbackId: String) { - let pluginResult = CDVPluginResult(status: .ok, messageAs: successfulResult) + func send(successfulResult: OSBARCScanResult, for callbackId: String) { + let resultDict: [String : Any] = ["ScanResult": successfulResult.text, "format": successfulResult.format.rawValue] + let pluginResult = CDVPluginResult(status: .ok, messageAs: resultDict) self.commandDelegate.send(pluginResult, callbackId: callbackId) }