1using System.ComponentModel;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
15 private readonly VerifyCodeNavigationArgs? navigationArgs;
23 this.navigationArgs = Args;
26 this.CodeVerification = Args.CodeVerification;
32 await base.OnInitialize();
34 LocalizationManager.Current.PropertyChanged += this.LocalizationManagerEventHandler;
36 if (this.CodeVerification is not
null)
37 this.CodeVerification.CountDownTimer.Tick += this.CountDownEventHandler;
39 this.LocalizationManagerEventHandler(
null,
new(
null));
45 LocalizationManager.Current.PropertyChanged -= this.LocalizationManagerEventHandler;
47 if (this.CodeVerification is not
null)
48 this.CodeVerification.CountDownTimer.Tick -= this.CountDownEventHandler;
50 if (this.navigationArgs?.VarifyCode is TaskCompletionSource<string> TaskSource)
51 TaskSource.TrySetResult(
string.Empty);
53 await base.OnDispose();
56 public void LocalizationManagerEventHandler(
object? sender, PropertyChangedEventArgs e)
58 this.OnPropertyChanged(nameof(this.LocalizedVerifyCodePageDetails));
59 this.OnPropertyChanged(nameof(this.LocalizedResendCodeText));
62 private void CountDownEventHandler(
object? sender, EventArgs e)
64 this.OnPropertyChanged(nameof(this.LocalizedResendCodeText));
71 private async Task TrySetResultAndClosePage(
string? Url)
73 if (this.navigationArgs?.VarifyCode is not
null)
75 TaskCompletionSource<string?> TaskSource = this.navigationArgs.VarifyCode;
76 this.navigationArgs.VarifyCode =
null;
78 await MainThread.InvokeOnMainThreadAsync(async () =>
83 TaskSource.TrySetResult(Url);
96 private ICodeVerification? codeVerification;
99 [NotifyCanExecuteChangedFor(nameof(VerifyCommand))]
100 private string? verifyCodeText;
102 public string LocalizedVerifyCodePageDetails
106 return ServiceRef.
Localizer[nameof(AppResources.OnboardingVerifyCodePageDetails), this.navigationArgs?.PhoneOrEmail ??
string.Empty];
110 public string LocalizedResendCodeText
114 if ((this.CodeVerification is not
null) && (this.CodeVerification.CountDownSeconds > 0))
115 return ServiceRef.
Localizer[nameof(AppResources.ResendCodeSeconds), this.CodeVerification.CountDownSeconds];
123 public bool CanVerify => !
string.IsNullOrEmpty(this.VerifyCodeText) && (this.VerifyCodeText.Length == 6);
125 [RelayCommand(CanExecute = nameof(CanVerify))]
128 return this.TrySetResultAndClosePage(this.VerifyCodeText);
134 return this.TrySetResultAndClosePage(
string.Empty);
Base class that references services in the app.
static ILogService LogService
Log service.
static IStringLocalizer Localizer
Localization service
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
The view model to bind to when verifying a code.
override Task GoBack()
Method called when user wants to navigate to the previous screen.
override async Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
VerifyCodeViewModel(VerifyCodeNavigationArgs? Args)
Creates a new instance of the VerifyCodeViewModel class.