| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using CommunityToolkit.Mvvm.ComponentModel;
- using CommunityToolkit.Mvvm.Input;
- using InABox.Avalonia.Platform.Barcodes;
- using Microsoft.Maui.Devices;
- using PRS.Avalonia.Modules;
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- namespace PRS.Avalonia.Components;
- public partial class ScannerViewModel : ModuleViewModel
- {
- public override string Title => "Equipment Scanner";
- [ObservableProperty]
- private bool _cameraEnabled;
- [ObservableProperty]
- private bool _processing;
- [ObservableProperty]
- private Func<IReadOnlySet<BarcodeResult>, Task<bool>>? _itemScanned;
- public ScannerViewModel()
- {
- }
- protected override Task OnActivated()
- {
- CameraEnabled = true;
- return base.OnActivated();
- }
- protected override Task OnDeactivated()
- {
- CameraEnabled = false;
- return base.OnDeactivated();
- }
- [RelayCommand]
- private async Task DetectionFinished(IReadOnlySet<BarcodeResult> result)
- {
- if(result.Count > 0)
- {
- if (Processing || !CameraEnabled) return;
- Processing = true;
- if(ItemScanned != null)
- {
- if(await ItemScanned.Invoke(result))
- {
- CameraEnabled = false;
- }
- }
- Processing = false;
- }
- }
- }
|