ADD : Start Camera Scan implementation

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

@ -15,6 +15,7 @@ public partial class AppShell : Shell
Routing.RegisterRoute("library/date/", typeof(FiltrageDateView));
Routing.RegisterRoute("library/note/", typeof(FiltrageNoteView));
Routing.RegisterRoute("library/contacts/", typeof(ContactsView));
Routing.RegisterRoute("library/scan/", typeof(ScanView));
Routing.RegisterRoute("library/tous/details/", typeof(DetailsLivreView));
InitializeComponent();
}

@ -53,6 +53,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Camera.MAUI" Version="1.4.4" />
<PackageReference Include="CommunityToolkit.Maui" Version="5.3.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>
@ -137,6 +138,9 @@
<MauiXaml Update="View\HeaderPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="View\ScanView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="View\StatutLectureView.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>

@ -1,4 +1,5 @@
using CommunityToolkit.Maui;
using Camera.MAUI;
using CommunityToolkit.Maui;
using LivreLand.View;
using LivreLand.View.ContentViews;
using LivreLand.ViewModel;
@ -17,6 +18,7 @@ public static class MauiProgram
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.UseMauiCameraView()
.ConfigureFonts(fonts =>
{
fonts.AddFont("SF-Compact-Display-Black.otf", "SFCompactDisplayBlack");
@ -35,6 +37,7 @@ public static class MauiProgram
.AddSingleton<FavorisView>()
.AddSingleton<ContactsView>()
.AddSingleton<PopupISBNView>()
.AddSingleton<ScanView>()
.AddSingleton<NavigatorVM>()
@ -54,7 +57,8 @@ public static class MauiProgram
.AddSingleton<EmpruntsPretsVM>()
.AddSingleton<FavorisVM>()
.AddSingleton<ContactsVM>()
.AddSingleton<PopupISBNVM>();
.AddSingleton<PopupISBNVM>()
.AddSingleton<ScanVM>();
#if DEBUG
builder.Logging.AddDebug();

@ -3,4 +3,5 @@
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
</manifest>

@ -26,10 +26,6 @@
Margin="10,5,10,5">
<Label Text="Ajouter un livre"
Style="{StaticResource MasterStateBookText}"/>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Navigator.NavigationCommand}"
CommandParameter="/add"/>
</Grid.GestureRecognizers>
</Grid>
<contentView:SeparatorEntireView Grid.Row="1"/>
@ -52,6 +48,10 @@
<toolkit:IconTintColorBehavior TintColor="{AppThemeBinding Light={StaticResource Black}, Dark={StaticResource White}}"/>
</Image.Behaviors>
</Image>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Navigator.NavigationCommand}"
CommandParameter="/scan"/>
</Grid.GestureRecognizers>
</Grid>
<contentView:SeparatorEntireView Grid.Row="3"/>

@ -351,7 +351,8 @@
HorizontalOptions="Center"
VerticalOptions="Center">
<Picker.Behaviors>
<toolkit:EventToCommandBehavior Command="{Binding DetailsLivreVM.Manager.UpdateStatusBookCommand}"
<toolkit:EventToCommandBehavior EventName="SelectedIndexChanged"
Command="{Binding DetailsLivreVM.Manager.UpdateStatusBookCommand}"
CommandParameter="{Binding DetailsLivreVM.Book}"/>
</Picker.Behaviors>
</Picker>

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:cv="clr-namespace:Camera.MAUI;assembly=Camera.MAUI"
x:Class="LivreLand.View.ScanView"
Title="ScanView">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<cv:CameraView BarCodeDetectionEnabled="True"
Camera="{Binding ScanVM.Camera}"
Cameras="{Binding ScanVM.Cameras}"
NumCamerasDetected="{Binding ScanVM.CamerasCount}"
AutoStartPreview="{Binding ScanVM.AutoStartPreview}"
AutoStartRecording="{Binding ScanVM.AutoStartRecording}"
WidthRequest="300"
HeightRequest="200">
<cv:CameraView.Behaviors>
<toolkit:EventToCommandBehavior EventName="BarcodeDetected"
Command="{Binding ScanVM.BarcodeDetectCommand}"/>
<toolkit:EventToCommandBehavior EventName="CamerasLoaded"
Command="{Binding ScanVM.CamerasLoadCommand}"/>
</cv:CameraView.Behaviors>
</cv:CameraView>
</Grid>
<Grid Margin="2"
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<Label Text="Annuler"
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"/>
</Grid>
</Grid>
</ContentPage>

@ -0,0 +1,23 @@
using LivreLand.ViewModel;
namespace LivreLand.View;
public partial class ScanView : ContentPage
{
#region Properties
public ScanVM ScanVM { get; set; }
#endregion
#region Constructor
public ScanView(ScanVM scanVM)
{
ScanVM = scanVM;
InitializeComponent();
BindingContext = this;
}
#endregion
}

@ -0,0 +1,129 @@
using Camera.MAUI;
using PersonalMVVMToolkit;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using ViewModels;
namespace LivreLand.ViewModel
{
public class ScanVM : BaseViewModel
{
#region Fields
private CameraInfo camera = null;
private ObservableCollection<CameraInfo> cameras = new();
private int camerasCount;
private string barcodeText = "ISBN";
#endregion
#region Properties
public CameraInfo Camera
{
get => camera;
set
{
camera = value;
OnPropertyChanged(nameof(Camera));
AutoStartPreview = false;
OnPropertyChanged(nameof(AutoStartPreview));
AutoStartPreview = true;
OnPropertyChanged(nameof(AutoStartPreview));
}
}
public ObservableCollection<CameraInfo> Cameras
{
get => cameras;
set
{
if (cameras != value)
{
cameras = value;
OnPropertyChanged(nameof(Cameras));
}
}
}
public int CamerasCount
{
get => camerasCount = Cameras.Count();
set
{
if (value > 0)
{
Camera = Cameras.First();
}
}
}
public string BarcodeText
{
get => barcodeText;
set
{
if (barcodeText != value)
{
barcodeText = value;
OnPropertyChanged(nameof(BarcodeText));
}
}
}
public bool AutoStartPreview { get; set; } = false;
public bool AutoStartRecording { get; set; } = false;
public NavigatorVM Navigator { get; private set; }
public ManagerVM Manager { get; private set; }
public ICommand StartCameraCommand { get; private set; }
public ICommand BarcodeDetectCommand { get; private set; }
public ICommand StartRecordingCommand { get; private set; }
#endregion
#region Constructor
public ScanVM(NavigatorVM navigatorVM, ManagerVM managerVM)
{
Navigator = navigatorVM;
Manager = managerVM;
StartCameraCommand = new RelayCommand(() => StartCamera());
BarcodeDetectCommand = new RelayCommand(() => BarcodeDetect());
StartRecordingCommand = new RelayCommand(() => StartRecording());
}
#endregion
#region Methods
private async Task StartCamera()
{
AutoStartPreview = true;
OnPropertyChanged(nameof(AutoStartPreview));
}
private async Task BarcodeDetect()
{
}
private async Task StartRecording()
{
AutoStartRecording = true;
OnPropertyChanged(nameof(AutoStartRecording));
}
#endregion
}
}

@ -485,6 +485,9 @@ namespace ViewModels
var book = await Model.GetBookById(bookVM.Id);
book.Status = SelectedStatus;
await Model.UpdateBook(book);
var updatedBook = new BookVM(book);
bookVM = updatedBook;
OnPropertyChanged(nameof(bookVM));
}
private async Task UpdateToBeReadBook(BookVM bookVM)

Loading…
Cancel
Save