Skip to content

Commit 00d92b4

Browse files
Vetle444Vetle Finstad
andauthored
Remove BarcodeScanner duplicate scan suppression (#903)
Co-authored-by: Vetle Finstad <finstad@Vetles-MacBook-Pro-2.local>
1 parent c01a0f8 commit 00d92b4

7 files changed

Lines changed: 6 additions & 82 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [61.0.0]
2+
- [BarcodeScanner] **BREAKING**: Removed `BarcodeScannerStartOptions.DuplicateScanCooldown`. Repeated scans of the same barcode are no longer suppressed after the scanner resumes.
3+
14
## [60.5.0]
25
- Resources was updated from DIPS.Mobile.DesignTokens
36

src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/BarcodeScanner.cs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ namespace DIPS.Mobile.UI.API.Camera.BarcodeScanning;
77

88
public partial class BarcodeScanner : ICameraUseCase
99
{
10-
private const int CooldownTimeout = 500;
11-
1210
// Session lifecycle
1311
private BarcodeScannerStartOptions m_currentStartOptions = new();
1412
private BarcodeScanSession? m_scanSession;
@@ -18,11 +16,8 @@ public partial class BarcodeScanner : ICameraUseCase
1816
private bool m_isDisposed;
1917
private bool m_isPlatformStarted;
2018

21-
// Detection pipeline & cooldown
19+
// Detection pipeline
2220
private readonly BarcodeDetectionAggregator m_detectionAggregator = new();
23-
private readonly HashSet<string> m_confirmedBarcodeValues = new(StringComparer.Ordinal);
24-
private bool m_isCoolingDown;
25-
private Timer? m_cooldownTimer;
2621
private CancellationTokenSource? m_automaticHintCts;
2722
private bool m_hasCompletedAutomaticHint;
2823

@@ -70,9 +65,7 @@ public async Task Start(BarcodeScannerStartOptions startOptions)
7065
m_confirmationHandler?.Dispose();
7166
m_confirmationHandler = null;
7267
ResetScanState();
73-
DisposeCooldownTimer();
7468
m_hasCompletedAutomaticHint = false;
75-
m_confirmedBarcodeValues.Clear();
7669

7770
m_scanSession?.Dispose();
7871
m_scanSession = new BarcodeScanSession(m_currentStartOptions, StopPlatformIfNeededAsync);
@@ -182,9 +175,7 @@ public void PauseScanning(bool resetOverlay = true)
182175
EndCurrentScanRun();
183176
m_scanSession?.PauseScanning();
184177
ResetBarcodeConfirmationState(resetOverlay);
185-
DisposeCooldownTimer();
186178
StopAutomaticHint();
187-
m_confirmedBarcodeValues.Clear();
188179
}
189180
catch (Exception e)
190181
{
@@ -205,8 +196,6 @@ public void ResumeScanning()
205196
BeginNewScanRun();
206197
ResetScanState();
207198
m_confirmationHandler?.Reset();
208-
DisposeCooldownTimer();
209-
m_confirmedBarcodeValues.Clear();
210199
m_scanSession?.ResumeScanning();
211200
RestartAutomaticHintTimer();
212201
}
@@ -237,7 +226,6 @@ private void StopScanningCore(bool resetOverlay)
237226
EndCurrentScanRun();
238227
StopPlatformIfNeeded();
239228
ResetBarcodeConfirmationState(resetOverlay);
240-
DisposeCooldownTimer();
241229
StopAutomaticHint();
242230
m_confirmationHandler?.Dispose();
243231
m_confirmationHandler = null;
@@ -267,15 +255,6 @@ internal void InvokeBarcodeFound(Barcode barcode, RectF? overlayBounds = null, i
267255

268256
StopAutomaticHint();
269257

270-
if (m_confirmedBarcodeValues.Contains(barcodeKey))
271-
{
272-
m_confirmationHandler?.OnConfirmedBarcodeRedetected();
273-
return;
274-
}
275-
276-
if (m_isCoolingDown)
277-
return;
278-
279258
m_detectionAggregator.AddObservation(barcode);
280259

281260
m_confirmationHandler?.OnBarcodeDetected(overlayBounds);
@@ -319,11 +298,6 @@ private void ReportMostDetectedBarcode(int scanRunId)
319298
}
320299

321300
Log($"The most detected bar code: {mostDetectedBarcodeObservation.Barcode}");
322-
foreach (var obs in orderedObservations)
323-
{
324-
m_confirmedBarcodeValues.Add(BarcodeDetectionAggregator.GetBarcodeKey(obs.Barcode));
325-
}
326-
327301
ResetBarcodeConfirmationState(resetOverlay: false);
328302

329303
var barcodeScanResult = new BarcodeScanResult(mostDetectedBarcodeObservation.Barcode,
@@ -375,42 +349,11 @@ private void OnBarcodeLostByHandler()
375349
if (!IsSessionActive)
376350
return;
377351

378-
m_confirmedBarcodeValues.Clear();
379352
ResetScanState();
380353
m_scanRectangleOverlay?.ResetBarcodeDetection();
381354
RestartAutomaticHintTimer();
382355
}
383356

384-
private void StartCooldown()
385-
{
386-
m_isCoolingDown = true;
387-
m_cooldownTimer?.Dispose();
388-
var scanRunId = CurrentScanRunId;
389-
m_cooldownTimer = new Timer(_ => MainThread.BeginInvokeOnMainThread(() => FinishCooldown(scanRunId)),
390-
null, (int)Math.Max(m_currentStartOptions.DuplicateScanCooldown.TotalMilliseconds, CooldownTimeout), Timeout.Infinite);
391-
}
392-
393-
private void FinishCooldown(int scanRunId)
394-
{
395-
if (scanRunId != CurrentScanRunId)
396-
return;
397-
398-
m_isCoolingDown = false;
399-
if (m_scanRectangleOverlay is null)
400-
{
401-
m_confirmedBarcodeValues.Clear();
402-
}
403-
m_cooldownTimer?.Dispose();
404-
m_cooldownTimer = null;
405-
}
406-
407-
private void DisposeCooldownTimer()
408-
{
409-
m_cooldownTimer?.Dispose();
410-
m_cooldownTimer = null;
411-
m_isCoolingDown = false;
412-
}
413-
414357
private void RestartAutomaticHintTimer()
415358
{
416359
StopAutomaticHint();
@@ -553,7 +496,6 @@ private void ResumeScanningAfterAnimation()
553496
if (!CanResumeSession)
554497
return;
555498

556-
StartCooldown();
557499
m_scanSession?.ResumeScanning();
558500
RestartAutomaticHintTimer();
559501
}

src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/BarcodeScannerStartOptions.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,4 @@ public class BarcodeScannerStartOptions
5050
/// Gets or sets automatic hint options for scan rectangle barcode scanner sessions.
5151
/// </summary>
5252
public BarcodeScannerHintOptions Hint { get; set; } = new();
53-
54-
/// <summary>
55-
/// Gets or sets the cooldown applied after a scan has been accepted or rejected.
56-
/// </summary>
57-
public TimeSpan DuplicateScanCooldown { get; set; } = TimeSpan.FromMilliseconds(800);
5853
}

