reactnative-plugin-appice 1.7.25 → 1.7.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/README.md +37 -37
  2. package/android/README.md +14 -14
  3. package/android/build.gradle +158 -158
  4. package/android/gitignore +47 -47
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  6. package/android/gradlew +234 -234
  7. package/android/local.properties +8 -8
  8. package/android/src/main/AndroidManifest.xml +138 -164
  9. package/android/src/main/java/com/reactlibrary/AppICEUtils.java +274 -274
  10. package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +778 -778
  11. package/android/src/main/java/com/reactlibrary/AppIceReactPluginPackage.java +28 -28
  12. package/android/src/main/java/com/reactlibrary/CampaignCampsReceiver.java +56 -56
  13. package/android/src/main/java/com/reactlibrary/EnumConstants.java +282 -282
  14. package/android/src/main/java/com/reactlibrary/NotificationEventService.java +59 -59
  15. package/android/src/main/java/com/reactlibrary/StringConstants.java +24 -24
  16. package/campaign.js +25 -25
  17. package/example/App.js +332 -332
  18. package/example/Gemfile +6 -6
  19. package/example/PageA.tsx +15 -15
  20. package/example/__tests__/App-test.js +14 -14
  21. package/example/ancilliary.js +486 -486
  22. package/example/android/app/_BUCK +55 -55
  23. package/example/android/app/build.gradle +320 -320
  24. package/example/android/app/build_defs.bzl +19 -19
  25. package/example/android/app/proguard-rules.pro +10 -10
  26. package/example/android/app/src/debug/AndroidManifest.xml +13 -13
  27. package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +73 -73
  28. package/example/android/app/src/main/AndroidManifest.xml +72 -72
  29. package/example/android/app/src/main/java/com/example/MainActivity.java +48 -48
  30. package/example/android/app/src/main/java/com/example/MainApplication.java +91 -91
  31. package/example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +116 -116
  32. package/example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +36 -36
  33. package/example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -48
  34. package/example/android/app/src/main/jni/Android.mk +48 -48
  35. package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -24
  36. package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -16
  37. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -45
  38. package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -38
  39. package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -61
  40. package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -32
  41. package/example/android/app/src/main/jni/OnLoad.cpp +11 -11
  42. package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -36
  43. package/example/android/app/src/main/res/values/strings.xml +3 -3
  44. package/example/android/app/src/main/res/values/styles.xml +9 -9
  45. package/example/android/build.gradle +73 -73
  46. package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -5
  47. package/example/android/gradle.properties +40 -40
  48. package/example/android/gradlew +234 -234
  49. package/example/android/settings.gradle +11 -11
  50. package/example/app.json +3 -3
  51. package/example/babel.config.js +3 -3
  52. package/example/index.js +9 -9
  53. package/example/ios/Podfile +44 -44
  54. package/example/ios/Podfile.lock +561 -561
  55. package/example/ios/_xcode.env +11 -11
  56. package/example/ios/example/AppDelegate.h +8 -8
  57. package/example/ios/example/AppDelegate.mm +174 -174
  58. package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -53
  59. package/example/ios/example/Images.xcassets/Contents.json +6 -6
  60. package/example/ios/example/Info.plist +62 -62
  61. package/example/ios/example/LaunchScreen.storyboard +47 -47
  62. package/example/ios/example/example.entitlements +8 -8
  63. package/example/ios/example/main.m +10 -10
  64. package/example/ios/example.xcodeproj/project.pbxproj +712 -712
  65. package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -88
  66. package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -10
  67. package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  68. package/example/ios/exampleTests/Info.plist +24 -24
  69. package/example/ios/exampleTests/exampleTests.m +66 -66
  70. package/example/metro.config.js +17 -17
  71. package/example/package.json +36 -36
  72. package/example/yarn.lock +7176 -7176
  73. package/index.js +590 -590
  74. package/ios/AppICEReactEvent.h +23 -23
  75. package/ios/AppICEReactEvent.m +86 -86
  76. package/ios/AppIceReactPlugin.h +65 -65
  77. package/ios/AppIceReactPlugin.m +683 -683
  78. package/ios/AppIceReactPlugin.xcodeproj/project.pbxproj +364 -364
  79. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
  80. package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  81. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  82. package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  83. package/ios/AppIceReactPlugin.xcworkspace/contents.xcworkspacedata +10 -10
  84. package/ios/AppIceReactPlugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
  85. package/ios/Podfile +10 -10
  86. package/ios/Podfile.lock +3 -3
  87. package/ios/Pods/Manifest.lock +3 -3
  88. package/ios/Pods/Pods.xcodeproj/project.pbxproj +395 -395
  89. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/Pods-AppIceReactPlugin.xcscheme +58 -58
  90. package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +18 -18
  91. package/ios/Pods/Pods.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
  92. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-Info.plist +26 -26
  93. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.markdown +3 -3
  94. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.plist +29 -29
  95. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-dummy.m +5 -5
  96. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-umbrella.h +16 -16
  97. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.debug.xcconfig +6 -6
  98. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.modulemap +6 -6
  99. package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.release.xcconfig +6 -6
  100. package/package.json +42 -42
  101. package/reactnative-plugin-appice.podspec +30 -30
  102. package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
  103. package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
  104. package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
  105. package/example/android/.gradle/7.3.3/gc.properties +0 -0
  106. package/example/android/.gradle/vcs-1/gc.properties +0 -0
