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.OnInitializeAsync();
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.OnDisposeAsync();
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
110 public string LocalizedResendCodeText
114 if ((this.CodeVerification is not
null) && (this.CodeVerification.CountDownSeconds > 0))
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);
A strongly-typed resource class, for looking up localized strings, etc.
static string OnboardingVerifyCodePageDetails
Looks up a localized string similar to Please enter verification code sent to {0}.
static string ResendCode
Looks up a localized string similar to Resend Code.
static string ResendCodeSeconds
Looks up a localized string similar to Resend ({0}).
Base class that references services in the app.
static ILogService LogService
Log service.
static IReportingStringLocalizer 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 OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
VerifyCodeViewModel(VerifyCodeNavigationArgs? Args)
Creates a new instance of the VerifyCodeViewModel class.
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...