-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.cs
More file actions
98 lines (84 loc) · 2.66 KB
/
App.cs
File metadata and controls
98 lines (84 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using Xamarin.Forms;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
namespace Formtest
{
public class App
{
public static Page GetMainPage ()
{
Layout l = parseThing ();
return new ContentPage {
Content = l
/*new Label {
Text = "Hello, Forms !",
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
},*/
};
}
private static Layout parseThing() {
WebClient w = new WebClient();
string str = w.DownloadString ("https://noveria.nl/apitest.html");
//string str = {"fields":[{"label":"Maak foto's van het ongeluk","field_type":"photo","required":true,"field_options":{"description":"let vooral op de pinda's"},"cid":"c6"},{"label":"Aard v/h ongeluk","field_type":"text","required":true,"field_options":{"size":"small"},"cid":"c10"},{"label":"Veroorzaker","field_type":"text","required":true,"field_options":{"size":"medium","minlength":"ape","maxlength":"nuts"},"cid":"c17"},{"label":"Handtekening","field_type":"signature","required":true,"field_options":{},"cid":"c2"}]}
var parsed = Newtonsoft.Json.Linq.JObject.Parse (str);
IList<View> childs = new List<View> ();
ListView lv = new ListView ();
foreach(JObject field in parsed["fields"]) {
Label lbl = genLabel (field);
View element = genInput (field);
if (element != null) {
childs.Add (lbl);
childs.Add (element);
}
}
StackLayout layout = new StackLayout {
Children = {}
};
foreach (View vw in childs) {
layout.Children.Add (vw);
}
Button submitButton = new Button {
Text = "Submit"
};
submitButton.Clicked += (sender, EventArgs) => {
List<Object> listo = new List<Object>();
foreach(View gv in childs) {
if(gv is DatePicker)
listo.Add(((DatePicker) gv).Date);
if(gv is Entry)
listo.Add(((Entry) gv).Text);
if(gv is Button)
listo.Add(((Button) gv).Text);
}
string outstring = Newtonsoft.Json.JsonConvert.SerializeObject(listo);
Console.WriteLine(outstring);
};
layout.Children.Add (submitButton);
var v = new ScrollView {
Content = layout
};
return v;
}
static Label genLabel(JObject lal) {
return new Label {
Text = (string)lal ["label"],
BackgroundColor = Color.Blue
};
}
static View genInput(JObject input) {
switch ((string) input ["field_type"]) {
case "photo":
return new DatePicker ();
case "text":
return new Entry ();
case "signature":
return new Button ();
default:
return null;
}
}
}
}