|
5 | 5 | import android.util.Log;
|
6 | 6 |
|
7 | 7 | import com.estimote.proximity_sdk.proximity.EstimoteCloudCredentials;
|
8 |
| -import com.estimote.proximity_sdk.proximity.ProximityAttachment; |
| 8 | +import com.estimote.proximity_sdk.proximity.ProximityContext; |
9 | 9 | import com.estimote.proximity_sdk.proximity.ProximityObserver;
|
10 | 10 | import com.estimote.proximity_sdk.proximity.ProximityObserverBuilder;
|
11 | 11 | import com.estimote.proximity_sdk.proximity.ProximityZone;
|
@@ -91,41 +91,40 @@ public void startObservingZones(ReadableArray zonesJSON) {
|
91 | 91 |
|
92 | 92 | final String _id = zoneJSON.getString("_id");
|
93 | 93 | double range = zoneJSON.getDouble("range");
|
94 |
| - String attachmentKey = zoneJSON.getString("attachmentKey"); |
95 |
| - String attachmentValue = zoneJSON.getString("attachmentValue"); |
| 94 | + String tag = zoneJSON.getString("tag"); |
96 | 95 |
|
97 | 96 | ProximityZone zone = observer.zoneBuilder()
|
98 |
| - .forAttachmentKeyAndValue(attachmentKey, attachmentValue) |
| 97 | + .forTag(tag) |
99 | 98 | .inCustomRange(range)
|
100 |
| - .withOnEnterAction(new Function1<ProximityAttachment, Unit>() { |
| 99 | + .withOnEnterAction(new Function1<ProximityContext, Unit>() { |
101 | 100 | @Override
|
102 |
| - public Unit invoke(ProximityAttachment attachment) { |
103 |
| - Log.i(TAG, "onEnterAction, zoneId = " + _id + ", attachment = " + attachment.toString()); |
| 101 | + public Unit invoke(ProximityContext context) { |
| 102 | + Log.i(TAG, "onEnterAction, zoneId = " + _id + ", context = " + context.toString()); |
104 | 103 | WritableMap map = new WritableNativeMap();
|
105 | 104 | map.putString("zoneId", _id);
|
106 |
| - map.putMap("attachment", attachmentToMap(attachment)); |
| 105 | + map.putMap("context", contextToMap(context)); |
107 | 106 | sendEvent("Enter", map);
|
108 | 107 | return null;
|
109 | 108 | }
|
110 | 109 | })
|
111 |
| - .withOnExitAction(new Function1<ProximityAttachment, Unit>() { |
| 110 | + .withOnExitAction(new Function1<ProximityContext, Unit>() { |
112 | 111 | @Override
|
113 |
| - public Unit invoke(ProximityAttachment attachment) { |
114 |
| - Log.i(TAG, "onExitAction, zoneId = " + _id + ", attachment = " + attachment.toString()); |
| 112 | + public Unit invoke(ProximityContext context) { |
| 113 | + Log.i(TAG, "onExitAction, zoneId = " + _id + ", context = " + context.toString()); |
115 | 114 | WritableMap map = new WritableNativeMap();
|
116 | 115 | map.putString("zoneId", _id);
|
117 |
| - map.putMap("attachment", attachmentToMap(attachment)); |
| 116 | + map.putMap("context", contextToMap(context)); |
118 | 117 | sendEvent("Exit", map);
|
119 | 118 | return null;
|
120 | 119 | }
|
121 | 120 | })
|
122 |
| - .withOnChangeAction(new Function1<List<? extends ProximityAttachment>, Unit>() { |
| 121 | + .withOnChangeAction(new Function1<List<? extends ProximityContext>, Unit>() { |
123 | 122 | @Override
|
124 |
| - public Unit invoke(List<? extends ProximityAttachment> attachments) { |
125 |
| - Log.i(TAG, "onChangeAction, zoneId = " + _id + ", attachments = " + attachments.toString()); |
| 123 | + public Unit invoke(List<? extends ProximityContext> contexts) { |
| 124 | + Log.i(TAG, "onChangeAction, zoneId = " + _id + ", contexts = " + contexts.toString()); |
126 | 125 | WritableMap map = new WritableNativeMap();
|
127 | 126 | map.putString("zoneId", _id);
|
128 |
| - map.putArray("attachments", attachmentsToArray(attachments)); |
| 127 | + map.putArray("contexts", contextsToArray(contexts)); |
129 | 128 | sendEvent("Change", map);
|
130 | 129 | return null;
|
131 | 130 | }
|
@@ -159,25 +158,26 @@ public void onCatalystInstanceDestroy() {
|
159 | 158 |
|
160 | 159 | // serialization helpers
|
161 | 160 |
|
162 |
| - private WritableMap payloadToMap(Map<String, String> payload) { |
| 161 | + private WritableMap attachmentsToMap(Map<String, String> attachments) { |
163 | 162 | WritableMap map = new WritableNativeMap();
|
164 |
| - for (Map.Entry<String, String> entry : payload.entrySet()) { |
| 163 | + for (Map.Entry<String, String> entry : attachments.entrySet()) { |
165 | 164 | map.putString(entry.getKey(), entry.getValue());
|
166 | 165 | }
|
167 | 166 | return map;
|
168 | 167 | }
|
169 | 168 |
|
170 |
| - private WritableMap attachmentToMap(ProximityAttachment attachment) { |
| 169 | + private WritableMap contextToMap(ProximityContext context) { |
171 | 170 | WritableMap map = new WritableNativeMap();
|
172 |
| - map.putString("deviceIdentifier", attachment.getDeviceId()); |
173 |
| - map.putMap("payload", payloadToMap(attachment.getPayload())); |
| 171 | + map.putString("tag", context.getTag()); |
| 172 | + map.putMap("attachments", attachmentsToMap(context.getAttachments())); |
| 173 | + map.putString("deviceIdentifier", context.getInfo().getDeviceId()); |
174 | 174 | return map;
|
175 | 175 | }
|
176 | 176 |
|
177 |
| - private WritableArray attachmentsToArray(List<? extends ProximityAttachment> attachments) { |
| 177 | + private WritableArray contextsToArray(List<? extends ProximityContext> contexts) { |
178 | 178 | WritableArray array = new WritableNativeArray();
|
179 |
| - for (ProximityAttachment attachment : attachments) { |
180 |
| - array.pushMap(attachmentToMap(attachment)); |
| 179 | + for (ProximityContext context : contexts) { |
| 180 | + array.pushMap(contextToMap(context)); |
181 | 181 | }
|
182 | 182 | return array;
|
183 | 183 | }
|
|
0 commit comments