Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
QrXmppViewModel.cs
1using CommunityToolkit.Mvvm.ComponentModel;
2
4{
8 public abstract partial class QrXmppViewModel : XmppViewModel, ILinkableView
9 {
13 protected QrXmppViewModel()
14 : base()
15 {
16 }
17
22 public void GenerateQrCode(string Uri)
23 {
24 if (this.QrCodeWidth == 0 || this.QrCodeHeight == 0)
25 {
26 this.QrCodeWidth = Constants.QrCode.DefaultImageWidth;
27 this.QrCodeHeight = Constants.QrCode.DefaultImageHeight;
28 }
29
30 if (this.QrResolutionScale == 0)
31 this.QrResolutionScale = Constants.QrCode.DefaultResolutionScale;
32
33 byte[] Bin = Services.UI.QR.QrCode.GeneratePng(Uri, this.QrCodeWidth * this.QrResolutionScale, this.QrCodeHeight * this.QrResolutionScale);
34 this.QrCode = ImageSource.FromStream(() => new MemoryStream(Bin));
35 this.QrCodeBin = Bin;
36 this.QrCodeContentType = Constants.MimeTypes.Png;
37 this.QrCodeUri = Uri;
38 this.HasQrCode = true;
39 }
40
44 public void RemoveQrCode()
45 {
46 this.QrCode = null;
47 this.QrCodeBin = null;
48 this.QrCodeContentType = null;
49 this.QrCodeUri = null;
50 this.HasQrCode = false;
51 }
52
53 #region Properties
54
58 [ObservableProperty]
59 private ImageSource? qrCode;
60
64 [ObservableProperty]
65 private bool hasQrCode;
66
70 [ObservableProperty]
71 private string? qrCodeUri;
72
76 [ObservableProperty]
77 private int qrCodeWidth;
78
82 [ObservableProperty]
83 private int qrCodeHeight;
84
90 [ObservableProperty]
91 private int qrResolutionScale;
92
96 [ObservableProperty]
97 private byte[]? qrCodeBin;
98
102 [ObservableProperty]
103 private string? qrCodeContentType;
104
105
106
107 #endregion
108
109 #region ILinkableView
110
114 public virtual bool IsLinkable => this.HasQrCode;
115
119 public virtual bool EncodeAppLinks => true;
120
124 public virtual string? Link => this.QrCodeUri;
125
129 public abstract Task<string> Title { get; }
130
134 public virtual bool HasMedia => this.HasQrCode;
135
139 public virtual byte[]? Media => this.QrCodeBin;
140
144 public virtual string? MediaContentType => this.QrCodeContentType;
145
146 #endregion
147 }
148}
const string Png
The PNG MIME type.
Definition: Constants.cs:242
const int DefaultImageHeight
The default height to use when generating QR Code images.
Definition: Constants.cs:866
const int DefaultImageWidth
The default width to use when generating QR Code images.
Definition: Constants.cs:862
const int DefaultResolutionScale
The default scale factor to apply to the QR Code image resolution.
Definition: Constants.cs:870
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
A view model that holds the XMPP state.
virtual bool HasMedia
If linkable view has media associated with link.
virtual ? string Link
Link to the current view
QrXmppViewModel()
Creates an instance of a XmppViewModel.
virtual bool IsLinkable
If the current view is linkable.
virtual ? string MediaContentType
Content-Type of associated media.
abstract Task< string > Title
Title of the current view
void RemoveQrCode()
Removes the QR-code
void GenerateQrCode(string Uri)
Generates a QR-code
virtual ? byte[] Media
Encoded media, if available.
virtual bool EncodeAppLinks
If App links should be encoded with the link.
A view model that holds the XMPP state.
Interface for linkable views.
Definition: ILinkableView.cs:7