src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/IBarcodeConfirmationHandler.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@ namespace DIPS.Mobile.UI.API.Camera.BarcodeScanning;
88
internal interface IBarcodeConfirmationHandler : IDisposable
99
{
1010
/// <summary>
11-
/// Called when a new (unconfirmed, non-cooldown) barcode observation has been recorded.
11+
/// Called when a barcode observation has been recorded.
1212
/// </summary>
1313
void OnBarcodeDetected(RectF? overlayBounds);
1414

15-
/// <summary>
16-
/// Called when an already-confirmed barcode is detected again.
17-
/// Keeps the overlay barcode-lost timer alive in overlay mode; no-op in timer mode.
18-
/// </summary>
19-
void OnConfirmedBarcodeRedetected();
20-
2115
/// <summary>
2216
/// Resets transient tracking state (e.g. bracket animation flags) without disposing timers.
2317
/// </summary>

src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/OverlayBarcodeConfirmationHandler.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ public void OnBarcodeDetected(RectF? overlayBounds)
7777
}
7878
}
7979

80-
public void OnConfirmedBarcodeRedetected()
81-
{
82-
ResetBarcodeLostTimer();
83-
}
84-
8580
public void ResetTrackingState()
8681
{
8782
m_isTrackingBarcode = false;

src/library/DIPS.Mobile.UI/API/Camera/BarcodeScanning/TimerBarcodeConfirmationHandler.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ public void OnBarcodeDetected(RectF? overlayBounds)
3636
null, m_detectionTime, Timeout.InfiniteTimeSpan);
3737
}
3838

39-
public void OnConfirmedBarcodeRedetected()
40-
{
41-
// No barcode-lost tracking in timer mode.
42-
}
43-
4439
public void ResetTrackingState()
4540
{
4641
// No transient tracking state in timer mode.

wiki/Media/Camera.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected override void OnAppearing()
7171
> Notice that `CameraPreview` is the code behind reference from the preview guide.
7272
7373
## Validate barcodes before accepting them
74-
Use `ValidateBarcodeAsync` when the scanner should ask your app whether a detected barcode belongs in the current workflow before playing the success animation. If validation returns invalid, the scanner plays the failure animation, does not increment the progress counter, and resumes scanning after a short cooldown.
74+
Use `ValidateBarcodeAsync` when the scanner should ask your app whether a detected barcode belongs in the current workflow before playing the success animation. If validation returns invalid, the scanner plays the failure animation, does not increment the progress counter, and then resumes scanning. Repeated scans of the same barcode are processed like any other scan; reject already-scanned values in `ValidateBarcodeAsync` when your workflow needs that behavior.
7575

7676
```csharp
7777
private readonly BarcodeScanner m_scanner = new();

0 commit comments

Comments
 (0)