reactnative-plugin-appice 1.7.14 → 1.7.16
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.
- package/README.md +37 -37
- package/android/README.md +14 -14
- package/android/build.gradle +153 -151
- package/android/gitignore +47 -47
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -5
- package/android/gradlew +234 -234
- package/android/local.properties +8 -8
- package/android/src/main/AndroidManifest.xml +153 -153
- package/android/src/main/java/com/reactlibrary/AppICEUtils.java +241 -241
- package/android/src/main/java/com/reactlibrary/AppIceReactPluginModule.java +748 -748
- package/android/src/main/java/com/reactlibrary/AppIceReactPluginPackage.java +28 -28
- package/android/src/main/java/com/reactlibrary/CampaignCampsReceiver.java +56 -56
- package/android/src/main/java/com/reactlibrary/EnumConstants.java +256 -256
- package/android/src/main/java/com/reactlibrary/NotificationEventService.java +59 -59
- package/android/src/main/java/com/reactlibrary/StringConstants.java +9 -9
- package/example/App.js +292 -292
- package/example/Gemfile +6 -6
- package/example/__tests__/App-test.js +14 -14
- package/example/ancilliary.js +484 -474
- package/example/android/app/_BUCK +55 -55
- package/example/android/app/build.gradle +320 -320
- package/example/android/app/build_defs.bzl +19 -19
- package/example/android/app/proguard-rules.pro +10 -10
- package/example/android/app/src/debug/AndroidManifest.xml +13 -13
- package/example/android/app/src/debug/java/com/example/ReactNativeFlipper.java +73 -73
- package/example/android/app/src/main/AndroidManifest.xml +72 -72
- package/example/android/app/src/main/java/com/example/MainActivity.java +48 -48
- package/example/android/app/src/main/java/com/example/MainApplication.java +91 -91
- package/example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java +116 -116
- package/example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java +36 -36
- package/example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java +48 -48
- package/example/android/app/src/main/jni/Android.mk +48 -48
- package/example/android/app/src/main/jni/MainApplicationModuleProvider.cpp +24 -24
- package/example/android/app/src/main/jni/MainApplicationModuleProvider.h +16 -16
- package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp +45 -45
- package/example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h +38 -38
- package/example/android/app/src/main/jni/MainComponentsRegistry.cpp +61 -61
- package/example/android/app/src/main/jni/MainComponentsRegistry.h +32 -32
- package/example/android/app/src/main/jni/OnLoad.cpp +11 -11
- package/example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -36
- package/example/android/app/src/main/res/values/strings.xml +3 -3
- package/example/android/app/src/main/res/values/styles.xml +9 -9
- package/example/android/build.gradle +73 -73
- package/example/android/gradle/wrapper/gradle-wrapper.properties +5 -5
- package/example/android/gradle.properties +40 -40
- package/example/android/gradlew +234 -234
- package/example/android/local.properties +8 -0
- package/example/android/settings.gradle +11 -11
- package/example/app.json +3 -3
- package/example/babel.config.js +3 -3
- package/example/index.js +9 -9
- package/example/ios/Podfile +44 -44
- package/example/ios/Podfile.lock +561 -561
- package/example/ios/_xcode.env +11 -11
- package/example/ios/example/AppDelegate.h +8 -8
- package/example/ios/example/AppDelegate.mm +174 -174
- package/example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json +53 -53
- package/example/ios/example/Images.xcassets/Contents.json +6 -6
- package/example/ios/example/Info.plist +62 -62
- package/example/ios/example/LaunchScreen.storyboard +47 -47
- package/example/ios/example/example.entitlements +8 -8
- package/example/ios/example/main.m +10 -10
- package/example/ios/example.xcodeproj/project.pbxproj +712 -712
- package/example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme +88 -88
- package/example/ios/example.xcworkspace/contents.xcworkspacedata +10 -10
- package/example/ios/example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/example/ios/exampleTests/Info.plist +24 -24
- package/example/ios/exampleTests/exampleTests.m +66 -66
- package/example/metro.config.js +17 -17
- package/example/package.json +36 -36
- package/example/yarn.lock +7713 -7176
- package/index.js +520 -485
- package/ios/AppICEReactEvent.h +23 -23
- package/ios/AppICEReactEvent.m +86 -86
- package/ios/AppIceReactPlugin.h +59 -59
- package/ios/AppIceReactPlugin.m +641 -641
- package/ios/AppIceReactPlugin.xcodeproj/project.pbxproj +364 -364
- package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -4
- package/ios/AppIceReactPlugin.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/ios/AppIceReactPlugin.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/ios/AppIceReactPlugin.xcworkspace/contents.xcworkspacedata +10 -10
- package/ios/AppIceReactPlugin.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -8
- package/ios/Podfile +10 -10
- package/ios/Podfile.lock +3 -3
- package/ios/Pods/Manifest.lock +3 -3
- package/ios/Pods/Pods.xcodeproj/project.pbxproj +395 -395
- package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/Pods-AppIceReactPlugin.xcscheme +58 -58
- package/ios/Pods/Pods.xcodeproj/xcuserdata/Adi.xcuserdatad/xcschemes/xcschememanagement.plist +18 -18
- package/ios/Pods/Pods.xcodeproj/xcuserdata/artherajesh.xcuserdatad/xcschemes/xcschememanagement.plist +14 -14
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-Info.plist +26 -26
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.markdown +3 -3
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-acknowledgements.plist +29 -29
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-dummy.m +5 -5
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin-umbrella.h +16 -16
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.debug.xcconfig +6 -6
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.modulemap +6 -6
- package/ios/Pods/Target Support Files/Pods-AppIceReactPlugin/Pods-AppIceReactPlugin.release.xcconfig +6 -6
- package/package.json +41 -41
- package/reactnative-plugin-appice.podspec +30 -30
- package/example/android/.gradle/7.3.3/checksums/checksums.lock +0 -0
- package/example/android/.gradle/7.3.3/fileChanges/last-build.bin +0 -0
- package/example/android/.gradle/7.3.3/fileHashes/fileHashes.lock +0 -0
- package/example/android/.gradle/vcs-1/gc.properties +0 -0
- /package/{example/android/.gradle/7.3.3/gc.properties → android/src/main/test} +0 -0
|
@@ -1,749 +1,749 @@
|
|
|
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 dob = map.get(EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
|
|
247
|
-
if (dob != null) {
|
|
248
|
-
user.setDob((Integer) dob);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
} catch (Exception e) {
|
|
252
|
-
AppICEUtils.printLog(TAG, "setUser: dob issue " + e.getMessage());
|
|
253
|
-
}
|
|
254
|
-
try {
|
|
255
|
-
if (map.containsKey(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue())) {
|
|
256
|
-
Object edt = map.get(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
|
|
257
|
-
if (edt != null) {
|
|
258
|
-
user.setEducationType(edt.toString());
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
} catch (Exception e) {
|
|
262
|
-
AppICEUtils.printLog(TAG, "setEducationType: edt issue " + e.getMessage());
|
|
263
|
-
}
|
|
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
|
+
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 dob = map.get(EnumConstants.APPICE_DATE_OF_BIRTH.getValue());
|
|
247
|
+
if (dob != null) {
|
|
248
|
+
user.setDob((Integer) dob);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
} catch (Exception e) {
|
|
252
|
+
AppICEUtils.printLog(TAG, "setUser: dob issue " + e.getMessage());
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
if (map.containsKey(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue())) {
|
|
256
|
+
Object edt = map.get(EnumConstants.APPICE_USER_EDUCATION_TYPE.getValue());
|
|
257
|
+
if (edt != null) {
|
|
258
|
+
user.setEducationType(edt.toString());
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} catch (Exception e) {
|
|
262
|
+
AppICEUtils.printLog(TAG, "setEducationType: edt issue " + e.getMessage());
|
|
263
|
+
}
|
|
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
|
+
}
|
|
749
749
|
}
|