1using System.Collections.ObjectModel;
2using System.ComponentModel;
3using CommunityToolkit.Mvvm.ComponentModel;
4using CommunityToolkit.Mvvm.Input;
16 private readonly ScanQrCodeNavigationArgs? navigationArgs;
17 private IDispatcherTimer? countDownTimer;
18 private bool suppressModeHandler;
27 this.isAutomaticScan =
true;
28 this.isDetecting =
true;
29 if (this.navigationArgs is not
null &&
30 this.navigationArgs.AllowedSchemas is not
null &&
31 this.navigationArgs.AllowedSchemas.Length > 0 &&
32 this.Icons.Count == 0)
34 foreach (
string Schema
in this.navigationArgs.AllowedSchemas)
76 if (this.Icons.Count == 0)
83 private async Task SwitchMode()
86 this.suppressModeHandler =
true;
87 this.IsAutomaticScan = !this.IsAutomaticScan;
88 this.suppressModeHandler =
false;
89 await Task.CompletedTask;
93 private void SwitchCamera()
95 this.CameraLocation = this.CameraLocation == CameraLocation.Rear ? CameraLocation.Front : CameraLocation.Rear;
99 private void SwitchTorch()
101 this.IsTorchOn = !this.IsTorchOn;
104 private static bool CanPickPhoto() =>
false;
106 [RelayCommand(CanExecute = nameof(CanPickPhoto))]
107 private async Task PickPhoto()
111 await Task.CompletedTask;
113 await Task.CompletedTask;
121 await base.OnInitializeAsync();
123 LocalizationManager.Current.PropertyChanged += this.LocalizationManagerEventHandler;
127 this.countDownTimer =
App.
Current.Dispatcher.CreateTimer();
128 this.countDownTimer.Interval = TimeSpan.FromMilliseconds(500);
129 this.countDownTimer.Tick += this.CountDownEventHandler;
136 LocalizationManager.Current.PropertyChanged -= this.LocalizationManagerEventHandler;
138 if (this.countDownTimer is not
null)
140 this.countDownTimer.Stop();
141 this.countDownTimer.Tick -= this.CountDownEventHandler;
142 this.countDownTimer =
null;
145 if (this.navigationArgs?.QrCodeScanned is TaskCompletionSource<string> TaskSource)
146 TaskSource.TrySetResult(
string.Empty);
148 await base.OnDisposeAsync();
151 private void CountDownEventHandler(
object? sender, EventArgs e)
153 this.countDownTimer?.Stop();
154 this.OnBackgroundColorChanged();
157 private void OnBackgroundColorChanged()
162 Icon.BackgroundColorChanged();
165 public void LocalizationManagerEventHandler(
object? sender, PropertyChangedEventArgs e)
170 public Task DoSwitchMode(
bool IsAutomaticScan)
172 this.IsAutomaticScan = IsAutomaticScan;
173 return Task.CompletedTask;
176 public Task SetScannedText(
string? ScannedText)
178 this.ScannedText = ScannedText ??
string.Empty;
179 this.countDownTimer?.Stop();
180 this.OnBackgroundColorChanged();
182 if (this.CanOpen(ScannedText))
184 return this.TrySetResultAndClosePage(ScannedText!.Trim());
186 this.countDownTimer?.Start();
187 this.OnBackgroundColorChanged();
189 return Task.CompletedTask;
196 private async Task TrySetResultAndClosePage(
string? Url)
198 if (this.navigationArgs?.QrCodeScanned is not
null)
200 TaskCompletionSource<string?> TaskSource = this.navigationArgs.QrCodeScanned;
201 this.navigationArgs.QrCodeScanned =
null;
203 await MainThread.InvokeOnMainThreadAsync(async () =>
208 TaskSource.TrySetResult(Url);
224 [NotifyCanExecuteChangedFor(nameof(OpenUrlCommand))]
225 private string? manualText;
231 private string? scannedText;
237 private bool isAutomaticScan =
true;
239 partial
void OnIsAutomaticScanChanged(
bool value)
241 if (!this.suppressModeHandler)
244 this.IsDetecting = value;
252 private bool isDetecting;
258 private bool isTorchOn;
264 private CameraLocation cameraLocation = CameraLocation.Rear;
269 public bool HasAllowedSchemas => this.navigationArgs?.AllowedSchemas is not
null && this.navigationArgs.AllowedSchemas.Length > 0;
276 [NotifyPropertyChangedFor(nameof(
SingleIcon))]
277 private ObservableCollection<UriSchemaIcon> icons = [];
296 if (
string.IsNullOrEmpty(this.ScannedText))
299 string Url = this.ScannedText.Trim();
301 if ((this.countDownTimer?.IsRunning ??
false) &&
302 (this.navigationArgs?.AllowedSchemas is not
null) &&
303 this.navigationArgs.AllowedSchemas.Length > 0)
305 return this.IsPermittedUrl(Url) ? Colors.White : Colors.LightSalmon;
312 private bool IsPermittedUrl(
string Url)
314 if (this.navigationArgs?.AllowedSchemas is not
null &&
315 System.Uri.TryCreate(Url, UriKind.Absolute, out Uri? Uri))
317 foreach (
string Schema
in this.navigationArgs.AllowedSchemas)
319 if (
string.Equals(Uri.Scheme, Schema, StringComparison.OrdinalIgnoreCase))
334 if (this.navigationArgs?.QrTitle is not
null)
341 private bool CanOpen(
string? Text)
343 string? Url = Text?.Trim();
344 if (
string.IsNullOrEmpty(Url))
347 if (this.navigationArgs?.AllowedSchemas is not
null && this.navigationArgs.AllowedSchemas.Length > 0)
348 return this.IsPermittedUrl(Url);
350 return Url.Length > 0;
366 private Task OpenUrl()
368 return this.TrySetResultAndClosePage(this.ManualText!.Trim());
374 return this.TrySetResultAndClosePage(
null);
Represents an instance of the Neuro-Access app.
static new? App Current
Gets the current application instance.
const string TagSign
TAG Signature (Quick-Login) URI Scheme (tagsign)
const string IotSc
The IoT Smart Contract URI Scheme (iotsc)
const string Onboarding
Onboarding URI Scheme (obinfo)
const string NeuroFeature
eDaler URI Scheme (edaler)
const string Aes256
AES-256-encrypted data.
const string IotDisco
The IoT Discovery URI Scheme (iotdisco)
const string Xmpp
XMPP URI Scheme (xmpp)
const string IotId
The IoT ID URI Scheme (iotid)
const string EDaler
eDaler URI Scheme (edaler)
A set of never changing property constants and helpful values.
Base class that references services in the app.
static ILogService LogService
Log service.
static INavigationService NavigationService
The navigation service for navigating between pages.
static IReportingStringLocalizer Localizer
Localization service
Static class containing SVG Paths for symbols used in the app.
static readonly Color UserColor
Default user icon color
static readonly Color EDalerColor
Default eDaler icon color
static readonly Geometry UserIconPath
User symbol for QR codes
static readonly Geometry OnboardingIconPath
Onboarding symbol for QR codes
static readonly Color OnboardingColor
Default onboarding icon color
static readonly Color TokenColor
Default token icon color
static readonly Geometry SignatureIconPath
Signature symbol for QR codes
static readonly Geometry EDalerIconPath
eDaler symbol for QR codes
static readonly Color Aes256Color
Default encrypted icon color
static readonly Color ContractColor
Default contract icon color
static readonly Geometry Aes256IconPath
Encrypted symbol for QR codes
static readonly Geometry ThingsIconPath
Things symbol for QR codes
static readonly Geometry ContractIconPath
Contract symbol for QR codes
static readonly Geometry TokenIconPath
Token symbol for QR codes
static readonly Color ThingsColor
Default things icon color
static readonly Color SignatureColor
Default signature icon color
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
The view model to bind to when scanning a QR code.
ScanQrCodeViewModel()
The view model to bind to when scanning a QR code.
override Task GoBack()
Method called when user wants to navigate to the previous screen.
bool CanOpenManual
If the manual code can be opened
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
bool SingleIcon
If only one icon is shown.
string LocalizedQrPageTitle
The localized page title text to display.
bool HasAllowedSchemas
If scanning of codes is restricted to a set of allowed schemas.
Color IconBackgroundColor
Background color of displayed icon.
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
bool CanOpenScanned
If the scanned code can be opened
bool MultipleIcons
If the view shows more than one icon.
class UriSchemaIcon(Geometry Geometry, Color ForegroundColor, ScanQrCodeViewModel ParentViewModel)
Represents an icon for an URI schema.