Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
BiometricsOnboardingStepViewModel.cs
1using System.ComponentModel;
2using System.Globalization;
3using System.Threading.Tasks;
4using CommunityToolkit.Mvvm.ComponentModel;
5using CommunityToolkit.Mvvm.Input;
6using Microsoft.Maui.Controls.Shapes;
12
14{
16 {
17 private readonly BiometricMethod biometricMethod = ServiceRef.PlatformSpecific.GetBiometricMethod();
18
19 public BiometricsOnboardingStepViewModel() : base(OnboardingStep.Biometrics) { }
20
21 public override async Task OnInitializeAsync()
22 {
23 await base.OnInitializeAsync();
24 LocalizationManager.Current.PropertyChanged += this.Localization_Changed;
25 }
26
27 public override async Task OnDisposeAsync()
28 {
29 LocalizationManager.Current.PropertyChanged -= this.Localization_Changed;
30 await base.OnDisposeAsync();
31 }
32
33 private void Localization_Changed(object? sender, PropertyChangedEventArgs e)
34 {
35 this.OnPropertyChanged(nameof(this.DetailText));
36 this.OnPropertyChanged(nameof(this.WhatIsX));
37 }
38
39 public double AuthenticationBackgroundSize => 120.0;
40
41 public RoundRectangle AuthenticationBackgroundStroke => new RoundRectangle { CornerRadius = this.AuthenticationBackgroundSize / 2 };
42
43 public double AuthenticationIconSize => 60.0;
44
45 public bool IsFingerprint => this.biometricMethod is BiometricMethod.Fingerprint or BiometricMethod.TouchId or BiometricMethod.Unknown;
46
47 public bool IsFace => this.biometricMethod is BiometricMethod.Face or BiometricMethod.FaceId or BiometricMethod.Unknown;
48
49 public string DetailText
50 {
51 get
52 {
53 string methodName = this.biometricMethod switch
54 {
55 BiometricMethod.TouchId => ServiceRef.Localizer[nameof(AppResources.TouchId)],
56 BiometricMethod.FaceId => ServiceRef.Localizer[nameof(AppResources.FaceId)],
57 _ => ServiceRef.Localizer[nameof(AppResources.BiometricAuthentication)].ToString().ToLower(CultureInfo.CurrentUICulture)
58 };
59
61 }
62 }
63
64 public string WhatIsX
65 {
66 get
67 {
68 string subject = this.biometricMethod switch
69 {
70 BiometricMethod.TouchId => ServiceRef.Localizer[nameof(AppResources.TouchId)],
71 BiometricMethod.FaceId => ServiceRef.Localizer[nameof(AppResources.FaceId)],
72 _ => ServiceRef.Localizer[nameof(AppResources.BiometricAuthentication)].ToString().ToLower(CultureInfo.CurrentUICulture)
73 };
74
75 return ServiceRef.Localizer[nameof(AppResources.WhatIsX), subject];
76 }
77 }
78
79 [RelayCommand]
80 private async Task ShowBiometricsInfo()
81 {
82 string message = this.biometricMethod switch
83 {
84 BiometricMethod.FaceId => ServiceRef.Localizer[nameof(AppResources.FaceIdInfo)],
85 BiometricMethod.TouchId => ServiceRef.Localizer[nameof(AppResources.TouchIdInfo)],
87 };
88
89 ShowInfoPopup popup = new(this.WhatIsX, message);
90 await ServiceRef.PopupService.PushAsync(popup);
91 }
92
93 [RelayCommand]
94 private async Task Later()
95 {
96 ServiceRef.TagProfile.AuthenticationMethod = AuthenticationMethod.Password;
97 OnboardingViewModel? Coordinator = this.CoordinatorViewModel;
98 if (Coordinator is not null)
99 {
100 Coordinator.MarkStepCompleted(OnboardingStep.Biometrics);
101 await Coordinator.GoToStepCommand.ExecuteAsync(OnboardingStep.Finalize);
102 }
103 }
104
105 [RelayCommand]
106 private async Task Enable()
107 {
108 ServiceRef.TagProfile.AuthenticationMethod = AuthenticationMethod.Fingerprint;
109 OnboardingViewModel? Coordinator = this.CoordinatorViewModel;
110 if (Coordinator is not null)
111 {
112 Coordinator.MarkStepCompleted(OnboardingStep.Biometrics);
113 await Coordinator.GoToStepCommand.ExecuteAsync(OnboardingStep.Finalize);
114 }
115 }
116 }
117}
A strongly-typed resource class, for looking up localized strings, etc.
static string FaceId
Looks up a localized string similar to Face ID.
static string BiometricAuthentication
Looks up a localized string similar to Biometric authentication.
static string WhatIsX
Looks up a localized string similar to What is {0}?.
static string TouchIdInfo
Looks up a localized string similar to Touch ID uses your fingerprint to ensure it's really you,...
static string BiometricAuthenticationInfo
Looks up a localized string similar to Biometric authentication uses your unique physical features,...
static string FaceIdInfo
Looks up a localized string similar to Face ID recognizes your face to ensure it's really you,...
static string OnboardingBiometricsPageDetails
Looks up a localized string similar to Neuro-Access works best when using {0}. Would you like to enab...
static string TouchId
Looks up a localized string similar to Touch ID.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static IPopupService PopupService
Popup service for presenting application popups.
Definition: ServiceRef.cs:142
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
static IPlatformSpecific PlatformSpecific
Localization service
Definition: ServiceRef.cs:383
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
BiometricMethod GetBiometricMethod()
Gets the biometric method supported by the device.
Definition: ImplTypes.g.cs:58
AuthenticationMethod
How the user authenticates itself with the App.
BiometricMethod
Enum representing the device biometric method for authentication.
OnboardingStep
Unified onboarding steps matching the registration journey.