reactnative-plugin-appice 1.7.7 → 1.7.10

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