Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
XmppViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
6
8{
12 public partial class XmppViewModel : BaseViewModel
13 {
17 protected XmppViewModel()
18 : base()
19 {
20 this.StateSummaryText = ServiceRef.Localizer[nameof(AppResources.XmppState_Offline)];
21 this.ConnectionStateText = ServiceRef.Localizer[nameof(AppResources.XmppState_Offline)];
22 this.ConnectionStateColor = new SolidColorBrush(Colors.Red);
23 this.StateSummaryText = string.Empty;
25 }
26
27
29 public override async Task OnInitializeAsync()
30 {
31 await base.OnInitializeAsync();
32
33 ServiceRef.XmppService.ConnectionStateChanged += this.XmppService_ConnectionStateChanged;
34 }
35
37 public override async Task OnDisposeAsync()
38 {
39 ServiceRef.XmppService.ConnectionStateChanged -= this.XmppService_ConnectionStateChanged;
40 await base.OnDisposeAsync();
41 }
42
43 #region Properties
44
48 [ObservableProperty]
49 private string connectionStateText;
50
54 [ObservableProperty]
55 private Brush connectionStateColor;
56
60 [ObservableProperty]
61 private string stateSummaryText;
62
66 [ObservableProperty]
67 private bool isConnected;
68
69 #endregion
70
75 protected virtual void SetConnectionStateAndText(XmppState State)
76 {
77 this.ConnectionStateText = State.ToDisplayText();
78 this.ConnectionStateColor = new SolidColorBrush(State.ToColor());
79 this.IsConnected = State == XmppState.Connected;
80 this.StateSummaryText = (ServiceRef.TagProfile.LegalIdentity?.State)?.ToString() + " - " + this.ConnectionStateText;
81 }
82
88 protected virtual Task XmppService_ConnectionStateChanged(object? _, XmppState NewState)
89 {
90 return MainThread.InvokeOnMainThreadAsync(() =>
91 {
92 this.SetConnectionStateAndText(NewState);
93 });
94 }
95 }
96}
A strongly-typed resource class, for looking up localized strings, etc.
static string XmppState_Offline
Looks up a localized string similar to Disconnected.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:202
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:190
A base class for all view models, inheriting from the BindableObject. NOTE: using this class requir...
A view model that holds the XMPP state.
XmppViewModel()
Creates an instance of a XmppViewModel.
virtual void SetConnectionStateAndText(XmppState State)
Sets both the connection state and connection text to the appropriate value.
override async Task OnDisposeAsync()
Method called when the view is disposed, and will not be used more. Use this method to unregister eve...
virtual Task XmppService_ConnectionStateChanged(object? _, XmppState NewState)
Listens to connection state changes from the XMPP server.
override async Task OnInitializeAsync()
Method called when view is initialized for the first time. Use this method to implement registration ...
Definition: ImplTypes.g.cs:58
XmppState
State of XMPP connection.
Definition: XmppState.cs:7