Philippe Geoffroy

Fix: with the "noDuplicates" detection speed, the same code is no longer detecte…

…d after stopping and restarting the scanner.
Fix: spamming code detection with "noDuplicates" detection speed on iOS.
@@ -70,7 +70,7 @@ class MobileScanner( @@ -70,7 +70,7 @@ class MobileScanner(
70 scanner.process(inputImage) 70 scanner.process(inputImage)
71 .addOnSuccessListener { barcodes -> 71 .addOnSuccessListener { barcodes ->
72 if (detectionSpeed == DetectionSpeed.NO_DUPLICATES) { 72 if (detectionSpeed == DetectionSpeed.NO_DUPLICATES) {
73 - val newScannedBarcodes = barcodes.map { barcode -> barcode.rawValue } 73 + val newScannedBarcodes = barcodes.mapNotNull({ barcode -> barcode.rawValue }).sorted()
74 if (newScannedBarcodes == lastScanned) { 74 if (newScannedBarcodes == lastScanned) {
75 // New scanned is duplicate, returning 75 // New scanned is duplicate, returning
76 return@addOnSuccessListener 76 return@addOnSuccessListener
@@ -224,6 +224,7 @@ class MobileScanner( @@ -224,6 +224,7 @@ class MobileScanner(
224 throw AlreadyStarted() 224 throw AlreadyStarted()
225 } 225 }
226 226
  227 + lastScanned = null
227 scanner = if (barcodeScannerOptions != null) { 228 scanner = if (barcodeScannerOptions != null) {
228 BarcodeScanning.getClient(barcodeScannerOptions) 229 BarcodeScanning.getClient(barcodeScannerOptions)
229 } else { 230 } else {
@@ -117,12 +117,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega @@ -117,12 +117,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
117 imagesCurrentlyBeingProcessed = false 117 imagesCurrentlyBeingProcessed = false
118 118
119 if (detectionSpeed == DetectionSpeed.noDuplicates) { 119 if (detectionSpeed == DetectionSpeed.noDuplicates) {
120 - let newScannedBarcodes = barcodes?.map { barcode in 120 + let newScannedBarcodes = barcodes?.compactMap({ barcode in
121 return barcode.rawValue 121 return barcode.rawValue
122 - } 122 + }).sorted()
  123 +
123 if (error == nil && barcodesString != nil && newScannedBarcodes != nil && barcodesString!.elementsEqual(newScannedBarcodes!)) { 124 if (error == nil && barcodesString != nil && newScannedBarcodes != nil && barcodesString!.elementsEqual(newScannedBarcodes!)) {
124 return 125 return
125 - } else { 126 + } else if (newScannedBarcodes?.isEmpty == false) {
126 barcodesString = newScannedBarcodes 127 barcodesString = newScannedBarcodes
127 } 128 }
128 } 129 }
@@ -139,6 +140,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega @@ -139,6 +140,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
139 throw MobileScannerError.alreadyStarted 140 throw MobileScannerError.alreadyStarted
140 } 141 }
141 142
  143 + barcodesString = nil
142 scanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner() 144 scanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner()
143 captureSession = AVCaptureSession() 145 captureSession = AVCaptureSession()
144 textureId = registry?.register(self) 146 textureId = registry?.register(self)