reactnative-plugin-appice 1.7.0 → 1.7.3

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 +151 -152
  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 -196
  10. package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +697 -697
  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 -4
  16. package/example/App.js +310 -310
  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 -53
  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,698 +1,698 @@
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
- }
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
+ }
698
698
  }