Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ContractSelector.cs
1using System;
2using System.Windows.Input;
4using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
11using CommunityToolkit.Mvvm.Input;
12
14{
18 public partial class ContractSelector : VerticalStackLayout
19 {
20 #region Constructor
21
26 {
27 Label TitleLabel = new();
28 TitleLabel.SetBinding(Label.TextProperty, new Binding(nameof(this.TitleLabelText), source: this));
29 TitleLabel.SetBinding(Label.StyleProperty, new Binding(nameof(this.TitleLabelStyle), source: this));
30
31 // Add entry to middle of CompositeInputView
32 CompositeEntry Entry = new();
33 Entry.SetBinding(CompositeEntry.PlaceholderProperty, new Binding(nameof(this.EntryPlaceholderText), source: this));
34 Entry.SetBinding(CompositeEntry.EntryDataProperty, new Binding(nameof(this.EntryData), source: this));
35 Entry.SetBinding(CompositeEntry.IsValidProperty, new Binding(nameof(this.IsValid), source: this));
36 Entry.SetBinding(CompositeEntry.StyleProperty, new Binding(nameof(this.EntryStyle), source: this));
37 Entry.SetBinding(CompositeEntry.LabelTextProperty, new Binding(nameof(this.TopText), source: this));
38 Entry.SetBinding(CompositeEntry.LabelStyleProperty, new Binding(nameof(this.TopTextStyle), source: this));
39
40 ImageButton ScanQrButton = new()
41 {
42 PathData = Geometries.ScanQrIconPath,
44 Command = new AsyncRelayCommand(() => this.ScanQr(Entry))
45 };
46
47 ImageButton OpenButton = new()
48 {
49 PathData = Geometries.VisibilityOnPath,
51 Command = new AsyncRelayCommand(() => this.OpenContract(Entry))
52 };
53
54 TextButton ChooseContractButton = new()
55 {
56 Style = AppStyles.SecondaryButton
57 };
58 // Add in the ctor:
59 ChooseContractButton.SetBinding(TextButton.LabelDataProperty, new Binding(nameof(this.ButtonText), source: this));
60 ChooseContractButton.SetBinding(TextButton.CommandProperty, new Binding(nameof(this.ButtonCommand), source: this));
61
62 Grid ButtonGrid = new Grid()
63 {
64 ColumnDefinitions = new ColumnDefinitionCollection
65 {
66 new ColumnDefinition { Width = GridLength.Auto },
67 new ColumnDefinition { Width = GridLength.Star }
68 },
69 ColumnSpacing = AppStyles.SmallSpacing
70 };
71 ButtonGrid.Add(ScanQrButton, 0, 0);
72 ButtonGrid.Add(ChooseContractButton, 1, 0);
73
74 Entry.RightView = OpenButton;
75 this.Add(TitleLabel);
76 this.Add(Entry);
77 this.Add(ButtonGrid);
78 this.Spacing = AppStyles.SmallSpacing;
79 }
80
81 #endregion
82
83 #region Bindable Properties
84
88 public static readonly BindableProperty TitleLabelTextProperty = BindableProperty.Create(nameof(TitleLabelText), typeof(string), typeof(ContractSelector), string.Empty);
89
90 public string TitleLabelText
91 {
92 get => (string)this.GetValue(TitleLabelTextProperty);
93 set => this.SetValue(TitleLabelTextProperty, value);
94 }
95
99 public static readonly BindableProperty TitleLabelStyleProperty = BindableProperty.Create(nameof(TitleLabelStyle), typeof(Style), typeof(ContractSelector), null);
100
101 public Style TitleLabelStyle
102 {
103 get => (Style)this.GetValue(TitleLabelStyleProperty);
104 set => this.SetValue(TitleLabelStyleProperty, value);
105 }
106
110 public static readonly BindableProperty EntryStyleProperty = BindableProperty.Create(nameof(EntryStyle), typeof(Style), typeof(ContractSelector), null);
111 public Style EntryStyle
112 {
113 get => (Style)this.GetValue(EntryStyleProperty);
114 set => this.SetValue(EntryStyleProperty, value);
115 }
116
120 public static readonly BindableProperty TopTextProperty = BindableProperty.Create(nameof(TopText), typeof(string), typeof(ContractSelector), string.Empty);
121
122 public string TopText
123 {
124 get => (string)this.GetValue(TopTextProperty);
125 set => this.SetValue(TopTextProperty, value);
126 }
127
131 public static readonly BindableProperty TopTextStyleProperty = BindableProperty.Create(nameof(TopTextStyle), typeof(Style), typeof(ContractSelector), null);
132
133 public Style TopTextStyle
134 {
135 get => (Style)this.GetValue(TopTextStyleProperty);
136 set => this.SetValue(TopTextStyleProperty, value);
137 }
138
142 public static readonly BindableProperty EntryDataProperty = BindableProperty.Create(nameof(EntryData), typeof(string), typeof(ContractSelector), string.Empty);
143
144 public string EntryData
145 {
146 get => (string)this.GetValue(EntryDataProperty);
147 set => this.SetValue(EntryDataProperty, value);
148 }
149
153 public static readonly BindableProperty EntryPlaceholderTextProperty = BindableProperty.Create(nameof(EntryPlaceholderText), typeof(string), typeof(ContractSelector), string.Empty);
154
155 public string EntryPlaceholderText
156 {
157 get => (string)this.GetValue(EntryPlaceholderTextProperty);
158 set => this.SetValue(EntryPlaceholderTextProperty, value);
159 }
160
164 public static readonly BindableProperty IsValidProperty = BindableProperty.Create(nameof(IsValid), typeof(bool), typeof(ContractSelector), true);
165
166 public bool IsValid
167 {
168 get => (bool)this.GetValue(IsValidProperty);
169 set => this.SetValue(IsValidProperty, value);
170 }
171
175 public static readonly BindableProperty ButtonTextProperty = BindableProperty.Create(nameof(ButtonText), typeof(string), typeof(ContractSelector), string.Empty);
176
177 public string ButtonText
178 {
179 get => (string)this.GetValue(ButtonTextProperty);
180 set => this.SetValue(ButtonTextProperty, value);
181 }
182
186 public static readonly BindableProperty ButtonStyleProperty = BindableProperty.Create(nameof(ButtonStyle), typeof(Style), typeof(ContractSelector), null);
187
188 public Style ButtonStyle
189 {
190 get => (Style)this.GetValue(ButtonStyleProperty);
191 set => this.SetValue(ButtonStyleProperty, value);
192 }
193
197 public static readonly BindableProperty ButtonCommandProperty = BindableProperty.Create(nameof(ButtonCommand), typeof(ICommand), typeof(ContractSelector), null);
198
199 public ICommand ButtonCommand
200 {
201 get => (ICommand)this.GetValue(ButtonCommandProperty);
202 set => this.SetValue(ButtonCommandProperty, value);
203 }
204
205 #endregion
206
207 #region Commands
208
212 [RelayCommand]
213 public async Task ScanQr(CompositeEntry Entry)
214 {
215 string[] AllowedSchemas = [Constants.UriSchemes.IotSc];
216
217 try
218 {
219 string Url = await QrCode.ScanQrCode(nameof(AppResources.QrScanCode), AllowedSchemas) ?? string.Empty;
220 if (string.IsNullOrEmpty(Url))
221 return;
222
223 MainThread.BeginInvokeOnMainThread(() =>
224 {
225 Entry.EntryData = Url;
226 });
227 }
228 catch (Exception Ex)
229 {
230 ServiceRef.LogService.LogException(Ex);
231 }
232 }
233
234
235 public async Task OpenContract(CompositeEntry Entry)
236 {
237 if (string.IsNullOrEmpty(Entry.EntryData))
238 {
239 return;
240 }
241 try
242 {
244 }
245 catch (Exception Ex)
246 {
247 ServiceRef.LogService.LogException(Ex);
248 }
249 }
250 #endregion
251 }
252}
const string IotSc
The IoT Smart Contract URI Scheme (iotsc)
Definition: Constants.cs:163
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
A strongly-typed resource class, for looking up localized strings, etc.
static string QrScanCode
Looks up a localized string similar to Scan QR code.
static string RequestToAccessContract
Looks up a localized string similar to Request to access contract.
Base class that references services in the app.
Definition: ServiceRef.cs:43
static ILogService LogService
Log service.
Definition: ServiceRef.cs:214
static IContractOrchestratorService ContractOrchestratorService
Contract orchestrator service.
Definition: ServiceRef.cs:238
static IReportingStringLocalizer Localizer
Localization service
Definition: ServiceRef.cs:370
Helper class to perform scanning of QR Codes by displaying the UI and handling async results.
Definition: QrCode.cs:20
static async Task< string?> ScanQrCode(string? QrTitle, string[] AllowedSchemas)
Navigates to the Scan QR Code Page, waits for scan to complete, and returns the result....
Definition: QrCode.cs:191
Static class that gives access to app-specific styles
Definition: AppStyles.cs:12
static Style SecondaryImageButton
Style for secondary image buttons.
Definition: AppStyles.cs:373
A customizable entry control that allows setting views on the left and right sides of the entry.
string EntryData
Gets or sets the text displayed in the entry.
static readonly BindableProperty EntryDataProperty
Bindable property for the text displayed in the entry.
static readonly BindableProperty PlaceholderProperty
Bindable property for the placeholder text displayed when the entry is empty.
static readonly BindableProperty LabelStyleProperty
Bindable property for the style applied to the label above the entry.
A custom control for selecting a contract
static readonly BindableProperty TitleLabelTextProperty
Bindable property for the title label text.
ContractSelector()
Constructor for the ContractSelector.
static readonly BindableProperty ButtonStyleProperty
Bindable Property for the select contract button style.
static readonly BindableProperty EntryDataProperty
Bindable Property for the contract id entry data.
static readonly BindableProperty IsValidProperty
Bindable Property for the contract id entry isvalid.
async Task ScanQr(CompositeEntry Entry)
Command that opens the ScanQrPage. And gets the url from the QR code.
static readonly BindableProperty ButtonCommandProperty
Bindable Property for the select contract button command.
static readonly BindableProperty TopTextProperty
Bindable Property for the contract id entry top label text.
static readonly BindableProperty TitleLabelStyleProperty
Bindable Property for the title label style.
static readonly BindableProperty EntryPlaceholderTextProperty
Bindable Property for the contract id entry placeholder text.
static readonly BindableProperty TopTextStyleProperty
Bindable Property for the contract id entry top label style.
static readonly BindableProperty EntryStyleProperty
Bindable Property for the contract id entry style.
static readonly BindableProperty ButtonTextProperty
Bindable Property for the select contract button text.
static readonly BindableProperty CommandProperty
The backing store for the Command bindable property.
static readonly BindableProperty LabelDataProperty
Bindable property for LabelData.
Definition: TextButton.cs:14
Static class containing SVG Paths for symbols used in the app.
Definition: Geometries.cs:11
static readonly Geometry ScanQrIconPath
Scan QR code button icon
Definition: Geometries.cs:132