@@ -1,779 +1,779 @@
1
- package com.reactlibrary;
2
-
3
- import static com.reactlibrary.AppICEUtils.arrayListStringFromReadableArray;
4
- import static com.reactlibrary.AppICEUtils.eventPropsFromReadableMap;
5
- import static com.reactlibrary.StringConstants.MEDIA_DATA;
6
- import static com.reactlibrary.StringConstants.MEDIA_THUMBNAIL;
7
- import static com.reactlibrary.StringConstants.MEDIA_TYPE;
8
- import static com.reactlibrary.StringConstants.MEDIA_URL;
9
-
10
- import android.content.Context;
11
- import android.content.Intent;
12
- import android.content.pm.PackageManager;
13
- import android.content.pm.ResolveInfo;
14
-
15
- import com.facebook.react.bridge.Arguments;
16
- import com.facebook.react.bridge.Callback;
17
- import com.facebook.react.bridge.ReactApplicationContext;
18
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
- import com.facebook.react.bridge.ReactMethod;
20
- import com.facebook.react.bridge.ReadableMap;
21
-
22
- import android.os.Handler;
23
- import semusi.activitysdk.Api;
24
- import semusi.activitysdk.ContextSdk;
25
- import semusi.activitysdk.SdkConfig;
26
-
27
- import semusi.context.ui.appInbox.AppICEInboxMessage;
28
- import semusi.context.ui.appInbox.IAppICESuccessCallback;
29
- import semusi.activitysdk.IAppICEDataCallback;
30
- import semusi.model.campaign.Campaign;
31
- import semusi.model.user.User;
32
-
33
- import java.util.*;
34
-
35
-
36
- import androidx.annotation.NonNull;
37
- import androidx.annotation.Nullable;
38
-
39
- import com.facebook.react.bridge.ReadableArray;
40
- import com.facebook.react.bridge.ReadableMapKeySetIterator;
41
- import com.facebook.react.bridge.WritableArray;
42
- import com.facebook.react.bridge.WritableMap;
43
- import com.facebook.react.modules.core.DeviceEventManagerModule;
44
-
45
- import org.json.JSONException;
46
- import org.json.JSONObject;
47
-
48
-
49
- public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
50
- private static ReactApplicationContext context = null;
51
- private static final String TAG = "AppIceReactPlugin";
52
-
53
- public AppIceReactPluginModule(ReactApplicationContext reactContext) {
54
- super(reactContext);
55
- context = reactContext;
56
- }
57
-
58
- @NonNull
59
- @Override
60
- public String getName() {
61
- return "AppIceReactPlugin";
62
- }
63
-
64
-
65
- //=========================
66
- // SDK CONFIG
67
- //========================
68
-
69
- /**
70
- * @param appID
71
- * @param appKey
72
- * @param apiKey
73
- * @param region
74
- * @param baseUrl
75
- * @param certs
76
- */
77
- //appID, appKey, apiKey, gcmID, region, baseUrl, certs,success, error
78
- @ReactMethod
79
- public void startContext(String appID, String appKey, String apiKey, String deviceID,
80
- String region, String baseUrl, ReadableArray certs
81
- ) {
82
- Context context = getReactApplicationContext();
83
- AppICEUtils.printLog(TAG, "in startContext : appID : " + appID + ", appkey : " + appKey + ", apiKey : " + apiKey);
84
- try {
85
- SdkConfig config = new SdkConfig();
86
- config.setAnalyticsTrackingAllowedState(true);
87
- //readaableArray can not read by java so converting it to list type array
88
- List<String> certList = new ArrayList<String>(certs.size());
89
-
90
- for (int i = 0; i < certs.size(); i++) {
91
-
92
- certList.add(certs.getString(i));
93
- }
94
- Api.initSdk(appID, appKey, apiKey, region, baseUrl
95
- , certList
96
- , context);
97
-
98
- Api.startContext(context, config);
99
-
100
- } catch (Exception e) {
101
- AppICEUtils.printLog(TAG, "Exception in startContext : " + e);
102
- }
103
- }
104
-
105
- /**
106
- * @return
107
- */
108
- @ReactMethod
109
- private void validateIntegration() {
110
- try {
111
- Context ctx = getReactApplicationContext();
112
- PackageManager pm = ctx.getPackageManager();
113
-
114
- Intent receiverIntent = new Intent();
115
- receiverIntent.setClass(ctx, CampaignCampsReceiver.class);
116
- List<ResolveInfo> receivers = pm.queryBroadcastReceivers(receiverIntent, 0);
117
- if (receivers == null || receivers.size() <= 0) {
118
- AppICEUtils.printLog(TAG, "Missing Receiver entry in AndroidManifest : CampaignCampsReceiver");
119
- }
120
- Intent serviceIntent = new Intent();
121
- serviceIntent.setClass(ctx, NotificationEventService.class);
122
- ResolveInfo services = pm.resolveService(serviceIntent, 0);
123
- if (services == null) {
124
- AppICEUtils.printLog(TAG, "Missing Service entry in AndroidManifest : NotificationEventService");
125
- }
126
-
127
- ContextSdk sdk = new ContextSdk(ctx);
128
- if (sdk.getAppId() == null || sdk.getAppId().length() <= 0 || sdk.getAppId().trim().length() <= 0) {
129
- AppICEUtils.printLog(TAG, "Missing Meta-data entry : AppID");
130
- }
131
-
132
- if (sdk.getAppKey() == null || sdk.getAppKey().length() <= 0 || sdk.getAppKey().trim().length() <= 0) {
133
- AppICEUtils.printLog(TAG, "Missing Meta-data entry : AppKey");
134
- }
135
-
136
- if (sdk.getApiKey() == null || sdk.getApiKey().length() <= 0 || sdk.getApiKey().trim().length() <= 0) {
137
- AppICEUtils.printLog(TAG, "Missing Meta-data entry : ApiKey");
138
- }
139
- } catch (Exception e) {
140
- AppICEUtils.printLog(TAG, "validateIntegration: " + e.getMessage());
141
- }
142
- }
143
-
144
- @ReactMethod
145
- public void registerLifeCycle() {
146
- final Context context = getReactApplicationContext();
147
- if (context != null) {
148
- Handler handler = new Handler(context.getMainLooper());
149
- handler.post(new Runnable() {
150
- @Override
151
- public void run() {
152
- ContextSdk.registerLifeCycle(context);
153
- }
154
- });
155
- }
156
- }
157
-
158
- //===========================
159
- // EVENTS AND VARIABLES
160
- //===========================
161
-
162
- /**
163
- * @param eventName
164
- */
165
- @ReactMethod
166
- public void tagEvent(String eventName, ReadableMap props) {
167
- Context context = getReactApplicationContext();
168
- try {
169
- HashMap<String, Object> mapData = eventPropsFromReadableMap(props);
170
- if (eventName != null && eventName.length() > 0) {
171
- ContextSdk.tagEventObj(eventName, mapData, context);
172
- }
173
- } catch (Exception e) {
174
- AppICEUtils.printLog(TAG, "Exception in tagEvent : " + e);
175
- }
176
- }
177
-
178
- @ReactMethod
179
- public void setCustomVariable(String eventName, String value) {
180
- Context context = getReactApplicationContext();
181
- try {
182
- if (value != null) {
183
- ContextSdk.setCustomVariable(eventName, (String) value, context);
184
- }
185
- } catch (Exception e) {
186
- AppICEUtils.printLog(TAG, "Exception in customVar : " + e);
187
- }
188
- }
189
-
190
- //====================================
191
- // user profile
192
- //=====================================
193
- @ReactMethod
194
- public void setUser(ReadableMap userDetails) {
195
- Context context = getReactApplicationContext();
196
-
197
- AppICEUtils.printLog(TAG, "setUser: " + userDetails);
198
- HashMap<String, Object> map = eventPropsFromReadableMap(userDetails);
199
-
200
- if (map != null) {
201
- try {
202
- User user = new User();
203
- try {
204
- if (map.containsKey(EnumConstants.APPICE_USER_NAME.getValue())) {
205
- Object name = map.get(EnumConstants.APPICE_USER_NAME.getValue());
206
- if (name != null) {
207
- user.setName(name.toString());
208
- }
209
- }
210
- } catch (Exception e) {
211
- AppICEUtils.printLog(TAG, "setUser: name issue " + e.getMessage());
212
- }
213
-
214
- try {
215
- if (map.containsKey(EnumConstants.APPICE_USER_PHONE.getValue())) {
216
- Object phone = map.get(EnumConstants.APPICE_USER_PHONE.getValue());
217
- if (phone != null) {
218
- user.setPhone(phone.toString());
219
- }
220
- }
221
- } catch (Exception e) {
222
- AppICEUtils.printLog(TAG, "setUser: phone issue " + e.getMessage());
223
- }
224
-
225
- try {
226
- if (map.containsKey(EnumConstants.APPICE_USER_EMAIL.getValue())) {
227
- Object email = map.get(EnumConstants.APPICE_USER_EMAIL.getValue());
228
- if (email != null) {
229
- user.setEmail(email.toString());
230
- }
231
- }
232
- } catch (Exception e) {
233
- AppICEUtils.printLog(TAG, "setUser: email issue " + e.getMessage());
234
- }
235
-
236
- try {
237
- if (map.containsKey(EnumConstants.APPICE_USER_AGE.getValue())) {
238
- Object age = map.get(EnumConstants.APPICE_USER_AGE.getValue());
239
- if (age != null) {
240
- user.setAge((Integer) age);
241
- }
242
- }
243
- } catch (Exception e) {
244
- AppICEUtils.printLog(TAG, "setUser: age issue " + e.getMessage());
245
- }
246
-
247
- try {
248
- if (map.containsKey(EnumConstants.APPICE_DATE_OF_BIRTH.getValue())) {
249
- Object dob = map.get(EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
250
- if (dob != null) {
251
- user.setDob((Integer) dob);
252
- }
253
- }
254
- } catch (Exception e) {
255
- AppICEUtils.printLog(TAG, "setUser: dob issue " + e.getMessage());
256
- }
257
- try {
258
- if (map.containsKey(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue())) {
259
- Object edt = map.get(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
260
- if (edt != null) {
261
- user.setEducationType(edt.toString());
262
- }
263
- }
264
- } catch (Exception e) {
265
- AppICEUtils.printLog(TAG, "setEducationType: edt issue " + e.getMessage());
266
- }
267
-
268
-
269
- try {
270
- if (map.containsKey(EnumConstants.APPICE_USER_GENDER.getValue())) {
271
- Object g = map.get(EnumConstants.APPICE_USER_GENDER.getValue());
272
- if (g != null) {
273
- user.setGender(g.toString());
274
- }
275
- }
276
- } catch (Exception e) {
277
- AppICEUtils.printLog(TAG, "setUser: gender issue " + e.getMessage());
278
- }
279
-
280
-
281
- try {
282
- if (map.containsKey(EnumConstants.APPICE_USER_IS_EMPLOYED.getValue())) {
283
- Object is_emp = map.get(EnumConstants.APPICE_USER_IS_EMPLOYED.getValue());
284
- if (is_emp != null) {
285
- user.setEmployed((Boolean) is_emp);
286
- }
287
- }
288
- } catch (Exception e) {
289
- AppICEUtils.printLog(TAG, "setUser: setEmployed issue " + e.getMessage());
290
- }
291
-
292
- try {
293
- if (map.containsKey(EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getValue())) {
294
- Object et = map.get(EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getValue());
295
- if (et != null) {
296
- user.setEmploymentType(et.toString());
297
- }
298
- }
299
- } catch (Exception e) {
300
- AppICEUtils.printLog(TAG, "setUser: et issue " + e.getMessage());
301
- }
302
-
303
- try {
304
- if (map.containsKey(EnumConstants.APPICE_USER_MARRIED.getValue())) {
305
- Object m = map.get(EnumConstants.APPICE_USER_MARRIED.getValue());
306
- if (m != null) {
307
- user.setMarried((Boolean) m);
308
- }
309
- }
310
- } catch (Exception e) {
311
- AppICEUtils.printLog(TAG, "setUser: married issue " + e.getMessage());
312
- }
313
- ContextSdk.setUser(user, context);
314
- } catch (Exception e) {
315
- }
316
- }
317
- }
318
-
319
- @ReactMethod
320
- public void getUser(Callback callback) {
321
- WritableMap userObject = Arguments.createMap();
322
- Context context = getReactApplicationContext();
323
- try {
324
- User user = ContextSdk.getUser(context);
325
- if (user != null) {
326
- userObject = AppICEUtils.convertUserClassToWritableMap(user);
327
- callback.invoke(userObject);
328
- }
329
- } catch (Throwable t) {
330
- callback.invoke(t.getMessage());
331
- }
332
- }
333
-
334
- //===============================================
335
- // User id setting
336
- //===============================================
337
- @ReactMethod
338
- public void setUserId(ReadableArray userIds) {
339
- Context context = getReactApplicationContext();
340
- try {
341
- ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
342
- if (finalValues != null) {
343
- String[] usersId = finalValues.toArray(new String[finalValues.size()]);
344
- ContextSdk.setUser(usersId, context);
345
- }
346
- } catch (Exception e) {
347
- }
348
- }
349
-
350
- /**
351
- * To get the user_id from sdk.
352
- *
353
- * @callback will have the string
354
- */
355
- @ReactMethod
356
- public void getUserId(Callback callback) {
357
- Context context = getReactApplicationContext();
358
- callback.invoke(ContextSdk.getUserId(context));
359
- }
360
-
361
- /**
362
- * Get appinbox cData through mediakey
363
- * mediakey is a kind of key just like in json we find key value
364
- * @param {inboxMessage} ReadableMap
365
- * @param {String} mediakey : will get this key from cData json
366
- * @Callback will recive Map<String, Object> object
367
- */
368
- @ReactMethod
369
- public void getMediaData(ReadableMap inboxMessage, String mediayKey, Callback callback) {
370
- try {
371
- Context context = getReactApplicationContext();
372
- getMediaApiHelper(inboxMessage,null, MEDIA_DATA, mediayKey, callback, context);
373
- } catch (Throwable e) {
374
- }
375
- }
376
-
377
-
378
- /**
379
- * To get Media URL from getMediaData
380
- * inboxMessage {AppICEInboxMessage as a ReadableMap}
381
- * mediaData customData
382
- * @callback callback will receive mediaUrl{string}
383
- */
384
- @ReactMethod
385
- public void getMediaUrl(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
386
- Context context = getReactApplicationContext();
387
- getMediaApiHelper(inboxMessage, mediaData, MEDIA_URL,"", callback, context);
388
- }
389
-
390
- /**
391
- * To get Media type from customdata
392
- * inboxMessage {AppICEInboxMessage as a ReadableMap}
393
- * mediaData customData : this we will recived from getmediadata callback
394
- *
395
- * @callback callback will receive mediaType{string}
396
- */
397
- @ReactMethod
398
- public void getMediaType(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
399
- Context context = getReactApplicationContext();
400
- getMediaApiHelper(inboxMessage, mediaData, MEDIA_TYPE, "", callback, context);
401
- }
402
-
403
- /**
404
- * To get Media Thumbnail from customdata
405
- * inboxMessage {AppICEInboxMessage as a ReadableMap}
406
- * mediaData customData : this we will recived from getmediadata callback
407
- *
408
- * @callback callback will receive Thumbnail{string}
409
- */
410
- @ReactMethod
411
- public void getMediaThumbnail(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
412
- Context context = getReactApplicationContext();
413
- getMediaApiHelper(inboxMessage, mediaData, MEDIA_THUMBNAIL, "",callback, context);
414
- }
415
-
416
- //======================
417
- // LISTENER
418
- //======================
419
- @ReactMethod
420
- public void addListener(String eventName) {
421
- // Set up any upstream listeners or background tasks as necessary
422
- }
423
-
424
- @ReactMethod
425
- public void removeListeners(Integer count) {
426
- // Remove upstream listeners, stop unnecessary background tasks
427
- }
428
-
429
- //==============================================
430
- // notification
431
- //==============================================
432
- @ReactMethod
433
- public void pushNotificationClicked(String payload) {
434
- Context ctx = getReactApplicationContext();
435
- ContextSdk.pushNotificationClicked(payload, ctx);
436
- }
437
-
438
- //========================================
439
- // AppInbox
440
- //=========================================
441
-
442
- /**
443
- * Get inbox messages list.
444
- *
445
- * @param type the message type
446
- * 1 = ALL
447
- * 2 = UNREAD
448
- * 3 = READ
449
- * 4 = VIEWED
450
- * 5 = DELETED
451
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
452
- * @callback will have the string json array
453
- */
454
- @ReactMethod
455
- public void getInboxMessages(int type, ReadableArray userIds, Callback callback) {
456
- Context context = getReactApplicationContext();
457
- WritableArray writableArray = Arguments.createArray();
458
- try {
459
- ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
460
- if (finalValues != null) {
461
- String[] usersId = finalValues.toArray(new String[finalValues.size()]);
462
- List<AppICEInboxMessage> appICEInboxMessage = ContextSdk.getInboxMessage(type, usersId, context);
463
- for (int i = 0; i < appICEInboxMessage.size(); i++) {
464
- AppICEInboxMessage inboxMessage = appICEInboxMessage.get(i);
465
- writableArray.pushMap(AppICEUtils.convertClassToWritableMap(inboxMessage));
466
- }
467
- }
468
- callback.invoke(writableArray);
469
- } catch (Throwable e) {
470
- callback.invoke(e.getMessage());
471
- }
472
- }
473
- /**
474
- * This method is to get user details from the given user id
475
- * this method takes user id in form of Array and return User class objects and return them
476
- * from callback
477
- * @param userIds An array of user IDs
478
- * @param callback will return instance of User class
479
- */
480
- @ReactMethod
481
- public void getUserForIds(ReadableArray userIds, Callback callback) {
482
- Context context = getReactApplicationContext();
483
- WritableArray writableArray = Arguments.createArray();
484
- try {
485
- ArrayList<String> finalValues = null;
486
- if (userIds != null) {
487
- // convert ReadableArray (Hybrid) to ArrayList<String> (Native)
488
- finalValues = arrayListStringFromReadableArray(userIds);
489
- }
490
- // get list of user class object from native sdk
491
- List<User> users = ContextSdk.getUser(finalValues,context);
492
- for (int i = 0; i < users.size(); i++) {
493
- User user = users.get(i);
494
- // conver native object to WritableMap
495
- writableArray.pushMap(AppICEUtils.convertUserClassToWritableMap(user));
496
- }
497
- // return callback
498
- callback.invoke(writableArray);
499
- } catch (Throwable e) {
500
- callback.invoke(e.getMessage());
501
- }
502
- }
503
- /**
504
- * To sync up data with server
505
- * callback will have boolean true or false
506
- */
507
- @ReactMethod
508
- public void synchronizeData(int timeout, Callback callback) {
509
- Context context = getReactApplicationContext();
510
- try {
511
- ContextSdk.synchronizeData(new IAppICEDataCallback(){
512
- @Override
513
- public void onSuccess() {
514
- callback.invoke(true);
515
- }
516
- @Override
517
- public void onFailure(String message) {
518
- callback.invoke(false);
519
- }
520
- }, timeout, context);
521
- } catch (Throwable e) {
522
- callback.invoke(e.getMessage());
523
- }
524
-
525
- }
526
- /**
527
- * Get inbox messages count.
528
- *
529
- * @param type the message type
530
- * 1 = ALL
531
- * 2 = UNREAD
532
- * 3 = READ
533
- * 4 = VIEWED
534
- * 5 = DELETED
535
- * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
536
- * @callback will have the integer
537
- */
538
- @ReactMethod
539
- public void getMessageCount(int type, ReadableArray userIds, Callback callback) {
540
- Context context = getReactApplicationContext();
541
- int count = 0;
542
- try {
543
- ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
544
- if (finalValues != null) {
545
- String[] usersId = finalValues.toArray(new String[finalValues.size()]);
546
- count = ContextSdk.getMessageCount(type, usersId, context);
547
- }
548
- callback.invoke(count);
549
- } catch (Throwable e) {
550
- callback.invoke(e.getMessage());
551
- }
552
- }
553
-
554
- /**
555
- * Get messages payload based on message id.
556
- *
557
- * @param messageId - message id of the notification
558
- * @param userId - single userid in string ie. "useridA"
559
- * @callback will have the json object
560
- */
561
- @ReactMethod
562
- public void getInboxMessageForId(String messageId, String userId, Callback callback) {
563
- Context context = getReactApplicationContext();
564
- try {
565
- AppICEInboxMessage inboxMessage = ContextSdk.getInboxMessageForId(messageId, userId, context);
566
- callback.invoke(AppICEUtils.convertClassToWritableMap(inboxMessage));
567
- } catch (Throwable e) {
568
- callback.invoke(e.getMessage());
569
- }
570
- }
571
-
572
- /**
573
- * update message status ex. UNREAD to READ.
574
- *
575
- * @param messageId - message id of the notification
576
- * @param type - integer value for status
577
- * @param userId - single userid in string
578
- * @callback will have the boolean
579
- */
580
- @ReactMethod
581
- public void updateInboxMessage(String messageId, int type, String userId, Callback callback) {
582
- Context context = getReactApplicationContext();
583
- try {
584
- boolean isUpdated = ContextSdk.updatedInboxMessage(messageId, type, userId, context);
585
- callback.invoke(isUpdated);
586
- } catch (Throwable e) {
587
- callback.invoke(e.getMessage());
588
- }
589
- }
590
-
591
-
592
- /**
593
- * To sync with server if server will have any new data to update.
594
- *
595
- * @param timeout - integer value for status
596
- * @callback will have the boolean
597
- */
598
- @ReactMethod
599
- public void synchronizeInbox(int timeout, final Callback callback) {
600
- Context context = getReactApplicationContext();
601
- try {
602
- ContextSdk.synchronizeInbox(new IAppICESuccessCallback() {
603
- @Override
604
- public void callback(boolean isAppInboxRefreshed) {
605
- callback.invoke(isAppInboxRefreshed);
606
- }
607
- }, timeout, context);
608
- } catch (Throwable e) {
609
- callback.invoke(e.getMessage());
610
- }
611
- }
612
-
613
- //===========================================
614
- // Device Setting
615
- //===========================================
616
-
617
- /**
618
- * To set the custom device_id.
619
- */
620
- @ReactMethod
621
- public void setInternalId(String deviceId) {
622
- //TODO{ we can not call setDevice Id here because it
623
- // will directly call start context with new device id
624
- // but here we want to store the data only
625
- // }
626
- //ContextSdk.setInternalId();
627
- }
628
-
629
- /**
630
- * To get the ad_id from sdk.
631
- *
632
- * @callback will have the string
633
- */
634
- @ReactMethod
635
- public void getDeviceId(Callback callback) {
636
- Context context = getReactApplicationContext();
637
- callback.invoke(ContextSdk.getInternalId(context));
638
- }
639
- @ReactMethod
640
- public void isDeviceReady(Boolean flag){
641
-
642
- }
643
-
644
- @Nullable
645
- @Override
646
- public Map<String, Object> getConstants() {
647
- final Map<String, Object> constants = new HashMap<>();
648
- constants.put(EnumConstants.APPICE_USER_NAME.getConstants(), EnumConstants.APPICE_USER_NAME.getValue());
649
- constants.put(EnumConstants.APPICE_USER_PHONE.getConstants(), EnumConstants.APPICE_USER_PHONE.getValue());
650
- constants.put(EnumConstants.APPICE_USER_EMAIL.getConstants(), EnumConstants.APPICE_USER_EMAIL.getValue());
651
- constants.put(EnumConstants.APPICE_DATE_OF_BIRTH.getConstants(), EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
652
- constants.put(EnumConstants.APPICE_USER_EDUCATION_TYPE.getConstants(), EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
653
- constants.put(EnumConstants.APPICE_USER_IS_EMPLOYED.getConstants(), EnumConstants.APPICE_USER_IS_EMPLOYED.getValue());
654
- constants.put(EnumConstants.APPICE_USER_MARRIED.getConstants(), EnumConstants.APPICE_USER_MARRIED.getValue());
655
- constants.put(EnumConstants.APPICE_USER_EDUCATION.getConstants(), EnumConstants.APPICE_USER_EDUCATION.getValue());
656
- constants.put(EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getConstants(), EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getValue());
657
- constants.put(EnumConstants.APPICE_USER_AGE.getConstants(), EnumConstants.APPICE_USER_AGE.getValue());
658
- constants.put(EnumConstants.APPICE_USER_GENDER.getConstants(), EnumConstants.APPICE_USER_GENDER.getValue());
659
- constants.put(EnumConstants.APPICE_PUSH_NOTIFICATION_CLICKED.getConstants(), EnumConstants.APPICE_PUSH_NOTIFICATION_CLICKED.getValue());
660
- constants.put(EnumConstants.APPICE_INAPP_NOTIFICATION_CLICKED.getConstants(), EnumConstants.APPICE_INAPP_NOTIFICATION_CLICKED.getValue());
661
- constants.put(EnumConstants.FIRST_SEEN.getConstants(), EnumConstants.FIRST_SEEN.getValue());
662
- constants.put(EnumConstants.LAST_SEEN.getConstants(), EnumConstants.LAST_SEEN.getValue());
663
- constants.put(EnumConstants.TOP_N_PRODUCTS_VIEWED.getConstants(), EnumConstants.TOP_N_PRODUCTS_VIEWED.getValue());
664
- constants.put(EnumConstants.N_COMPLAINTS_RAISED.getConstants(), EnumConstants.N_COMPLAINTS_RAISED.getValue());
665
- constants.put(EnumConstants.PREF_LOGIN_DEVICE.getConstants(), EnumConstants.PREF_LOGIN_DEVICE.getValue());
666
- constants.put(EnumConstants.REFERRAL_CAMPAIGN.getConstants(), EnumConstants.REFERRAL_CAMPAIGN.getValue());
667
- constants.put(EnumConstants.DEMOGRAPHIC_INFO.getConstants(), EnumConstants.DEMOGRAPHIC_INFO.getValue());
668
- constants.put(EnumConstants.TOTAL_ORDER_VALUE.getConstants(), EnumConstants.TOTAL_ORDER_VALUE.getValue());
669
- constants.put(EnumConstants.ADD_TO_CART_N_DAYS.getConstants(), EnumConstants.ADD_TO_CART_N_DAYS.getValue());
670
- constants.put(EnumConstants.FINANCIAL_SERVICES.getConstants(), EnumConstants.FINANCIAL_SERVICES.getValue());
671
- constants.put(EnumConstants.CREDIT_SCORE.getConstants(), EnumConstants.CREDIT_SCORE.getValue());
672
- constants.put(EnumConstants.DEBT_TO_INCOME_RATIO.getConstants(), EnumConstants.DEBT_TO_INCOME_RATIO.getValue());
673
- constants.put(EnumConstants.SAVINGS_BALANCE.getConstants(), EnumConstants.SAVINGS_BALANCE.getValue());
674
- constants.put(EnumConstants.CHECKING_BALANCE.getConstants(), EnumConstants.CHECKING_BALANCE.getValue());
675
- constants.put(EnumConstants.AVERAGE_TRANSACTION_AMOUNT.getConstants(), EnumConstants.AVERAGE_TRANSACTION_AMOUNT.getValue());
676
- constants.put(EnumConstants.FREQUENCY_OF_TRANSACTION.getConstants(), EnumConstants.FREQUENCY_OF_TRANSACTION.getValue());
677
- constants.put(EnumConstants.TYPE_OF_TRANSACTION.getConstants(), EnumConstants.TYPE_OF_TRANSACTION.getValue());
678
- constants.put(EnumConstants.CAMP_ID.getConstants(), EnumConstants.CAMP_ID.getValue());
679
- constants.put(EnumConstants.ACTION_URL.getConstants(), EnumConstants.ACTION_URL.getValue());
680
- constants.put(EnumConstants.ACTION_TYPE.getConstants(), EnumConstants.ACTION_TYPE.getValue());
681
- constants.put(EnumConstants.CUSTOMDATA.getConstants(), EnumConstants.CUSTOMDATA.getValue());
682
-
683
- return constants;
684
- }
685
-
686
- //=====================================
687
- public static void sendEvent(String eventName, @Nullable WritableMap params) {
688
- try {
689
- context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
690
- } catch (RuntimeException e) {
691
- AppICEUtils.printLog(TAG, "java.lang.RuntimeException: Trying to invoke JS before CatalystInstance has been set!" + e);
692
- }
693
- }
694
- private static AppICEInboxMessage getMediaPreProcessing(ReadableMap inboxMessage,Context context) {
695
- AppICEInboxMessage appICEInboxMessage = null;
696
- JSONObject inboxJSON = AppICEUtils.toJSONObject(inboxMessage);
697
- if (inboxJSON != null && inboxJSON.length()>0) {
698
- appICEInboxMessage = AppICEInboxMessage.getAppICEInboxMessage(inboxJSON.toString(), context);
699
- if (appICEInboxMessage != null) {
700
- return appICEInboxMessage;
701
- }
702
- }
703
- return appICEInboxMessage;
704
- }
705
-
706
- public static void getMediaApiHelper(ReadableMap inboxMessage, ReadableMap mediaData, String type, String mediayKey, Callback callback, Context context){
707
-
708
- AppICEInboxMessage appICEInboxMessage = getMediaPreProcessing(inboxMessage, context);
709
- if (appICEInboxMessage != null) {
710
- switch (type) {
711
- case "mediaType": {
712
- if (mediaData != null){
713
- String mediaType = appICEInboxMessage.getMediaType(AppICEUtils.eventPropsFromReadableMap(mediaData));
714
- callback.invoke(mediaType, null);
715
- }else
716
- callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
717
- break;
718
- }
719
-
720
- case "mediaUrl": {
721
- if (mediaData != null) {
722
- String mediaUrl = appICEInboxMessage.getMediaUrl(AppICEUtils.eventPropsFromReadableMap(mediaData));
723
- callback.invoke(mediaUrl, null);
724
- }else
725
- callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
726
- break;
727
- }
728
-
729
- case "mediaThumbnail": {
730
- if (mediaData != null) {
731
- String mediaThumbnail = appICEInboxMessage.getMediaThumbnail(AppICEUtils.eventPropsFromReadableMap(mediaData));
732
- callback.invoke(mediaThumbnail, null);
733
- }else
734
- callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
735
- break;
736
- }
737
-
738
- case "mediaData":{
739
- if (mediayKey != null) {
740
- Map<String, Object> map = appICEInboxMessage.getMediaData(mediayKey);
741
- if (map != null) {
742
- callback.invoke(AppICEUtils.toWritableMap(map), null);
743
- } else {
744
- callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
745
- }
746
- }else{
747
- callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
748
- }
749
- }
750
- }
751
- }else {
752
- callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
753
- }
754
- }
755
-
756
- @ReactMethod
757
- public void getCampaigns(String type, Callback callback) {
758
- Context context = getReactApplicationContext();
759
- WritableArray writableArray = Arguments.createArray();
760
- try{
761
- List<Campaign> campaigns = ContextSdk.getCampaigns(type, context);
762
- for (int i = 0; i < campaigns.size(); i++) {
763
- Campaign campaign = campaigns.get(i);
764
- writableArray.pushMap(AppICEUtils.convertClassToWritableMap(campaign));
765
- }
766
- callback.invoke(writableArray);
767
- }
768
- catch(Throwable e){
769
- callback.invoke(e.getMessage());
770
- }
771
- }
772
-
773
- @ReactMethod
774
- public void getCampaignById(String cmpId,Callback callback) {
775
- Context context = getReactApplicationContext();
776
- Campaign campaign = ContextSdk.getCampaignById(cmpId, context);
777
- callback.invoke(AppICEUtils.convertClassToWritableMap(campaign));
778
- }
1
+ package com.reactlibrary;
2
+
3
+ import static com.reactlibrary.AppICEUtils.arrayListStringFromReadableArray;
4
+ import static com.reactlibrary.AppICEUtils.eventPropsFromReadableMap;
5
+ import static com.reactlibrary.StringConstants.MEDIA_DATA;
6
+ import static com.reactlibrary.StringConstants.MEDIA_THUMBNAIL;
7
+ import static com.reactlibrary.StringConstants.MEDIA_TYPE;
8
+ import static com.reactlibrary.StringConstants.MEDIA_URL;
9
+
10
+ import android.content.Context;
11
+ import android.content.Intent;
12
+ import android.content.pm.PackageManager;
13
+ import android.content.pm.ResolveInfo;
14
+
15
+ import com.facebook.react.bridge.Arguments;
16
+ import com.facebook.react.bridge.Callback;
17
+ import com.facebook.react.bridge.ReactApplicationContext;
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
+ import com.facebook.react.bridge.ReactMethod;
20
+ import com.facebook.react.bridge.ReadableMap;
21
+
22
+ import android.os.Handler;
23
+ import semusi.activitysdk.Api;
24
+ import semusi.activitysdk.ContextSdk;
25
+ import semusi.activitysdk.SdkConfig;
26
+
27
+ import semusi.context.ui.appInbox.AppICEInboxMessage;
28
+ import semusi.context.ui.appInbox.IAppICESuccessCallback;
29
+ import semusi.activitysdk.IAppICEDataCallback;
30
+ import semusi.model.campaign.Campaign;
31
+ import semusi.model.user.User;
32
+
33
+ import java.util.*;
34
+
35
+
36
+ import androidx.annotation.NonNull;
37
+ import androidx.annotation.Nullable;
38
+
39
+ import com.facebook.react.bridge.ReadableArray;
40
+ import com.facebook.react.bridge.ReadableMapKeySetIterator;
41
+ import com.facebook.react.bridge.WritableArray;
42
+ import com.facebook.react.bridge.WritableMap;
43
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
44
+
45
+ import org.json.JSONException;
46
+ import org.json.JSONObject;
47
+
48
+
49
+ public class AppIceReactPluginModule extends ReactContextBaseJavaModule {
50
+ private static ReactApplicationContext context = null;
51
+ private static final String TAG = "AppIceReactPlugin";
52
+
53
+ public AppIceReactPluginModule(ReactApplicationContext reactContext) {
54
+ super(reactContext);
55
+ context = reactContext;
56
+ }
57
+
58
+ @NonNull
59
+ @Override
60
+ public String getName() {
61
+ return "AppIceReactPlugin";
62
+ }
63
+
64
+
65
+ //=========================
66
+ // SDK CONFIG
67
+ //========================
68
+
69
+ /**
70
+ * @param appID
71
+ * @param appKey
72
+ * @param apiKey
73
+ * @param region
74
+ * @param baseUrl
75
+ * @param certs
76
+ */
77
+ //appID, appKey, apiKey, gcmID, region, baseUrl, certs,success, error
78
+ @ReactMethod
79
+ public void startContext(String appID, String appKey, String apiKey, String deviceID,
80
+ String region, String baseUrl, ReadableArray certs
81
+ ) {
82
+ Context context = getReactApplicationContext();
83
+ AppICEUtils.printLog(TAG, "in startContext : appID : " + appID + ", appkey : " + appKey + ", apiKey : " + apiKey);
84
+ try {
85
+ SdkConfig config = new SdkConfig();
86
+ config.setAnalyticsTrackingAllowedState(true);
87
+ //readaableArray can not read by java so converting it to list type array
88
+ List<String> certList = new ArrayList<String>(certs.size());
89
+
90
+ for (int i = 0; i < certs.size(); i++) {
91
+
92
+ certList.add(certs.getString(i));
93
+ }
94
+ Api.initSdk(appID, appKey, apiKey, region, baseUrl
95
+ , certList
96
+ , context);
97
+
98
+ Api.startContext(context, config);
99
+
100
+ } catch (Exception e) {
101
+ AppICEUtils.printLog(TAG, "Exception in startContext : " + e);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * @return
107
+ */
108
+ @ReactMethod
109
+ private void validateIntegration() {
110
+ try {
111
+ Context ctx = getReactApplicationContext();
112
+ PackageManager pm = ctx.getPackageManager();
113
+
114
+ Intent receiverIntent = new Intent();
115
+ receiverIntent.setClass(ctx, CampaignCampsReceiver.class);
116
+ List<ResolveInfo> receivers = pm.queryBroadcastReceivers(receiverIntent, 0);
117
+ if (receivers == null || receivers.size() <= 0) {
118
+ AppICEUtils.printLog(TAG, "Missing Receiver entry in AndroidManifest : CampaignCampsReceiver");
119
+ }
120
+ Intent serviceIntent = new Intent();
121
+ serviceIntent.setClass(ctx, NotificationEventService.class);
122
+ ResolveInfo services = pm.resolveService(serviceIntent, 0);
123
+ if (services == null) {
124
+ AppICEUtils.printLog(TAG, "Missing Service entry in AndroidManifest : NotificationEventService");
125
+ }
126
+
127
+ ContextSdk sdk = new ContextSdk(ctx);
128
+ if (sdk.getAppId() == null || sdk.getAppId().length() <= 0 || sdk.getAppId().trim().length() <= 0) {
129
+ AppICEUtils.printLog(TAG, "Missing Meta-data entry : AppID");
130
+ }
131
+
132
+ if (sdk.getAppKey() == null || sdk.getAppKey().length() <= 0 || sdk.getAppKey().trim().length() <= 0) {
133
+ AppICEUtils.printLog(TAG, "Missing Meta-data entry : AppKey");
134
+ }
135
+
136
+ if (sdk.getApiKey() == null || sdk.getApiKey().length() <= 0 || sdk.getApiKey().trim().length() <= 0) {
137
+ AppICEUtils.printLog(TAG, "Missing Meta-data entry : ApiKey");
138
+ }
139
+ } catch (Exception e) {
140
+ AppICEUtils.printLog(TAG, "validateIntegration: " + e.getMessage());
141
+ }
142
+ }
143
+
144
+ @ReactMethod
145
+ public void registerLifeCycle() {
146
+ final Context context = getReactApplicationContext();
147
+ if (context != null) {
148
+ Handler handler = new Handler(context.getMainLooper());
149
+ handler.post(new Runnable() {
150
+ @Override
151
+ public void run() {
152
+ ContextSdk.registerLifeCycle(context);
153
+ }
154
+ });
155
+ }
156
+ }
157
+
158
+ //===========================
159
+ // EVENTS AND VARIABLES
160
+ //===========================
161
+
162
+ /**
163
+ * @param eventName
164
+ */
165
+ @ReactMethod
166
+ public void tagEvent(String eventName, ReadableMap props) {
167
+ Context context = getReactApplicationContext();
168
+ try {
169
+ HashMap<String, Object> mapData = eventPropsFromReadableMap(props);
170
+ if (eventName != null && eventName.length() > 0) {
171
+ ContextSdk.tagEventObj(eventName, mapData, context);
172
+ }
173
+ } catch (Exception e) {
174
+ AppICEUtils.printLog(TAG, "Exception in tagEvent : " + e);
175
+ }
176
+ }
177
+
178
+ @ReactMethod
179
+ public void setCustomVariable(String eventName, String value) {
180
+ Context context = getReactApplicationContext();
181
+ try {
182
+ if (value != null) {
183
+ ContextSdk.setCustomVariable(eventName, (String) value, context);
184
+ }
185
+ } catch (Exception e) {
186
+ AppICEUtils.printLog(TAG, "Exception in customVar : " + e);
187
+ }
188
+ }
189
+
190
+ //====================================
191
+ // user profile
192
+ //=====================================
193
+ @ReactMethod
194
+ public void setUser(ReadableMap userDetails) {
195
+ Context context = getReactApplicationContext();
196
+
197
+ AppICEUtils.printLog(TAG, "setUser: " + userDetails);
198
+ HashMap<String, Object> map = eventPropsFromReadableMap(userDetails);
199
+
200
+ if (map != null) {
201
+ try {
202
+ User user = new User();
203
+ try {
204
+ if (map.containsKey(EnumConstants.APPICE_USER_NAME.getValue())) {
205
+ Object name = map.get(EnumConstants.APPICE_USER_NAME.getValue());
206
+ if (name != null) {
207
+ user.setName(name.toString());
208
+ }
209
+ }
210
+ } catch (Exception e) {
211
+ AppICEUtils.printLog(TAG, "setUser: name issue " + e.getMessage());
212
+ }
213
+
214
+ try {
215
+ if (map.containsKey(EnumConstants.APPICE_USER_PHONE.getValue())) {
216
+ Object phone = map.get(EnumConstants.APPICE_USER_PHONE.getValue());
217
+ if (phone != null) {
218
+ user.setPhone(phone.toString());
219
+ }
220
+ }
221
+ } catch (Exception e) {
222
+ AppICEUtils.printLog(TAG, "setUser: phone issue " + e.getMessage());
223
+ }
224
+
225
+ try {
226
+ if (map.containsKey(EnumConstants.APPICE_USER_EMAIL.getValue())) {
227
+ Object email = map.get(EnumConstants.APPICE_USER_EMAIL.getValue());
228
+ if (email != null) {
229
+ user.setEmail(email.toString());
230
+ }
231
+ }
232
+ } catch (Exception e) {
233
+ AppICEUtils.printLog(TAG, "setUser: email issue " + e.getMessage());
234
+ }
235
+
236
+ try {
237
+ if (map.containsKey(EnumConstants.APPICE_USER_AGE.getValue())) {
238
+ Object age = map.get(EnumConstants.APPICE_USER_AGE.getValue());
239
+ if (age != null) {
240
+ user.setAge((Integer) age);
241
+ }
242
+ }
243
+ } catch (Exception e) {
244
+ AppICEUtils.printLog(TAG, "setUser: age issue " + e.getMessage());
245
+ }
246
+
247
+ try {
248
+ if (map.containsKey(EnumConstants.APPICE_DATE_OF_BIRTH.getValue())) {
249
+ Object dob = map.get(EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
250
+ if (dob != null) {
251
+ user.setDob((Integer) dob);
252
+ }
253
+ }
254
+ } catch (Exception e) {
255
+ AppICEUtils.printLog(TAG, "setUser: dob issue " + e.getMessage());
256
+ }
257
+ try {
258
+ if (map.containsKey(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue())) {
259
+ Object edt = map.get(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
260
+ if (edt != null) {
261
+ user.setEducationType(edt.toString());
262
+ }
263
+ }
264
+ } catch (Exception e) {
265
+ AppICEUtils.printLog(TAG, "setEducationType: edt issue " + e.getMessage());
266
+ }
267
+
268
+
269
+ try {
270
+ if (map.containsKey(EnumConstants.APPICE_USER_GENDER.getValue())) {
271
+ Object g = map.get(EnumConstants.APPICE_USER_GENDER.getValue());
272
+ if (g != null) {
273
+ user.setGender(g.toString());
274
+ }
275
+ }
276
+ } catch (Exception e) {
277
+ AppICEUtils.printLog(TAG, "setUser: gender issue " + e.getMessage());
278
+ }
279
+
280
+
281
+ try {
282
+ if (map.containsKey(EnumConstants.APPICE_USER_IS_EMPLOYED.getValue())) {
283
+ Object is_emp = map.get(EnumConstants.APPICE_USER_IS_EMPLOYED.getValue());
284
+ if (is_emp != null) {
285
+ user.setEmployed((Boolean) is_emp);
286
+ }
287
+ }
288
+ } catch (Exception e) {
289
+ AppICEUtils.printLog(TAG, "setUser: setEmployed issue " + e.getMessage());
290
+ }
291
+
292
+ try {
293
+ if (map.containsKey(EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getValue())) {
294
+ Object et = map.get(EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getValue());
295
+ if (et != null) {
296
+ user.setEmploymentType(et.toString());
297
+ }
298
+ }
299
+ } catch (Exception e) {
300
+ AppICEUtils.printLog(TAG, "setUser: et issue " + e.getMessage());
301
+ }
302
+
303
+ try {
304
+ if (map.containsKey(EnumConstants.APPICE_USER_MARRIED.getValue())) {
305
+ Object m = map.get(EnumConstants.APPICE_USER_MARRIED.getValue());
306
+ if (m != null) {
307
+ user.setMarried((Boolean) m);
308
+ }
309
+ }
310
+ } catch (Exception e) {
311
+ AppICEUtils.printLog(TAG, "setUser: married issue " + e.getMessage());
312
+ }
313
+ ContextSdk.setUser(user, context);
314
+ } catch (Exception e) {
315
+ }
316
+ }
317
+ }
318
+
319
+ @ReactMethod
320
+ public void getUser(Callback callback) {
321
+ WritableMap userObject = Arguments.createMap();
322
+ Context context = getReactApplicationContext();
323
+ try {
324
+ User user = ContextSdk.getUser(context);
325
+ if (user != null) {
326
+ userObject = AppICEUtils.convertUserClassToWritableMap(user);
327
+ callback.invoke(userObject);
328
+ }
329
+ } catch (Throwable t) {
330
+ callback.invoke(t.getMessage());
331
+ }
332
+ }
333
+
334
+ //===============================================
335
+ // User id setting
336
+ //===============================================
337
+ @ReactMethod
338
+ public void setUserId(ReadableArray userIds) {
339
+ Context context = getReactApplicationContext();
340
+ try {
341
+ ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
342
+ if (finalValues != null) {
343
+ String[] usersId = finalValues.toArray(new String[finalValues.size()]);
344
+ ContextSdk.setUser(usersId, context);
345
+ }
346
+ } catch (Exception e) {
347
+ }
348
+ }
349
+
350
+ /**
351
+ * To get the user_id from sdk.
352
+ *
353
+ * @callback will have the string
354
+ */
355
+ @ReactMethod
356
+ public void getUserId(Callback callback) {
357
+ Context context = getReactApplicationContext();
358
+ callback.invoke(ContextSdk.getUserId(context));
359
+ }
360
+
361
+ /**
362
+ * Get appinbox cData through mediakey
363
+ * mediakey is a kind of key just like in json we find key value
364
+ * @param {inboxMessage} ReadableMap
365
+ * @param {String} mediakey : will get this key from cData json
366
+ * @Callback will recive Map<String, Object> object
367
+ */
368
+ @ReactMethod
369
+ public void getMediaData(ReadableMap inboxMessage, String mediayKey, Callback callback) {
370
+ try {
371
+ Context context = getReactApplicationContext();
372
+ getMediaApiHelper(inboxMessage,null, MEDIA_DATA, mediayKey, callback, context);
373
+ } catch (Throwable e) {
374
+ }
375
+ }
376
+
377
+
378
+ /**
379
+ * To get Media URL from getMediaData
380
+ * inboxMessage {AppICEInboxMessage as a ReadableMap}
381
+ * mediaData customData
382
+ * @callback callback will receive mediaUrl{string}
383
+ */
384
+ @ReactMethod
385
+ public void getMediaUrl(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
386
+ Context context = getReactApplicationContext();
387
+ getMediaApiHelper(inboxMessage, mediaData, MEDIA_URL,"", callback, context);
388
+ }
389
+
390
+ /**
391
+ * To get Media type from customdata
392
+ * inboxMessage {AppICEInboxMessage as a ReadableMap}
393
+ * mediaData customData : this we will recived from getmediadata callback
394
+ *
395
+ * @callback callback will receive mediaType{string}
396
+ */
397
+ @ReactMethod
398
+ public void getMediaType(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
399
+ Context context = getReactApplicationContext();
400
+ getMediaApiHelper(inboxMessage, mediaData, MEDIA_TYPE, "", callback, context);
401
+ }
402
+
403
+ /**
404
+ * To get Media Thumbnail from customdata
405
+ * inboxMessage {AppICEInboxMessage as a ReadableMap}
406
+ * mediaData customData : this we will recived from getmediadata callback
407
+ *
408
+ * @callback callback will receive Thumbnail{string}
409
+ */
410
+ @ReactMethod
411
+ public void getMediaThumbnail(ReadableMap inboxMessage, ReadableMap mediaData, Callback callback) {
412
+ Context context = getReactApplicationContext();
413
+ getMediaApiHelper(inboxMessage, mediaData, MEDIA_THUMBNAIL, "",callback, context);
414
+ }
415
+
416
+ //======================
417
+ // LISTENER
418
+ //======================
419
+ @ReactMethod
420
+ public void addListener(String eventName) {
421
+ // Set up any upstream listeners or background tasks as necessary
422
+ }
423
+
424
+ @ReactMethod
425
+ public void removeListeners(Integer count) {
426
+ // Remove upstream listeners, stop unnecessary background tasks
427
+ }
428
+
429
+ //==============================================
430
+ // notification
431
+ //==============================================
432
+ @ReactMethod
433
+ public void pushNotificationClicked(String payload) {
434
+ Context ctx = getReactApplicationContext();
435
+ ContextSdk.pushNotificationClicked(payload, ctx);
436
+ }
437
+
438
+ //========================================
439
+ // AppInbox
440
+ //=========================================
441
+
442
+ /**
443
+ * Get inbox messages list.
444
+ *
445
+ * @param type the message type
446
+ * 1 = ALL
447
+ * 2 = UNREAD
448
+ * 3 = READ
449
+ * 4 = VIEWED
450
+ * 5 = DELETED
451
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
452
+ * @callback will have the string json array
453
+ */
454
+ @ReactMethod
455
+ public void getInboxMessages(int type, ReadableArray userIds, Callback callback) {
456
+ Context context = getReactApplicationContext();
457
+ WritableArray writableArray = Arguments.createArray();
458
+ try {
459
+ ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
460
+ if (finalValues != null) {
461
+ String[] usersId = finalValues.toArray(new String[finalValues.size()]);
462
+ List<AppICEInboxMessage> appICEInboxMessage = ContextSdk.getInboxMessage(type, usersId, context);
463
+ for (int i = 0; i < appICEInboxMessage.size(); i++) {
464
+ AppICEInboxMessage inboxMessage = appICEInboxMessage.get(i);
465
+ writableArray.pushMap(AppICEUtils.convertClassToWritableMap(inboxMessage));
466
+ }
467
+ }
468
+ callback.invoke(writableArray);
469
+ } catch (Throwable e) {
470
+ callback.invoke(e.getMessage());
471
+ }
472
+ }
473
+ /**
474
+ * This method is to get user details from the given user id
475
+ * this method takes user id in form of Array and return User class objects and return them
476
+ * from callback
477
+ * @param userIds An array of user IDs
478
+ * @param callback will return instance of User class
479
+ */
480
+ @ReactMethod
481
+ public void getUserForIds(ReadableArray userIds, Callback callback) {
482
+ Context context = getReactApplicationContext();
483
+ WritableArray writableArray = Arguments.createArray();
484
+ try {
485
+ ArrayList<String> finalValues = null;
486
+ if (userIds != null) {
487
+ // convert ReadableArray (Hybrid) to ArrayList<String> (Native)
488
+ finalValues = arrayListStringFromReadableArray(userIds);
489
+ }
490
+ // get list of user class object from native sdk
491
+ List<User> users = ContextSdk.getUser(finalValues,context);
492
+ for (int i = 0; i < users.size(); i++) {
493
+ User user = users.get(i);
494
+ // conver native object to WritableMap
495
+ writableArray.pushMap(AppICEUtils.convertUserClassToWritableMap(user));
496
+ }
497
+ // return callback
498
+ callback.invoke(writableArray);
499
+ } catch (Throwable e) {
500
+ callback.invoke(e.getMessage());
501
+ }
502
+ }
503
+ /**
504
+ * To sync up data with server
505
+ * callback will have boolean true or false
506
+ */
507
+ @ReactMethod
508
+ public void synchronizeData(int timeout, Callback callback) {
509
+ Context context = getReactApplicationContext();
510
+ try {
511
+ ContextSdk.synchronizeData(new IAppICEDataCallback(){
512
+ @Override
513
+ public void onSuccess() {
514
+ callback.invoke(true);
515
+ }
516
+ @Override
517
+ public void onFailure(String message) {
518
+ callback.invoke(false);
519
+ }
520
+ }, timeout, context);
521
+ } catch (Throwable e) {
522
+ callback.invoke(e.getMessage());
523
+ }
524
+
525
+ }
526
+ /**
527
+ * Get inbox messages count.
528
+ *
529
+ * @param type the message type
530
+ * 1 = ALL
531
+ * 2 = UNREAD
532
+ * 3 = READ
533
+ * 4 = VIEWED
534
+ * 5 = DELETED
535
+ * @param userIds the same way we are passing the value in setUserId same value we need here. ie. [ "useridA" ]
536
+ * @callback will have the integer
537
+ */
538
+ @ReactMethod
539
+ public void getMessageCount(int type, ReadableArray userIds, Callback callback) {
540
+ Context context = getReactApplicationContext();
541
+ int count = 0;
542
+ try {
543
+ ArrayList<String> finalValues = arrayListStringFromReadableArray(userIds);
544
+ if (finalValues != null) {
545
+ String[] usersId = finalValues.toArray(new String[finalValues.size()]);
546
+ count = ContextSdk.getMessageCount(type, usersId, context);
547
+ }
548
+ callback.invoke(count);
549
+ } catch (Throwable e) {
550
+ callback.invoke(e.getMessage());
551
+ }
552
+ }
553
+
554
+ /**
555
+ * Get messages payload based on message id.
556
+ *
557
+ * @param messageId - message id of the notification
558
+ * @param userId - single userid in string ie. "useridA"
559
+ * @callback will have the json object
560
+ */
561
+ @ReactMethod
562
+ public void getInboxMessageForId(String messageId, String userId, Callback callback) {
563
+ Context context = getReactApplicationContext();
564
+ try {
565
+ AppICEInboxMessage inboxMessage = ContextSdk.getInboxMessageForId(messageId, userId, context);
566
+ callback.invoke(AppICEUtils.convertClassToWritableMap(inboxMessage));
567
+ } catch (Throwable e) {
568
+ callback.invoke(e.getMessage());
569
+ }
570
+ }
571
+
572
+ /**
573
+ * update message status ex. UNREAD to READ.
574
+ *
575
+ * @param messageId - message id of the notification
576
+ * @param type - integer value for status
577
+ * @param userId - single userid in string
578
+ * @callback will have the boolean
579
+ */
580
+ @ReactMethod
581
+ public void updateInboxMessage(String messageId, int type, String userId, Callback callback) {
582
+ Context context = getReactApplicationContext();
583
+ try {
584
+ boolean isUpdated = ContextSdk.updatedInboxMessage(messageId, type, userId, context);
585
+ callback.invoke(isUpdated);
586
+ } catch (Throwable e) {
587
+ callback.invoke(e.getMessage());
588
+ }
589
+ }
590
+
591
+
592
+ /**
593
+ * To sync with server if server will have any new data to update.
594
+ *
595
+ * @param timeout - integer value for status
596
+ * @callback will have the boolean
597
+ */
598
+ @ReactMethod
599
+ public void synchronizeInbox(int timeout, final Callback callback) {
600
+ Context context = getReactApplicationContext();
601
+ try {
602
+ ContextSdk.synchronizeInbox(new IAppICESuccessCallback() {
603
+ @Override
604
+ public void callback(boolean isAppInboxRefreshed) {
605
+ callback.invoke(isAppInboxRefreshed);
606
+ }
607
+ }, timeout, context);
608
+ } catch (Throwable e) {
609
+ callback.invoke(e.getMessage());
610
+ }
611
+ }
612
+
613
+ //===========================================
614
+ // Device Setting
615
+ //===========================================
616
+
617
+ /**
618
+ * To set the custom device_id.
619
+ */
620
+ @ReactMethod
621
+ public void setInternalId(String deviceId) {
622
+ //TODO{ we can not call setDevice Id here because it
623
+ // will directly call start context with new device id
624
+ // but here we want to store the data only
625
+ // }
626
+ //ContextSdk.setInternalId();
627
+ }
628
+
629
+ /**
630
+ * To get the ad_id from sdk.
631
+ *
632
+ * @callback will have the string
633
+ */
634
+ @ReactMethod
635
+ public void getDeviceId(Callback callback) {
636
+ Context context = getReactApplicationContext();
637
+ callback.invoke(ContextSdk.getInternalId(context));
638
+ }
639
+ @ReactMethod
640
+ public void isDeviceReady(Boolean flag){
641
+
642
+ }
643
+
644
+ @Nullable
645
+ @Override
646
+ public Map<String, Object> getConstants() {
647
+ final Map<String, Object> constants = new HashMap<>();
648
+ constants.put(EnumConstants.APPICE_USER_NAME.getConstants(), EnumConstants.APPICE_USER_NAME.getValue());
649
+ constants.put(EnumConstants.APPICE_USER_PHONE.getConstants(), EnumConstants.APPICE_USER_PHONE.getValue());
650
+ constants.put(EnumConstants.APPICE_USER_EMAIL.getConstants(), EnumConstants.APPICE_USER_EMAIL.getValue());
651
+ constants.put(EnumConstants.APPICE_DATE_OF_BIRTH.getConstants(), EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
652
+ constants.put(EnumConstants.APPICE_USER_EDUCATION_TYPE.getConstants(), EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
653
+ constants.put(EnumConstants.APPICE_USER_IS_EMPLOYED.getConstants(), EnumConstants.APPICE_USER_IS_EMPLOYED.getValue());
654
+ constants.put(EnumConstants.APPICE_USER_MARRIED.getConstants(), EnumConstants.APPICE_USER_MARRIED.getValue());
655
+ constants.put(EnumConstants.APPICE_USER_EDUCATION.getConstants(), EnumConstants.APPICE_USER_EDUCATION.getValue());
656
+ constants.put(EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getConstants(), EnumConstants.APPICE_USER_EMPLOYMENT_TYPE.getValue());
657
+ constants.put(EnumConstants.APPICE_USER_AGE.getConstants(), EnumConstants.APPICE_USER_AGE.getValue());
658
+ constants.put(EnumConstants.APPICE_USER_GENDER.getConstants(), EnumConstants.APPICE_USER_GENDER.getValue());
659
+ constants.put(EnumConstants.APPICE_PUSH_NOTIFICATION_CLICKED.getConstants(), EnumConstants.APPICE_PUSH_NOTIFICATION_CLICKED.getValue());
660
+ constants.put(EnumConstants.APPICE_INAPP_NOTIFICATION_CLICKED.getConstants(), EnumConstants.APPICE_INAPP_NOTIFICATION_CLICKED.getValue());
661
+ constants.put(EnumConstants.FIRST_SEEN.getConstants(), EnumConstants.FIRST_SEEN.getValue());
662
+ constants.put(EnumConstants.LAST_SEEN.getConstants(), EnumConstants.LAST_SEEN.getValue());
663
+ constants.put(EnumConstants.TOP_N_PRODUCTS_VIEWED.getConstants(), EnumConstants.TOP_N_PRODUCTS_VIEWED.getValue());
664
+ constants.put(EnumConstants.N_COMPLAINTS_RAISED.getConstants(), EnumConstants.N_COMPLAINTS_RAISED.getValue());
665
+ constants.put(EnumConstants.PREF_LOGIN_DEVICE.getConstants(), EnumConstants.PREF_LOGIN_DEVICE.getValue());
666
+ constants.put(EnumConstants.REFERRAL_CAMPAIGN.getConstants(), EnumConstants.REFERRAL_CAMPAIGN.getValue());
667
+ constants.put(EnumConstants.DEMOGRAPHIC_INFO.getConstants(), EnumConstants.DEMOGRAPHIC_INFO.getValue());
668
+ constants.put(EnumConstants.TOTAL_ORDER_VALUE.getConstants(), EnumConstants.TOTAL_ORDER_VALUE.getValue());
669
+ constants.put(EnumConstants.ADD_TO_CART_N_DAYS.getConstants(), EnumConstants.ADD_TO_CART_N_DAYS.getValue());
670
+ constants.put(EnumConstants.FINANCIAL_SERVICES.getConstants(), EnumConstants.FINANCIAL_SERVICES.getValue());
671
+ constants.put(EnumConstants.CREDIT_SCORE.getConstants(), EnumConstants.CREDIT_SCORE.getValue());
672
+ constants.put(EnumConstants.DEBT_TO_INCOME_RATIO.getConstants(), EnumConstants.DEBT_TO_INCOME_RATIO.getValue());
673
+ constants.put(EnumConstants.SAVINGS_BALANCE.getConstants(), EnumConstants.SAVINGS_BALANCE.getValue());
674
+ constants.put(EnumConstants.CHECKING_BALANCE.getConstants(), EnumConstants.CHECKING_BALANCE.getValue());
675
+ constants.put(EnumConstants.AVERAGE_TRANSACTION_AMOUNT.getConstants(), EnumConstants.AVERAGE_TRANSACTION_AMOUNT.getValue());
676
+ constants.put(EnumConstants.FREQUENCY_OF_TRANSACTION.getConstants(), EnumConstants.FREQUENCY_OF_TRANSACTION.getValue());
677
+ constants.put(EnumConstants.TYPE_OF_TRANSACTION.getConstants(), EnumConstants.TYPE_OF_TRANSACTION.getValue());
678
+ constants.put(EnumConstants.CAMP_ID.getConstants(), EnumConstants.CAMP_ID.getValue());
679
+ constants.put(EnumConstants.ACTION_URL.getConstants(), EnumConstants.ACTION_URL.getValue());
680
+ constants.put(EnumConstants.ACTION_TYPE.getConstants(), EnumConstants.ACTION_TYPE.getValue());
681
+ constants.put(EnumConstants.CUSTOMDATA.getConstants(), EnumConstants.CUSTOMDATA.getValue());
682
+
683
+ return constants;
684
+ }
685
+
686
+ //=====================================
687
+ public static void sendEvent(String eventName, @Nullable WritableMap params) {
688
+ try {
689
+ context.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
690
+ } catch (RuntimeException e) {
691
+ AppICEUtils.printLog(TAG, "java.lang.RuntimeException: Trying to invoke JS before CatalystInstance has been set!" + e);
692
+ }
693
+ }
694
+ private static AppICEInboxMessage getMediaPreProcessing(ReadableMap inboxMessage,Context context) {
695
+ AppICEInboxMessage appICEInboxMessage = null;
696
+ JSONObject inboxJSON = AppICEUtils.toJSONObject(inboxMessage);
697
+ if (inboxJSON != null && inboxJSON.length()>0) {
698
+ appICEInboxMessage = AppICEInboxMessage.getAppICEInboxMessage(inboxJSON.toString(), context);
699
+ if (appICEInboxMessage != null) {
700
+ return appICEInboxMessage;
701
+ }
702
+ }
703
+ return appICEInboxMessage;
704
+ }
705
+
706
+ public static void getMediaApiHelper(ReadableMap inboxMessage, ReadableMap mediaData, String type, String mediayKey, Callback callback, Context context){
707
+
708
+ AppICEInboxMessage appICEInboxMessage = getMediaPreProcessing(inboxMessage, context);
709
+ if (appICEInboxMessage != null) {
710
+ switch (type) {
711
+ case "mediaType": {
712
+ if (mediaData != null){
713
+ String mediaType = appICEInboxMessage.getMediaType(AppICEUtils.eventPropsFromReadableMap(mediaData));
714
+ callback.invoke(mediaType, null);
715
+ }else
716
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
717
+ break;
718
+ }
719
+
720
+ case "mediaUrl": {
721
+ if (mediaData != null) {
722
+ String mediaUrl = appICEInboxMessage.getMediaUrl(AppICEUtils.eventPropsFromReadableMap(mediaData));
723
+ callback.invoke(mediaUrl, null);
724
+ }else
725
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
726
+ break;
727
+ }
728
+
729
+ case "mediaThumbnail": {
730
+ if (mediaData != null) {
731
+ String mediaThumbnail = appICEInboxMessage.getMediaThumbnail(AppICEUtils.eventPropsFromReadableMap(mediaData));
732
+ callback.invoke(mediaThumbnail, null);
733
+ }else
734
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
735
+ break;
736
+ }
737
+
738
+ case "mediaData":{
739
+ if (mediayKey != null) {
740
+ Map<String, Object> map = appICEInboxMessage.getMediaData(mediayKey);
741
+ if (map != null) {
742
+ callback.invoke(AppICEUtils.toWritableMap(map), null);
743
+ } else {
744
+ callback.invoke(null, StringConstants.FAILED_RETRIVE_MEDIA_DATA);
745
+ }
746
+ }else{
747
+ callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
748
+ }
749
+ }
750
+ }
751
+ }else {
752
+ callback.invoke(null, StringConstants.INVALID_INBOX_FORMAT);
753
+ }
754
+ }
755
+
756
+ @ReactMethod
757
+ public void getCampaigns(String type, Callback callback) {
758
+ Context context = getReactApplicationContext();
759
+ WritableArray writableArray = Arguments.createArray();
760
+ try{
761
+ List<Campaign> campaigns = ContextSdk.getCampaigns(type, context);
762
+ for (int i = 0; i < campaigns.size(); i++) {
763
+ Campaign campaign = campaigns.get(i);
764
+ writableArray.pushMap(AppICEUtils.convertClassToWritableMap(campaign));
765
+ }
766
+ callback.invoke(writableArray);
767
+ }
768
+ catch(Throwable e){
769
+ callback.invoke(e.getMessage());
770
+ }
771
+ }
772
+
773
+ @ReactMethod
774
+ public void getCampaignById(String cmpId,Callback callback) {
775
+ Context context = getReactApplicationContext();
776
+ Campaign campaign = ContextSdk.getCampaignById(cmpId, context);
777
+ callback.invoke(AppICEUtils.convertClassToWritableMap(campaign));
778
+ }
779
779
  }