1using System.ComponentModel;
2using System.Globalization;
3using CommunityToolkit.Mvvm.ComponentModel;
4using CommunityToolkit.Mvvm.Input;
25 await base.OnInitialize();
27 LocalizationManager.Current.PropertyChanged += this.LocalizationManagerEventHandler;
31 this.CountDownTimer =
App.
Current.Dispatcher.CreateTimer();
32 this.CountDownTimer.Interval = TimeSpan.FromMilliseconds(1000);
33 this.CountDownTimer.Tick += this.CountDownEventHandler;
40 LocalizationManager.Current.PropertyChanged -= this.LocalizationManagerEventHandler;
42 if (this.CountDownTimer is not
null)
44 this.CountDownTimer.Stop();
45 this.CountDownTimer.Tick -= this.CountDownEventHandler;
46 this.CountDownTimer =
null;
49 await base.OnDispose();
55 await base.DoAssignProperties();
60 this.SendCodeCommand.NotifyCanExecuteChanged();
64 protected override void OnPropertyChanged(PropertyChangedEventArgs e)
66 base.OnPropertyChanged(e);
68 if (e.PropertyName == nameof(this.IsBusy))
69 this.SendCodeCommand.NotifyCanExecuteChanged();
72 public void LocalizationManagerEventHandler(
object? sender, PropertyChangedEventArgs e)
74 this.OnPropertyChanged(nameof(this.LocalizedSendCodeText));
75 this.OnPropertyChanged(nameof(this.LocalizedValidationError));
79 [NotifyCanExecuteChangedFor(nameof(SendCodeCommand))]
80 [NotifyPropertyChangedFor(nameof(LocalizedValidationError))]
84 [NotifyPropertyChangedFor(nameof(LocalizedSendCodeText))]
85 [NotifyCanExecuteChangedFor(nameof(SendCodeCommand))]
86 [NotifyCanExecuteChangedFor(nameof(ResendCodeCommand))]
87 private int countDownSeconds;
90 private IDispatcherTimer? countDownTimer;
92 public string LocalizedSendCodeText
96 if (this.CountDownSeconds > 0)
103 public string LocalizedValidationError
107 if (!this.EmailIsValid)
118 private string emailText =
string.Empty;
120 public bool CanSendCode => this.EmailIsValid && !this.IsBusy &&
121 (this.EmailText.Length > 0) && (this.CountDownSeconds <= 0);
123 public bool CanResendCode => this.CountDownSeconds <= 0;
125 [RelayCommand(CanExecute = nameof(CanSendCode))]
126 private async Task SendCode()
142 new Dictionary<string, object>()
144 {
"EMail", this.EmailText },
145 {
"AppName", Constants.Application.Name },
146 {
"Language", CultureInfo.CurrentCulture.TwoLetterISOLanguageName }
147 },
new KeyValuePair<string, string>(
"Accept",
"application/json"));
150 if (SendResult is Dictionary<string, object> SendResponse &&
151 SendResponse.TryGetValue(
"Status", out
object? Obj) && Obj is
bool SendStatus && SendStatus)
155 VerifyCodeNavigationArgs
NavigationArgs =
new(
this, this.EmailText);
159 if (!
string.IsNullOrEmpty(Code))
163 new Dictionary<string, object>()
165 {
"EMail", this.EmailText },
166 {
"Code",
int.Parse(Code, NumberStyles.None, CultureInfo.InvariantCulture) }
167 },
new KeyValuePair<string, string>(
"Accept",
"application/json"));
170 if (VerifyResult is Dictionary<string, object> VerifyResponse &&
171 VerifyResponse.TryGetValue(
"Status", out Obj) && Obj is
bool VerifyStatus && VerifyStatus)
173 ServiceRef.TagProfile.EMail = this.EmailText;
209 [RelayCommand(CanExecute = nameof(CanResendCode))]
210 private async Task ResendCode()
224 new Dictionary<string, object>()
226 {
"EMail", this.EmailText },
227 {
"AppName", Constants.Application.Name },
228 {
"Language", CultureInfo.CurrentCulture.TwoLetterISOLanguageName }
229 },
new KeyValuePair<string, string>(
"Accept",
"application/json"));
231 if (SendResult is Dictionary<string, object> SendResponse &&
232 SendResponse.TryGetValue(
"Status", out
object? Obj) && Obj is
bool SendStatus && SendStatus)
253 private void StartTimer()
255 if (this.CountDownTimer is not
null)
257 this.CountDownSeconds = 30;
259 if (!this.CountDownTimer.IsRunning)
260 this.CountDownTimer.Start();
264 private void CountDownEventHandler(
object? sender, EventArgs e)
266 if (this.CountDownTimer is not
null)
268 if (this.CountDownSeconds > 0)
269 this.CountDownSeconds--;
271 this.CountDownTimer.Stop();
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 IdDomain
Neuro-Access domain.
A set of never changing property constants and helpful values.
Base class that references services in the app.
static ILogService LogService
Log service.
static INetworkService NetworkService
Network service.
static IUiService UiService
Service serializing and managing UI-related tasks.
static ITagProfile TagProfile
TAG Profile service.
static IStringLocalizer Localizer
Localization service
An base class holding page specific navigation parameters.
override async Task OnInitialize()
override async Task OnDispose()
override async Task DoAssignProperties()
Static class managing encoding and decoding of internet content.
static Task< object > PostAsync(Uri Uri, object Data, params KeyValuePair< string, string >[] Headers)
Posts to a resource, using a Uniform Resource Identifier (or Locator).
string? Account
The account name for this profile
string? EMail
Verified e-mail address.
Task GoToAsync(string Route, BackMethod BackMethod=BackMethod.Inherited, string? UniqueId=null)
Navigates the AppShell to the specified route, with page arguments to match.
Task< bool > DisplayAlert(string Title, string Message, string? Accept=null, string? Cancel=null)
Displays an alert/message box to the user.
RegistrationStep
The different steps of a TAG Profile registration journey.
BackMethod
Navigation Back Method