diff --git a/LivreLand/View/ScanView.xaml b/LivreLand/View/ScanView.xaml
index 0ea1198..e5519f1 100644
--- a/LivreLand/View/ScanView.xaml
+++ b/LivreLand/View/ScanView.xaml
@@ -13,12 +13,12 @@
-
@@ -28,7 +28,7 @@
Command="{Binding ScanVM.CamerasLoadCommand}"/>
-
+
@@ -44,13 +44,6 @@
TextColor="{StaticResource Blue100Accent}"
Grid.Column="0"/>
-
-
-
-
diff --git a/LivreLand/View/ScanView.xaml.cs b/LivreLand/View/ScanView.xaml.cs
index cd8b3aa..fd22222 100644
--- a/LivreLand/View/ScanView.xaml.cs
+++ b/LivreLand/View/ScanView.xaml.cs
@@ -16,6 +16,7 @@ public partial class ScanView : ContentPage
{
ScanVM = scanVM;
InitializeComponent();
+ ScanVM.CameraView = cameraView;
BindingContext = this;
}
diff --git a/LivreLand/ViewModel/ScanVM.cs b/LivreLand/ViewModel/ScanVM.cs
index 7e43475..e2b0ebe 100644
--- a/LivreLand/ViewModel/ScanVM.cs
+++ b/LivreLand/ViewModel/ScanVM.cs
@@ -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 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