ADD : Scan BarCode working - method to add book ToAdd

scan-20-10
Lou BRODA 1 year ago
parent a480a564ad
commit 37cd46dee8

@ -13,12 +13,12 @@
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<cv:CameraView BarCodeDetectionEnabled="True"
<cv:CameraView x:Name="cameraView"
BarCodeDetectionEnabled="True"
Camera="{Binding ScanVM.Camera}"
Cameras="{Binding ScanVM.Cameras}"
NumCamerasDetected="{Binding ScanVM.CamerasCount}"
AutoStartPreview="{Binding ScanVM.AutoStartPreview}"
AutoStartRecording="{Binding ScanVM.AutoStartRecording}"
BarCodeResults="{Binding ScanVM.BarCodeResult}"
WidthRequest="300"
HeightRequest="200">
<cv:CameraView.Behaviors>
@ -28,7 +28,7 @@
Command="{Binding ScanVM.CamerasLoadCommand}"/>
</cv:CameraView.Behaviors>
</cv:CameraView>
</Grid>
</Grid>
<Grid Margin="2"
Grid.Row="1">
@ -44,13 +44,6 @@
TextColor="{StaticResource Blue100Accent}"
Grid.Column="0"/>
<Button Text="Start Camera"
Command="{Binding ScanVM.StartCameraCommand}"
Grid.Column="2"/>
<Button Text="Start Record"
Command="{Binding ScanVM.StartRecordingCommand}"/>
<Label Text="{Binding ScanVM.BarcodeText}"
TextColor="{StaticResource Blue100Accent}"
Grid.Column="4"/>

@ -16,6 +16,7 @@ public partial class ScanView : ContentPage
{
ScanVM = scanVM;
InitializeComponent();
ScanVM.CameraView = cameraView;
BindingContext = this;
}

@ -8,6 +8,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels;
using ZXing;
namespace LivreLand.ViewModel
{
@ -15,26 +16,40 @@ namespace LivreLand.ViewModel
{
#region Fields
private CameraView cameraView;
private CameraInfo camera = null;
private ObservableCollection<CameraInfo> cameras = new();
private int camerasCount;
private Result[] result;
private string barcodeText = "ISBN";
#endregion
#region Properties
public CameraView CameraView
{
get => cameraView;
set
{
if (cameraView != value)
{
cameraView = value;
OnPropertyChanged(nameof(CameraView));
}
}
}
public CameraInfo Camera
{
get => camera;
set
{
camera = value;
OnPropertyChanged(nameof(Camera));
AutoStartPreview = false;
OnPropertyChanged(nameof(AutoStartPreview));
AutoStartPreview = true;
OnPropertyChanged(nameof(AutoStartPreview));
if (camera != value)
{
camera = value;
OnPropertyChanged(nameof(Camera));
}
}
}
@ -63,6 +78,19 @@ namespace LivreLand.ViewModel
}
}
public Result[] BarCodeResult
{
get => result;
set
{
if (result != value)
{
result = value;
OnPropertyChanged(nameof(BarCodeResult));
}
}
}
public string BarcodeText
{
get => barcodeText;
@ -84,12 +112,10 @@ namespace LivreLand.ViewModel
public ManagerVM Manager { get; private set; }
public ICommand StartCameraCommand { get; private set; }
public ICommand CamerasLoadCommand { get; private set; }
public ICommand BarcodeDetectCommand { get; private set; }
public ICommand StartRecordingCommand { get; private set; }
#endregion
#region Constructor
@ -98,30 +124,33 @@ namespace LivreLand.ViewModel
{
Navigator = navigatorVM;
Manager = managerVM;
StartCameraCommand = new RelayCommand(() => StartCamera());
CamerasLoadCommand = new RelayCommand(() => CamerasLoad());
BarcodeDetectCommand = new RelayCommand(() => BarcodeDetect());
StartRecordingCommand = new RelayCommand(() => StartRecording());
}
#endregion
#region Methods
private async Task StartCamera()
private async Task CamerasLoad()
{
AutoStartPreview = true;
OnPropertyChanged(nameof(AutoStartPreview));
if (Cameras.Count > 0)
{
Camera = Cameras.First();
MainThread.BeginInvokeOnMainThread(async () =>
{
await CameraView.StopCameraAsync();
await CameraView.StartCameraAsync();
});
}
}
private async Task BarcodeDetect()
{
}
private async Task StartRecording()
{
AutoStartRecording = true;
OnPropertyChanged(nameof(AutoStartRecording));
MainThread.BeginInvokeOnMainThread(() =>
{
BarcodeText = BarCodeResult[0].Text;
});
}
#endregion

Loading…
Cancel
Save