1using System.Collections.ObjectModel;
2using System.ComponentModel;
3using CommunityToolkit.Mvvm.ComponentModel;
4using CommunityToolkit.Mvvm.Input;
15 private readonly ScanQrCodeNavigationArgs? navigationArgs;
16 private IDispatcherTimer? countDownTimer;
24 this.navigationArgs = Args;
25 if (this.navigationArgs is not
null &&
26 this.navigationArgs.AllowedSchemas is not
null &&
27 this.navigationArgs.AllowedSchemas.Length > 0 &&
28 this.Icons.Count == 0)
30 foreach (
string Schema
in this.navigationArgs.AllowedSchemas)
72 if (this.Icons.Count == 0)
80 await base.OnInitialize();
82 LocalizationManager.Current.PropertyChanged += this.LocalizationManagerEventHandler;
86 this.countDownTimer =
App.
Current.Dispatcher.CreateTimer();
87 this.countDownTimer.Interval = TimeSpan.FromMilliseconds(500);
88 this.countDownTimer.Tick += this.CountDownEventHandler;
95 LocalizationManager.Current.PropertyChanged -= this.LocalizationManagerEventHandler;
97 if (this.countDownTimer is not
null)
99 this.countDownTimer.Stop();
100 this.countDownTimer.Tick -= this.CountDownEventHandler;
101 this.countDownTimer =
null;
104 if (this.navigationArgs?.QrCodeScanned is TaskCompletionSource<string> TaskSource)
105 TaskSource.TrySetResult(
string.Empty);
107 await base.OnDispose();
110 private void CountDownEventHandler(
object? sender, EventArgs e)
112 this.countDownTimer?.Stop();
113 this.OnBackgroundColorChanged();
116 private void OnBackgroundColorChanged()
121 Icon.BackgroundColorChanged();
124 public void LocalizationManagerEventHandler(
object? sender, PropertyChangedEventArgs e)
129 public Task DoSwitchMode(
bool IsAutomaticScan)
131 this.IsAutomaticScan = IsAutomaticScan;
132 return Task.CompletedTask;
135 public Task SetScannedText(
string? ScannedText)
137 this.ScannedText = ScannedText ??
string.Empty;
138 this.countDownTimer?.Stop();
139 this.OnBackgroundColorChanged();
141 if (this.CanOpen(ScannedText))
143 return this.TrySetResultAndClosePage(ScannedText!.Trim());
145 this.countDownTimer?.Start();
146 this.OnBackgroundColorChanged();
148 return Task.CompletedTask;
155 private async Task TrySetResultAndClosePage(
string? Url)
157 if (this.navigationArgs?.QrCodeScanned is not
null)
159 TaskCompletionSource<string?> TaskSource = this.navigationArgs.QrCodeScanned;
160 this.navigationArgs.QrCodeScanned =
null;
162 await MainThread.InvokeOnMainThreadAsync(async () =>
167 TaskSource.TrySetResult(Url);
183 [NotifyCanExecuteChangedFor(nameof(OpenUrlCommand))]
184 private string? manualText;
190 private string? scannedText;
196 private bool isAutomaticScan =
true;
201 public bool HasAllowedSchemas => this.navigationArgs?.AllowedSchemas is not
null && this.navigationArgs.AllowedSchemas.Length > 0;
208 [NotifyPropertyChangedFor(nameof(
SingleIcon))]
209 private ObservableCollection<UriSchemaIcon> icons = [];
228 if (
string.IsNullOrEmpty(this.ScannedText))
231 string Url = this.ScannedText.Trim();
233 if ((this.countDownTimer?.IsRunning ??
false) &&
234 (this.navigationArgs?.AllowedSchemas is not
null) &&
235 this.navigationArgs.AllowedSchemas.Length > 0)
237 return this.IsPermittedUrl(Url) ? Colors.White : Colors.LightSalmon;
244 private bool IsPermittedUrl(
string Url)
246 if (this.navigationArgs?.AllowedSchemas is not
null &&
247 System.Uri.TryCreate(Url, UriKind.Absolute, out Uri? Uri))
249 foreach (
string Schema
in this.navigationArgs.AllowedSchemas)
251 if (
string.Equals(Uri.Scheme, Schema, StringComparison.OrdinalIgnoreCase))
266 if (this.navigationArgs?.QrTitle is not
null)
273 private bool CanOpen(
string? Text)
275 string? Url = Text?.Trim();
276 if (
string.IsNullOrEmpty(Url))
279 if (this.navigationArgs?.AllowedSchemas is not
null && this.navigationArgs.AllowedSchemas.Length > 0)
280 return this.IsPermittedUrl(Url);
282 return Url.Length > 0;
298 private Task OpenUrl()
300 return this.TrySetResultAndClosePage(this.ManualText!.Trim());
306 return this.TrySetResultAndClosePage(
null);
The Application class, representing an instance of the Neuro-Access app.
static new? App Current
Gets the current application, type casted to App.
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 IStringLocalizer 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.
override Task GoBack()
Method called when user wants to navigate to the previous screen.
bool CanOpenManual
If the manual code can be opened
bool SingleIcon
If only one icon is shown.
override async Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
string LocalizedQrPageTitle
The localized page title text to display.
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
bool HasAllowedSchemas
If scanning of codes is restricted to a set of allowed schemas.
Color IconBackgroundColor
Background color of displayed icon.
bool CanOpenScanned
If the scanned code can be opened
ScanQrCodeViewModel(ScanQrCodeNavigationArgs? Args)
The view model to bind to when scanning a QR code.
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.