Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
TransferIdentityViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2using CommunityToolkit.Mvvm.Input;
6
8{
12 public partial class TransferIdentityViewModel : QrXmppViewModel, IDisposable
13 {
14 private bool isDisposed;
15 private Timer? timer;
16
21 public TransferIdentityViewModel(TransferIdentityNavigationArgs? Args)
22 : base()
23 {
24 if (Args is not null)
25 this.Uri = Args.Uri;
26 }
27
29 protected override async Task OnInitialize()
30 {
31 await base.OnInitialize();
32
33 if (this.Uri is not null)
34 {
35 this.QrCodeWidth = 400;
36 this.QrCodeHeight = 400;
37 this.GenerateQrCode(this.Uri);
38 }
39
40 this.timer = new Timer(this.Timeout, null, 60000, 60000);
41 }
42
43 private void Timeout(object? _)
44 {
45 this.timer?.Dispose();
46 this.timer = null;
47
48 MainThread.BeginInvokeOnMainThread(async () =>
49 {
50 await this.GoBack();
51 });
52 }
53
55 protected override Task OnDispose()
56 {
57 this.timer?.Dispose();
58 this.timer = null;
59
60 return base.OnDispose();
61 }
62
63 #region Properties
64
68 [ObservableProperty]
69 private string? uri;
70
71 #endregion
72
73 [RelayCommand]
74 private async Task CopyUriToClipboard()
75 {
76 await Clipboard.SetTextAsync(this.Uri);
77
78 await ServiceRef.UiService.DisplayAlert(
79 ServiceRef.Localizer[nameof(AppResources.SuccessTitle)],
80 ServiceRef.Localizer[nameof(AppResources.TagValueCopiedToClipboard)]);
81 }
82
83 #region ILinkableView
84
88 public override Task<string> Title => Task.FromResult(ContactInfo.GetFriendlyName(ServiceRef.TagProfile.LegalIdentity!));
89
90 #endregion
91
95 public void Dispose()
96 {
97 this.Dispose(true);
98 GC.SuppressFinalize(this);
99 }
100
104 protected virtual void Dispose(bool disposing)
105 {
106 if (this.isDisposed)
107 return;
108
109 if (disposing)
110 {
111 this.timer?.Dispose();
112 this.timer = null;
113 }
114
115 this.isDisposed = true;
116 }
117 }
118}
Contains information about a contact.
Definition: ContactInfo.cs:21
static async Task< string > GetFriendlyName(CaseInsensitiveString RemoteId)
Gets the friendly name of a remote identity (Legal ID or Bare JID).
Definition: ContactInfo.cs:257
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
static IStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:235
virtual async Task GoBack()
Method called when user wants to navigate to the previous screen.
override 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 ...
TransferIdentityViewModel(TransferIdentityNavigationArgs? Args)
Creates an instance of the TransferIdentityViewModel class.
A view model that holds the XMPP state.
void GenerateQrCode(string Uri)
Generates a QR-code