Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RegistrationViewModel.cs
1using System.Collections.ObjectModel;
2using System.ComponentModel;
3using CommunityToolkit.Mvvm.ComponentModel;
4using CommunityToolkit.Mvvm.Input;
5using Mopups.Services;
10
12{
13 public partial class RegistrationViewModel : BaseViewModel
14 {
16 {
17 }
18
20 protected override async Task OnInitialize()
21 {
22 await base.OnInitialize();
23
24 LocalizationManager.Current.PropertyChanged += this.LocalizationManagerEventHandler;
25 ServiceRef.TagProfile.StepChanged += this.TagProfile_StepChanged;
26 }
27
29 protected override async Task OnDispose()
30 {
31 LocalizationManager.Current.PropertyChanged -= this.LocalizationManagerEventHandler;
32 ServiceRef.TagProfile.StepChanged -= this.TagProfile_StepChanged;
33
34 await base.OnDispose();
35 }
36
41 public void SetPagesContainer(List<BaseRegistrationView> Items)
42 {
43 foreach (BaseRegistrationView Item in Items)
44 {
45 BaseRegistrationViewModel ViewModel = (BaseRegistrationViewModel)Item.BindingContext;
46 this.registrationSteps[ViewModel.Step] = this.AddChildViewModel(ViewModel);
47 };
48 }
49
50 public Task DoAssignProperties(RegistrationStep Step)
51 {
52 this.CurrentStep = Step;
53 return this.registrationSteps[Step].DoAssignProperties();
54 }
55
59 [ObservableProperty]
60 [NotifyPropertyChangedFor(nameof(CanGoToPrev))]
61 [NotifyCanExecuteChangedFor(nameof(GoToPrevCommand))]
62 RegistrationStep currentStep = RegistrationStep.Complete;
63
67 private readonly SortedDictionary<RegistrationStep, BaseRegistrationViewModel> registrationSteps = [];
68
69 [ObservableProperty]
70 private ObservableCollection<LanguageInfo> languages = new(App.SupportedLanguages);
71
72 [ObservableProperty]
73 private LanguageInfo selectedLanguage = App.SelectedLanguage;
74
75 public void LocalizationManagerEventHandler(object? sender, PropertyChangedEventArgs e)
76 {
77 this.SelectedLanguage = App.SelectedLanguage;
78 }
79
80 private void TagProfile_StepChanged(object? Sender, EventArgs e)
81 {
82 this.GoToPrevCommand.NotifyCanExecuteChanged();
83 }
84
85 public bool CanGoToPrev
86 {
87 get
88 {
90 {
91
92 case RegistrationStep.ValidatePhone:
93 case RegistrationStep.ValidateEmail:
94 return string.IsNullOrEmpty(ServiceRef.TagProfile.Account); // Disable the back button if account is already created
95 case RegistrationStep.NameEntry:
96 case RegistrationStep.ChooseProvider:
97 case RegistrationStep.ContactSupport:
98 return true;
99 case RegistrationStep.GetStarted:
100 case RegistrationStep.CreateAccount:
101 case RegistrationStep.DefinePassword:
102 case RegistrationStep.Complete:
103 case RegistrationStep.Biometrics:
104 case RegistrationStep.Finalize:
105 default:
106 return false;
107
108
109 }
110 }
111 }
112
116 [RelayCommand(CanExecute = nameof(CanGoToPrev))]
117 private async Task GoToPrev()
118 {
119 try
120 {
121 await this.registrationSteps[this.CurrentStep].DoClearProperties();
122
124 switch (this.CurrentStep)
125 {
126 case RegistrationStep.NameEntry:
127 NewStep = RegistrationStep.GetStarted;
128 break;
129 case RegistrationStep.ValidatePhone:
130 NewStep = RegistrationStep.GetStarted;
131 break;
132 case RegistrationStep.ValidateEmail:
133 NewStep = RegistrationStep.GetStarted;
134 break;
135 case RegistrationStep.ChooseProvider:
136 NewStep = RegistrationStep.GetStarted;
137 break;
138 case RegistrationStep.ContactSupport:
139 NewStep = RegistrationStep.GetStarted;
140 break;
141
142 default: // Should not happen. Something forgotten?
143 throw new NotImplementedException();
144 }
145 ServiceRef.PlatformSpecific.HideKeyboard();
146
147 GoToRegistrationStep(NewStep);
148 }
149 catch (Exception ex)
150 {
151 await ServiceRef.UiService.DisplayException(ex);
152 }
153 }
154
155 [RelayCommand]
156 private static async Task ChangeLanguage()
157 {
158 await ServiceRef.UiService.PushAsync<SelectLanguagePopup>();
159 }
160 }
161}
The Application class, representing an instance of the Neuro-Access app.
Definition: App.xaml.cs:69
static LanguageInfo SelectedLanguage
Selected language.
Definition: App.xaml.cs:196
static readonly LanguageInfo[] SupportedLanguages
Supported languages.
Definition: App.xaml.cs:176
Base class that references services in the app.
Definition: ServiceRef.cs:31
static IUiService UiService
Service serializing and managing UI-related tasks.
Definition: ServiceRef.cs:55
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:79
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
static void GoToRegistrationStep(RegistrationStep NewStep)
Set a new registration step
A base class view for all registration steps views.
override async Task OnDispose()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
void SetPagesContainer(List< BaseRegistrationView > Items)
Adds sub-views
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
RegistrationStep Step
This profile's current registration step.
Definition: ITagProfile.cs:161
string? Account
The account name for this profile
Definition: ITagProfile.cs:101
RegistrationStep
The different steps of a TAG Profile registration journey.