forked from bolav/fuse-foreignhelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListDict.uno
140 lines (121 loc) · 3.57 KB
/
ListDict.uno
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using Fuse;
using Fuse.Scripting;
using Fuse.Reactive;
using Uno.IO;
using Uno.Compiler.ExportTargetInterop;
namespace Bolav.ForeignHelpers {
public class JSList : ForeignList {
Context ctx;
Fuse.Scripting.Array array;
int pos = 0;
public JSList (Context c) {
ctx = c;
array = (Fuse.Scripting.Array)ctx.Evaluate("(no file)", "new Array()");
}
public override ForeignDict NewDictRow () {
var r = new JSDict(ctx);
array[pos] = r.GetScriptingObject();
pos++;
return r;
}
public Fuse.Scripting.Array GetScriptingArray () {
return array;
}
[Foreign(Language.ObjC)]
extern(iOS) public void FromiOS (ObjC.Object ary)
@{
for(id obj in ary) {
if ([obj isKindOfClass:[NSDictionary class]]) {
id<UnoObject> ddict = @{JSList:Of(_this).NewDictRow():Call()};
@{JSDict:Of(ddict).FromiOS(ObjC.Object):Call(obj)};
}
else {
NSLog(@"Unhandled class JSList.FromiOS: %@", NSStringFromClass([obj class]));
}
}
@}
[Foreign(Language.Java)]
extern(Android) public void FromJava (Java.Object ary)
@{
java.util.List l = (java.util.List)ary;
for (Object obj : l) {
if (obj instanceof java.util.HashMap) {
UnoObject ddict = @{JSList:Of(_this).NewDictRow():Call()};
@{JSDict:Of(ddict).FromJava(Java.Object):Call(obj)};
}
else {
debug_log("Unhandled class JSList.FromJava: " + obj);
}
}
@}
}
public class JSDict : ForeignDict {
Context ctx;
Fuse.Scripting.Object obj;
public JSDict (Context c) {
ctx = c;
obj = ctx.NewObject();
}
public Fuse.Scripting.Object GetScriptingObject () {
return obj;
}
[Foreign(Language.ObjC)]
extern(iOS) public void FromiOS (ObjC.Object dict)
@{
for(id key in dict) {
::id value = [dict objectForKey:key];
// NSLog(@"key=%@ value=%@", key, [dict objectForKey:key]);
if ([value isKindOfClass:[NSString class]]) {
@{JSDict:Of(_this).SetKeyVal(string, string):Call(key, value)};
}
else if ([value isKindOfClass:[NSDictionary class]]) {
id<UnoObject> ddict = @{JSDict:Of(_this).AddDictForKey(string):Call(key)};
@{JSDict:Of(ddict).FromiOS(ObjC.Object):Call(value)};
}
else {
NSLog(@"Unhandled class JSDict.FromiOS: %@", NSStringFromClass([value class]));
}
}
@}
[Foreign(Language.Java)]
extern(Android) public void FromJava (Java.Object dict)
@{
java.util.HashMap map = (java.util.HashMap)dict;
for (Object key : map.keySet()) {
String key_s = key.toString();
Object value = map.get(key_s);
if (value instanceof String) {
@{JSDict:Of(_this).SetKeyVal(string, string):Call(key_s, value.toString())};
}
else {
debug_log("Unhandled class JSDict.FromJava: " + value);
}
}
@}
public override void SetKeyVal (string key, string val) {
obj[key] = val;
}
public override ForeignList AddListForKey (string key) {
var list = new JSList(ctx);
obj[key] = list.GetScriptingArray();
return list;
}
public override ForeignDict AddDictForKey (string key) {
var dict = new JSDict(ctx);
obj[key] = dict.GetScriptingObject();
return dict;
}
}
public abstract class ListDict {
public abstract void NewRowSetActive();
public abstract void SetRow_Column(string key, string val);
}
public abstract class ForeignList {
public abstract ForeignDict NewDictRow();
}
public abstract class ForeignDict {
public abstract ForeignList AddListForKey(string key);
public abstract ForeignDict AddDictForKey (string key);
public abstract void SetKeyVal(string key, string val);
}
}