mirror of
https://gitlab.com/fabinfra/fabaccess/borepin.git
synced 2025-03-12 14:51:44 +01:00
Improved QR Code scanning
This commit is contained in:
commit
0600b97837
@ -47,7 +47,8 @@ namespace Borepin
|
||||
containerRegistry.RegisterForNavigation<MachineListPage, MachineListPageModel>();
|
||||
containerRegistry.RegisterForNavigation<ServerListPage, ServerListPageModel>();
|
||||
containerRegistry.RegisterForNavigation<ServerPage, ServerPageModel>();
|
||||
containerRegistry.RegisterForNavigation<ScanPage, ScanPageModel>();
|
||||
containerRegistry.RegisterForNavigation<ScanPage, ScanPageModel>("ScanPage");
|
||||
containerRegistry.RegisterForNavigation<ScanPage, ScanURNPageModel>("ScanURNPage");
|
||||
#endregion
|
||||
|
||||
#region Register Sequence Navigation
|
||||
|
@ -38,7 +38,7 @@ namespace Borepin.Model
|
||||
Manager = null;
|
||||
}
|
||||
|
||||
if(_Machine.Manage != null)
|
||||
if(!((ManageInterface_Proxy)_Machine.Manage).IsNull)
|
||||
{
|
||||
MachineInfoExtended machineInfoExtended = await _Machine.Manage.GetMachineInfoExtended().ConfigureAwait(false);
|
||||
if (machineInfoExtended.CurrentUser.Just == null)
|
||||
@ -51,7 +51,7 @@ namespace Borepin.Model
|
||||
CurrentUser.LoadData();
|
||||
}
|
||||
|
||||
if (machineInfoExtended.LastUser.Just == null)
|
||||
if (machineInfoExtended.LastUser .Just== null)
|
||||
{
|
||||
LastUser = null;
|
||||
}
|
||||
@ -68,11 +68,11 @@ namespace Borepin.Model
|
||||
}
|
||||
|
||||
CanUse = !((UseInterface_Proxy)_Machine.Use).IsNull;
|
||||
CanInUse = !((InUseInterface_Proxy) _Machine.Inuse).IsNull;
|
||||
CanTakeOver = !((TakeoverInterface_Proxy) _Machine.Takeover).IsNull;
|
||||
CanCheck = !((CheckInterface_Proxy) _Machine.Check).IsNull;
|
||||
CanManage = !((ManageInterface_Proxy) _Machine.Manage).IsNull;
|
||||
CanAdmin = !((AdminInterface_Proxy) _Machine.Admin).IsNull;
|
||||
CanInUse = !((InUseInterface_Proxy)_Machine.Inuse).IsNull;
|
||||
CanTakeOver = !((TakeoverInterface_Proxy)_Machine.Takeover).IsNull;
|
||||
CanCheck = !((CheckInterface_Proxy)_Machine.Check).IsNull;
|
||||
CanManage = !((ManageInterface_Proxy)_Machine.Manage).IsNull;
|
||||
CanAdmin = !((AdminInterface_Proxy)_Machine.Admin).IsNull;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
<Button Text="Scan QR-Code" Command="{Binding ScanCodeCommand}" Style="{StaticResource Style_Button_Primary}">
|
||||
<Button.IsVisible>
|
||||
<OnPlatform x:TypeArguments="x:Boolean"
|
||||
iOS="False"
|
||||
iOS="True"
|
||||
Android="True"/>
|
||||
</Button.IsVisible>
|
||||
</Button>
|
||||
|
@ -5,7 +5,7 @@
|
||||
x:Class="Borepin.Page.ScanPage">
|
||||
<ContentPage.Content>
|
||||
<StackLayout IsVisible="{Binding IsVisible}">
|
||||
<zxing:ZXingScannerView Result="{Binding ScanResult, Mode=TwoWay}" ScanResultCommand="{Binding ScannedCommand}" IsScanning="{Binding IsScanning}" WidthRequest="300" HeightRequest="500" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand"/>
|
||||
<zxing:ZXingScannerView Result="{Binding ScanResult, Mode=TwoWay}" ScanResultCommand="{Binding ScannedCommand}" IsScanning="{Binding IsScanning}" WidthRequest="300" HeightRequest="500" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Options="{Binding ScanOptions}"/>
|
||||
<Button Text="Abort" Command="{Binding AbortCommand}"/>
|
||||
</StackLayout>
|
||||
</ContentPage.Content>
|
||||
|
@ -8,7 +8,6 @@ using Borepin.Service.BFFH;
|
||||
using Borepin.Base;
|
||||
using FabAccessAPI.Schema;
|
||||
using Prism.Services;
|
||||
using Prism.AppModel;
|
||||
using static FabAccessAPI.Schema.Machine;
|
||||
using System;
|
||||
using NaturalSort.Extension;
|
||||
@ -16,7 +15,7 @@ using System.Linq;
|
||||
|
||||
namespace Borepin.PageModel
|
||||
{
|
||||
public class MachineListPageModel : ConnectionModelBase, IPageLifecycleAware
|
||||
public class MachineListPageModel : ConnectionModelBase
|
||||
{
|
||||
#region Private Fields
|
||||
private Machine _NextMachine;
|
||||
@ -198,24 +197,6 @@ namespace Borepin.PageModel
|
||||
{
|
||||
IsBusy = true;
|
||||
|
||||
if (parameters["result"] != null)
|
||||
{
|
||||
if (parameters["result"].Equals("scanned"))
|
||||
{
|
||||
string urn = (string)parameters["value"];
|
||||
ScanCode_Result(urn);
|
||||
|
||||
NavigationParameters parameters2 = new NavigationParameters
|
||||
{
|
||||
{ "id", _NextMachine.Id},
|
||||
};
|
||||
|
||||
_NextMachine = null;
|
||||
|
||||
await _NavigationService.NavigateAsync("MachinePage", parameters2).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
await LoadData().ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
172
Borepin/Borepin/PageModel/ScanURNPageModel.cs
Normal file
172
Borepin/Borepin/PageModel/ScanURNPageModel.cs
Normal file
@ -0,0 +1,172 @@
|
||||
using Borepin.Base;
|
||||
using Borepin.Service.BFFH;
|
||||
using FabAccessAPI.Schema;
|
||||
using Prism.Commands;
|
||||
using Prism.Navigation;
|
||||
using Prism.Services;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms;
|
||||
using ZXing;
|
||||
using ZXing.Mobile;
|
||||
|
||||
namespace Borepin.PageModel
|
||||
{
|
||||
class ScanURNPageModel : ConnectionModelBase
|
||||
{
|
||||
#region Contructors
|
||||
public ScanURNPageModel(INavigationService navigationService, IPageDialogService pageDialogService, IBFFHService bffhService) : base(navigationService, pageDialogService, bffhService)
|
||||
{
|
||||
AbortCommand = new DelegateCommand(async () => await AbortCommandExecute().ConfigureAwait(true));
|
||||
ScannedCommand = new DelegateCommand(async () => await ScannedCommandExecuteAsync().ConfigureAwait(false));
|
||||
|
||||
IsVisible = true;
|
||||
IsScanning = true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Data
|
||||
public override async Task LoadData()
|
||||
{
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Fields
|
||||
public MobileBarcodeScanningOptions ScanOptions
|
||||
{
|
||||
get
|
||||
{
|
||||
return new MobileBarcodeScanningOptions()
|
||||
{
|
||||
PossibleFormats = new List<BarcodeFormat>()
|
||||
{
|
||||
BarcodeFormat.QR_CODE,
|
||||
BarcodeFormat.EAN_13
|
||||
// TODO add more Barcode Formats if needed
|
||||
}
|
||||
};
|
||||
}
|
||||
//set => SetProperty(ref _ScanOptions, value);
|
||||
}
|
||||
|
||||
private Result _ScanResult;
|
||||
public Result ScanResult
|
||||
{
|
||||
get => _ScanResult;
|
||||
set => SetProperty(ref _ScanResult, value);
|
||||
}
|
||||
|
||||
private bool _IsScanning;
|
||||
public bool IsScanning
|
||||
{
|
||||
get => _IsScanning;
|
||||
set => SetProperty(ref _IsScanning, value);
|
||||
}
|
||||
|
||||
private bool _IsVisible;
|
||||
public bool IsVisible
|
||||
{
|
||||
get => _IsVisible;
|
||||
set => SetProperty(ref _IsVisible, value);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
private ICommand _ScannedCommand;
|
||||
|
||||
public ICommand ScannedCommand
|
||||
{
|
||||
get => _ScannedCommand;
|
||||
set => SetProperty(ref _ScannedCommand, value);
|
||||
}
|
||||
|
||||
public async Task ScannedCommandExecuteAsync()
|
||||
{
|
||||
IsScanning = false;
|
||||
|
||||
// HACK
|
||||
if(string.Equals(ScanResult.Text, "4014472002512", System.StringComparison.Ordinal))
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await _PageDialogService.DisplayAlertAsync("YAY", "It's Bionade", "OK").ConfigureAwait(false);
|
||||
IsScanning = true;
|
||||
});
|
||||
return;
|
||||
}
|
||||
// END HACK
|
||||
|
||||
string id = await QRToID(ScanResult.Text).ConfigureAwait(false);
|
||||
|
||||
if (id != null)
|
||||
{
|
||||
NavigationParameters parameters = new NavigationParameters
|
||||
{
|
||||
{ "id", id },
|
||||
};
|
||||
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
INavigationResult result = await _NavigationService.NavigateAsync("/MainPage/NavigationPage/MachineListPage/MachinePage", parameters).ConfigureAwait(false);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(async () =>
|
||||
{
|
||||
await _PageDialogService.DisplayAlertAsync("Alert", "QR Code is invalid", "OK").ConfigureAwait(false);
|
||||
IsScanning = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<string> QRToID(string value)
|
||||
{
|
||||
if (!_BFFHService.IsConnected)
|
||||
{
|
||||
IsConnected = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
MachineSystem machineSystem = (await _BFFHService.GetSession().ConfigureAwait(false)).MachineSystem;
|
||||
|
||||
Optional<Machine> optional = await machineSystem.Info.GetMachineURN(value).ConfigureAwait(false);
|
||||
|
||||
if (optional.Just == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return optional.Just.Id;
|
||||
}
|
||||
|
||||
private ICommand _AbortCommand;
|
||||
public ICommand AbortCommand
|
||||
{
|
||||
get => _AbortCommand;
|
||||
set => SetProperty(ref _AbortCommand, value);
|
||||
}
|
||||
public async Task AbortCommandExecute()
|
||||
{
|
||||
IsScanning = false;
|
||||
IsVisible = false;
|
||||
|
||||
await _NavigationService.GoBackAsync().ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region INavigationService
|
||||
public override void OnNavigatedFrom(INavigationParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnNavigatedTo(INavigationParameters parameters)
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user