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

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

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

Loading…
Cancel
Save