@customerglu/react-native-customerglu 1.1.1 → 1.2.1

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.
@@ -14,10 +14,14 @@ import android.graphics.Color;
14
14
  import android.net.Uri;
15
15
  import android.os.Bundle;
16
16
  import android.util.Log;
17
+ import android.widget.Toast;
17
18
 
18
19
  import androidx.annotation.NonNull;
19
20
 
21
+ import com.customerglu.sdk.Interface.CGDeepLinkListener;
22
+ import com.customerglu.sdk.Modal.DeepLinkWormholeModel;
20
23
  import com.customerglu.sdk.Modal.NudgeConfiguration;
24
+ import com.customerglu.sdk.Utils.CGConstants;
21
25
  import com.customerglu.sdk.Utils.Comman;
22
26
  import com.facebook.react.bridge.LifecycleEventListener;
23
27
  import com.facebook.react.bridge.WritableArray;
@@ -42,6 +46,7 @@ import com.google.gson.Gson;
42
46
  import org.json.JSONArray;
43
47
  import org.json.JSONException;
44
48
  import org.json.JSONObject;
49
+ import org.json.JSONTokener;
45
50
 
46
51
  import java.net.MalformedURLException;
47
52
  import java.util.ArrayList;
@@ -53,719 +58,859 @@ import java.util.Map;
53
58
 
54
59
 
55
60
  @ReactModule(name = RncustomergluModule.NAME)
56
- public class RncustomergluModule extends ReactContextBaseJavaModule implements LifecycleEventListener
57
- {
58
- public static final String TAG = RncustomergluModule.class.getName();
59
- public static String Myclassname = "";
60
- public static final String NAME = "Rncustomerglu";
61
- private static ReactApplicationContext mContext;
62
-
63
-
64
- public RncustomergluModule(ReactApplicationContext reactContext) {
65
- super(reactContext);
66
- mContext = reactContext;
67
- reactContext.addLifecycleEventListener(this);
68
- CustomerGlu.initializeSdk(getReactApplicationContext());
69
- setPlatformAndSdkVersion();
70
- }
71
- @ReactMethod
72
- public void addListener(String eventName) {
73
- }
74
- @ReactMethod
75
- public void removeListeners(Integer count) {
76
- }
77
-
78
- private void setPlatformAndSdkVersion() {
79
- if(CustomerGlu.getInstance()!=null){
80
-
81
- CustomerGlu.cg_sdk_version="1.1.1";
82
- CustomerGlu.cg_app_platform="REACT_NATIVE";
83
- }
84
- }
85
-
86
-
87
- private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
88
- @Override
89
- public void onReceive(Context context, Intent intent) {
90
- Log.d(TAG,"on Received....");
91
- try {
92
- if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_ANALYTICS_EVENT")) {
93
- /* If you want to listen CUSTOMERGLU_ANALYTICS_EVENT */
94
- if (intent.getStringExtra("data") != null) {
95
- String data = intent.getStringExtra("data");
96
- JSONObject jsonObject = new JSONObject(data);
97
- WritableMap map = jsonToWritableMap(jsonObject);
98
- sendEventToJs("CUSTOMERGLU_ANALYTICS_EVENT", map);
99
- }
61
+ public class RncustomergluModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
62
+ public static final String TAG = RncustomergluModule.class.getName();
63
+ public static String Myclassname = "";
64
+ public static final String NAME = "Rncustomerglu";
65
+ private static ReactApplicationContext mContext;
66
+
67
+
68
+ public RncustomergluModule(ReactApplicationContext reactContext) {
69
+ super(reactContext);
70
+ mContext = reactContext;
71
+ reactContext.addLifecycleEventListener(this);
72
+ CustomerGlu.initializeSdk(getReactApplicationContext());
73
+ setPlatformAndSdkVersion();
74
+ }
75
+
76
+ @ReactMethod
77
+ public void addListener(String eventName) {
78
+ }
79
+
80
+ @ReactMethod
81
+ public void removeListeners(Integer count) {
82
+ }
83
+
84
+ private void setPlatformAndSdkVersion() {
85
+ if (CustomerGlu.getInstance() != null) {
86
+
87
+ CustomerGlu.cg_sdk_version = "1.2.0";
88
+ CustomerGlu.cg_app_platform = "REACT_NATIVE";
100
89
  }
90
+ }
101
91
 
102
- /* If you want to listen CUSTOMERGLU_DEEPLINK_EVENT */
103
92
 
104
- if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_DEEPLINK_EVENT")) {
105
- if (intent.getStringExtra("data") != null) {
106
- String data = intent.getStringExtra("data");
107
- JSONObject jsonObject = new JSONObject(data);
108
- WritableMap map = jsonToWritableMap(jsonObject);
109
- sendEventToJs("CUSTOMERGLU_DEEPLINK_EVENT", map);
110
- }
93
+ private final BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
94
+ @Override
95
+ public void onReceive(Context context, Intent intent) {
96
+ Log.d(TAG, "on Received....");
97
+ try {
98
+ if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_ANALYTICS_EVENT")) {
99
+ /* If you want to listen CUSTOMERGLU_ANALYTICS_EVENT */
100
+ if (intent.getStringExtra("data") != null) {
101
+ String data = intent.getStringExtra("data");
102
+ JSONObject jsonObject = new JSONObject(data);
103
+ WritableMap map = jsonToWritableMap(jsonObject);
104
+ sendEventToJs("CUSTOMERGLU_ANALYTICS_EVENT", map);
105
+ }
106
+ }
107
+
108
+ /* If you want to listen CUSTOMERGLU_DEEPLINK_EVENT */
109
+
110
+ if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_DEEPLINK_EVENT")) {
111
+ if (intent.getStringExtra("data") != null) {
112
+ String data = intent.getStringExtra("data");
113
+ JSONObject jsonObject = new JSONObject(data);
114
+ WritableMap map = jsonToWritableMap(jsonObject);
115
+ sendEventToJs("CUSTOMERGLU_DEEPLINK_EVENT", map);
116
+ }
117
+ }
118
+
119
+
120
+ if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_BANNER_LOADED")) {
121
+ /* If you want to listen CUSTOMERGLU_BANNER_LOADED */
122
+ if (intent.getStringExtra("data") != null) {
123
+ String data = intent.getStringExtra("data");
124
+ JSONObject jsonObject = new JSONObject(data);
125
+ WritableMap map = jsonToWritableMap(jsonObject);
126
+ sendEventToJs("CUSTOMERGLU_BANNER_LOADED", map);
127
+ }
128
+ }
129
+
130
+ if (intent.getAction().equalsIgnoreCase("CG_INVALID_CAMPAIGN_ID")) {
131
+ /* If you want to listen CG_INVALID_CAMPAIGN_ID */
132
+ if (intent.getStringExtra("data") != null) {
133
+ String data = intent.getStringExtra("data");
134
+ JSONObject jsonObject = new JSONObject(data);
135
+ WritableMap map = jsonToWritableMap(jsonObject);
136
+ sendEventToJs("CG_INVALID_CAMPAIGN_ID", map);
137
+ }
138
+ }
139
+
140
+
141
+
142
+ } catch (Exception e) {
143
+ System.out.println(e);
144
+ }
111
145
  }
112
146
 
147
+ };
113
148
 
149
+ private void registerBroadcastReceiver() {
150
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_ANALYTICS_EVENT"));
151
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_DEEPLINK_EVENT"));
152
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_BANNER_LOADED"));
153
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CG_INVALID_CAMPAIGN_ID"));
114
154
 
155
+ }
115
156
 
116
- if (intent.getAction().equalsIgnoreCase("CUSTOMERGLU_BANNER_LOADED")) {
117
- /* If you want to listen CUSTOMERGLU_BANNER_LOADED */
118
- if (intent.getStringExtra("data") != null) {
119
- String data = intent.getStringExtra("data");
120
- JSONObject jsonObject = new JSONObject(data);
121
- WritableMap map = jsonToWritableMap(jsonObject);
122
- sendEventToJs("CUSTOMERGLU_BANNER_LOADED", map);
123
- }
157
+
158
+ private void sendEventToJs(String eventName, WritableMap map) {
159
+ try {
160
+ getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
161
+ .emit(eventName, map);
162
+ } catch (Exception e) {
124
163
  }
125
164
 
126
- if (intent.getAction().equalsIgnoreCase("CG_INVALID_CAMPAIGN_ID")) {
127
- /* If you want to listen CG_INVALID_CAMPAIGN_ID */
128
- if (intent.getStringExtra("data") != null) {
129
- String data = intent.getStringExtra("data");
130
- JSONObject jsonObject = new JSONObject(data);
131
- WritableMap map = jsonToWritableMap(jsonObject);
132
- sendEventToJs("CG_INVALID_CAMPAIGN_ID", map);
133
- }
165
+ }
166
+
167
+
168
+ @Override
169
+ @NonNull
170
+ public String getName() {
171
+ return NAME;
172
+ }
173
+
174
+ @Override
175
+ public void onHostResume() {
176
+ Log.e(TAG, "On Host Resume....");
177
+ CustomerGlu.getInstance().showEntryPoint(getReactApplicationContext().getCurrentActivity());
178
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_ANALYTICS_EVENT"));
179
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_DEEPLINK_EVENT"));
180
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_BANNER_LOADED"));
181
+ mContext.registerReceiver(mMessageReceiver, new IntentFilter("CG_INVALID_CAMPAIGN_ID"));
182
+ CustomerGlu.getInstance().setCgDeepLinkListener(new CGDeepLinkListener() {
183
+ @Override
184
+ public void onSuccess(CGConstants.CGSTATE message, DeepLinkWormholeModel.DeepLinkData deepLinkData) {
185
+ JSONObject jsonObject = null;
186
+ try {
187
+ if (message.equals(CGConstants.CGSTATE.DEEPLINK_URL)) {
188
+ String url = "";
189
+ if (deepLinkData.getContent().getUrl() != null) {
190
+ url = deepLinkData.getContent().getUrl();
191
+ Log.e("DeepLink URL", "Success " + message);
192
+ }
193
+ // Add your logic
194
+ }
195
+ Log.e("Onelink", "Success " + message);
196
+ jsonObject = new JSONObject();
197
+ jsonObject.put("status",message.toString());
198
+ Gson gson = new Gson();
199
+ String json = gson.toJson(deepLinkData);
200
+ JSONObject mJSONObject = new JSONObject(json);
201
+ jsonObject.put("data",mJSONObject);
202
+
203
+ Log.e("Onelink2", "Success " + jsonObject);
204
+ // Intent intent = new Intent("CG_UNI_DEEPLINK_EVENT");
205
+ // intent.putExtra("data", jsonObject.toString());
206
+ // context.sendBroadcast(intent);
207
+
208
+ WritableMap map = jsonToWritableMap(jsonObject);
209
+ sendEventToJs("CG_UNI_DEEPLINK_EVENT", map);
210
+
211
+ Log.e("Onelink4", "Success " + message);
212
+ }catch (Exception e)
213
+ {
214
+ Log.e("Onelink ex ",e.toString());
215
+ }
216
+ }
217
+
218
+ @Override
219
+ public void onFailure(CGConstants.CGSTATE exceptions) {
220
+ try {
221
+ Log.e("Onelink", "Success " + exceptions);
222
+ JSONObject jsonObject = new JSONObject();
223
+ jsonObject.put("status", exceptions.toString());
224
+
225
+ JSONObject mJSONObject = new JSONObject();
226
+ jsonObject.put("data", mJSONObject);
227
+ WritableMap map = jsonToWritableMap(jsonObject);
228
+ sendEventToJs("CG_UNI_DEEPLINK_EVENT", map);
229
+
230
+ Log.e("Onelink2", "Success " + jsonObject);
231
+
232
+ //
233
+ // Intent intent = new Intent("CG_UNI_DEEPLINK_EVENT");
234
+ // intent.putExtra("data", jsonObject.toString());
235
+ // context.sendBroadcast(intent);
236
+ }catch (Exception e)
237
+ {
238
+ Log.e("Onelink ex ",e.toString());
239
+
240
+ }
241
+
242
+ }
243
+ });
244
+
245
+ }
246
+ @ReactMethod
247
+ public void handleDeepLinkUri(String urls){
248
+ if(urls!=null){
249
+ Uri uri = Uri.parse(urls);
250
+ Comman.handleDeepLinkUri(uri);}
251
+ else
252
+ {
253
+ JSONObject jsonObject = new JSONObject();
254
+ try {
255
+ jsonObject.put("status", "EXCEPTION");
256
+ JSONObject mJSONObject = new JSONObject();
257
+ jsonObject.put("data", mJSONObject);
258
+ WritableMap map = jsonToWritableMap(jsonObject);
259
+ sendEventToJs("CG_UNI_DEEPLINK_EVENT", map);
260
+ } catch (JSONException e) {
261
+ e.printStackTrace();
262
+ }
263
+
264
+
134
265
  }
266
+ }
135
267
 
268
+ @Override
269
+ public void onHostPause() {
270
+ // mContext.unregisterReceiver(mMessageReceiver);
271
+ }
136
272
 
273
+ @Override
274
+ public void onHostDestroy() {
275
+ // mContext.unregisterReceiver(mMessageReceiver);
137
276
 
138
- } catch (Exception e) {
139
- System.out.println(e);
140
- }
141
277
  }
142
278
 
143
- };
279
+ // Example method
280
+ // See https://reactnative.dev/docs/native-modules-android
281
+
282
+
283
+ @ReactMethod
284
+ public void registerDevice(ReadableMap map, Promise promise) {
285
+ if (map != null) {
286
+ JSONObject jsonObject = convertMapToJson(map);
287
+ HashMap<String, Object> userData = new Gson().fromJson(jsonObject.toString(), HashMap.class);
288
+ Log.d(TAG, "userdata----> " + userData.toString() + " " + new Date().getTime());
289
+
290
+ CustomerGlu.getInstance().registerDevice(getReactApplicationContext(), userData, new DataListner() {
291
+ //this method registers the user
292
+ @Override
293
+ public void onSuccess(RegisterModal registerModal) {
294
+ // Toast.makeText(getReactApplicationContext(), "Registered", Toast.LENGTH_SHORT).show();
144
295
 
145
- private void registerBroadcastReceiver() {
146
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_ANALYTICS_EVENT"));
147
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_DEEPLINK_EVENT"));
148
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_BANNER_LOADED"));
149
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CG_INVALID_CAMPAIGN_ID"));
296
+ RegisterModal remodal = registerModal;
297
+ Log.d(TAG, "Registered!..." + " " + new Date().getTime());
298
+ promise.resolve(true);
150
299
 
151
- }
152
300
 
301
+ }
302
+
303
+ @Override
304
+ public void onFail(String message) {
305
+ // Toast.makeText(getReactApplicationContext(), "" + message, Toast.LENGTH_SHORT).show();
306
+ Log.d(TAG, "Registeration Failed!..." + message.toString());
307
+
308
+ promise.resolve(false);
309
+
310
+ }
311
+ });
312
+ }
153
313
 
154
- private void sendEventToJs(String eventName, WritableMap map) {
155
- try {
156
- getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
157
- .emit(eventName, map);
158
- } catch (Exception e) {
159
314
  }
160
315
 
161
- }
316
+ @ReactMethod
317
+ public void dataClear() {
318
+ CustomerGlu.getInstance().clearGluData(getCurrentActivity());
319
+ }
162
320
 
321
+ @ReactMethod
322
+ public void sendData(ReadableMap readableMap) {
323
+ Log.e(TAG, "rereadableMapquest----- " + readableMap);
324
+ if (readableMap != null) {
325
+ try {
326
+ String evnt = "";
327
+ JSONObject obj = convertMapToJson(readableMap);
328
+ Log.e(TAG, "request----- " + obj);
329
+ if (obj.has("eventName")) {
330
+ evnt = (String) obj.get("eventName");
331
+ }
332
+ if (obj.has("eventProperties")) {
333
+ Object eventProperties = obj.get("eventProperties");
334
+ if (eventProperties instanceof JSONObject) {
335
+ Log.e(TAG, "data>>>>>----- " + (JSONObject) eventProperties);
336
+ CustomerGlu.getInstance().sendEvent(getReactApplicationContext(), evnt, jsonToMap((JSONObject) eventProperties));
337
+ }
338
+ } else {
339
+ Map<String, Object> s = new HashMap<>();
340
+ CustomerGlu.getInstance().sendEvent(getReactApplicationContext(), evnt, s);
341
+ }
342
+ } catch (JSONException e) {
343
+ e.printStackTrace();
344
+ }
345
+ }
163
346
 
164
- @Override
165
- @NonNull
166
- public String getName() {
167
- return NAME;
168
- }
347
+ }
169
348
 
170
- @Override
171
- public void onHostResume() {
172
- Log.e(TAG,"On Host Resume....");
173
- CustomerGlu.getInstance().showEntryPoint(getReactApplicationContext().getCurrentActivity());
174
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_ANALYTICS_EVENT"));
175
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_DEEPLINK_EVENT"));
176
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CUSTOMERGLU_BANNER_LOADED"));
177
- mContext.registerReceiver(mMessageReceiver, new IntentFilter("CG_INVALID_CAMPAIGN_ID"));
349
+ public static Map<String, Object> jsonToMap(JSONObject json) throws JSONException {
350
+ Map<String, Object> retMap = new HashMap<String, Object>();
351
+ if (json != JSONObject.NULL) {
352
+ retMap = toMap(json);
353
+ }
354
+ return retMap;
355
+ }
178
356
 
179
- }
357
+ public static Map<String, Object> toMap(JSONObject object) throws JSONException {
358
+ Map<String, Object> map = new HashMap<String, Object>();
359
+ Iterator<String> keysItr = object.keys();
360
+ while (keysItr.hasNext()) {
361
+ String key = keysItr.next();
362
+ Object value = object.get(key);
363
+
364
+ if (value instanceof JSONArray) {
365
+ value = toList((JSONArray) value);
366
+ } else if (value instanceof JSONObject) {
367
+ value = toMap((JSONObject) value);
368
+ }
369
+ map.put(key, value);
370
+ }
371
+ return map;
372
+ }
180
373
 
181
- @Override
182
- public void onHostPause() {
183
- // mContext.unregisterReceiver(mMessageReceiver);
184
- }
374
+ public static List<Object> toList(JSONArray array) throws JSONException {
375
+ List<Object> list = new ArrayList<Object>();
376
+ for (int i = 0; i < array.length(); i++) {
377
+ Object value = array.get(i);
378
+ if (value instanceof JSONArray) {
379
+ value = toList((JSONArray) value);
380
+ } else if (value instanceof JSONObject) {
381
+ value = toMap((JSONObject) value);
382
+ }
383
+ list.add(value);
384
+ }
385
+ return list;
386
+ }
185
387
 
186
- @Override
187
- public void onHostDestroy() {
188
- // mContext.unregisterReceiver(mMessageReceiver);
388
+ @ReactMethod
389
+ public void openWallet(ReadableMap readableMap) {
390
+ try {
391
+ if (readableMap.hasKey("nudgeConfiguration")) {
392
+ Log.e(TAG, "openwallet-----" + readableMap.toString());
393
+
394
+ JSONObject nudgeConfigurationdata;
395
+ NudgeConfiguration nudgeConfiguration = new NudgeConfiguration();
396
+ JSONObject obj = convertMapToJson(readableMap);
397
+ nudgeConfigurationdata = obj.getJSONObject("nudgeConfiguration");
398
+ if (nudgeConfigurationdata.has("layout")) {
399
+ nudgeConfiguration.setLayout(nudgeConfigurationdata.getString("layout"));
400
+ }
401
+ if (nudgeConfigurationdata.has("opacity")) {
402
+ nudgeConfiguration.setOpacity(Double.parseDouble(nudgeConfigurationdata.getString("opacity")));
403
+ }
404
+ if (nudgeConfigurationdata.has("closeOnDeepLink")) {
405
+ nudgeConfiguration.setCloseOnDeepLink(nudgeConfigurationdata.getBoolean("closeOnDeepLink"));
406
+ }
407
+ if (nudgeConfigurationdata.has("absoluteHeight")) {
408
+ nudgeConfiguration.setAbsoluteHeight(Double.parseDouble(nudgeConfigurationdata.getString("absoluteHeight")));
409
+ }
410
+ if (nudgeConfigurationdata.has("relativeHeight")) {
411
+ nudgeConfiguration.setRelativeHeight(Double.parseDouble(nudgeConfigurationdata.getString("relativeHeight")));
412
+ }
413
+ CustomerGlu.getInstance().openWallet(getReactApplicationContext(), nudgeConfiguration);
414
+
415
+
416
+ } else {
417
+ CustomerGlu.getInstance().openWallet(getReactApplicationContext());
418
+ }
419
+ } catch (JSONException e) {
420
+ e.printStackTrace();
421
+ }
422
+ }
189
423
 
190
- }
191
424
 
192
- // Example method
193
- // See https://reactnative.dev/docs/native-modules-android
425
+ @ReactMethod
426
+ public void loadCampaignById(String id, ReadableMap readableMap) {
427
+ Log.e(TAG, "loadCampaignById-----" + readableMap.toString());
428
+ try {
429
+ JSONObject nudgeConfigurationdata;
430
+ NudgeConfiguration nudgeConfiguration = new NudgeConfiguration();
431
+ if (readableMap.hasKey("nudgeConfiguration")) {
432
+ JSONObject obj = convertMapToJson(readableMap);
433
+ nudgeConfigurationdata = obj.getJSONObject("nudgeConfiguration");
434
+ if (nudgeConfigurationdata.has("layout")) {
435
+ nudgeConfiguration.setLayout(nudgeConfigurationdata.getString("layout"));
436
+ }
437
+ if (nudgeConfigurationdata.has("opacity")) {
438
+ nudgeConfiguration.setOpacity(Double.parseDouble(nudgeConfigurationdata.getString("opacity")));
439
+ }
440
+ if (nudgeConfigurationdata.has("closeOnDeepLink")) {
441
+ nudgeConfiguration.setCloseOnDeepLink(nudgeConfigurationdata.getBoolean("closeOnDeepLink"));
442
+ }
443
+ if (nudgeConfigurationdata.has("absoluteHeight")) {
444
+ nudgeConfiguration.setAbsoluteHeight(Double.parseDouble(nudgeConfigurationdata.getString("absoluteHeight")));
445
+ }
446
+ if (nudgeConfigurationdata.has("relativeHeight")) {
447
+ nudgeConfiguration.setRelativeHeight(Double.parseDouble(nudgeConfigurationdata.getString("relativeHeight")));
448
+ }
449
+ CustomerGlu.getInstance().loadCampaignById(getReactApplicationContext(), id, nudgeConfiguration);
450
+ } else {
451
+ CustomerGlu.getInstance().loadCampaignById(getReactApplicationContext(), id);
452
+ }
453
+ } catch (JSONException e) {
454
+ e.printStackTrace();
455
+ }
194
456
 
195
457
 
458
+ }
196
459
 
197
- @ReactMethod
198
- public void registerDevice(ReadableMap map, Promise promise) {
199
- JSONObject jsonObject = convertMapToJson(map);
200
- HashMap<String, Object> userData = new Gson().fromJson(jsonObject.toString(), HashMap.class);
201
- Log.d(TAG, "userdata----> " + userData.toString()+" "+new Date().getTime());
460
+ @ReactMethod
461
+ public void enableAnalytic(Boolean bool) {
462
+ CustomerGlu.getInstance().enableAnalyticsEvent(bool);
463
+ }
202
464
 
203
- CustomerGlu.getInstance().registerDevice(getReactApplicationContext(), userData, new DataListner() {
204
- //this method registers the user
205
- @Override
206
- public void onSuccess(RegisterModal registerModal) {
207
- // Toast.makeText(getReactApplicationContext(), "Registered", Toast.LENGTH_SHORT).show();
208
465
 
209
- RegisterModal remodal = registerModal;
210
- Log.d(TAG,"Registered!..."+" "+new Date().getTime());
211
- promise.resolve(true);
466
+ @ReactMethod
467
+ public void disableGluSdk(Boolean bool) {
468
+ CustomerGlu.getInstance().disableGluSdk(bool);
212
469
 
470
+ }
213
471
 
214
- }
472
+ @ReactMethod
473
+ public void configureLoaderColour(String color) {
474
+ CustomerGlu.getInstance().configureLoaderColour(getReactApplicationContext(), color);
475
+ }
215
476
 
216
- @Override
217
- public void onFail(String message) {
218
- // Toast.makeText(getReactApplicationContext(), "" + message, Toast.LENGTH_SHORT).show();
219
- Log.d(TAG,"Registeration Failed!..."+message.toString());
220
-
221
- promise.resolve(false);
222
-
223
- }
224
- });
225
-
226
- }
227
-
228
- @ReactMethod
229
- public void dataClear()
230
- {
231
- CustomerGlu.getInstance().clearGluData(getCurrentActivity());
232
- }
233
-
234
- @ReactMethod
235
- public void sendData(ReadableMap readableMap) {
236
- try {
237
- String evnt="";
238
- JSONObject obj= convertMapToJson(readableMap);
239
- if(obj.has("eventName")){
240
- evnt = (String) obj.get("eventName");}
241
- Log.e(TAG,"eventProperties"+evnt);
242
- CustomerGlu.getInstance().sendEvent(getReactApplicationContext(),evnt, jsonToMap(obj.getJSONObject("eventProperties")));
243
-
244
- } catch (JSONException e) {
245
- e.printStackTrace();
246
- }
247
-
248
- }
249
- public static Map<String, Object> jsonToMap(JSONObject json) throws JSONException {
250
- Map<String, Object> retMap = new HashMap<String, Object>(); if(json != JSONObject.NULL) {
251
- retMap = toMap(json);
252
- }
253
- return retMap;
254
- }
255
- public static Map<String, Object> toMap(JSONObject object) throws JSONException {
256
- Map<String, Object> map = new HashMap<String, Object>();
257
- Iterator<String> keysItr = object.keys();
258
- while(keysItr.hasNext()) {
259
- String key = keysItr.next();
260
- Object value = object.get(key);
261
-
262
- if(value instanceof JSONArray) {
263
- value = toList((JSONArray) value);
264
- }
265
-
266
- else if(value instanceof JSONObject) {
267
- value = toMap((JSONObject) value);
268
- }
269
- map.put(key, value);
270
- }
271
- return map;
272
- }
273
- public static List<Object> toList(JSONArray array) throws JSONException {
274
- List<Object> list = new ArrayList<Object>();
275
- for(int i = 0; i < array.length(); i++) {
276
- Object value = array.get(i);
277
- if(value instanceof JSONArray) {
278
- value = toList((JSONArray) value);
279
- }
280
- else if(value instanceof JSONObject) {
281
- value = toMap((JSONObject) value);
282
- }
283
- list.add(value);
284
- }
285
- return list;
286
- }
287
-
288
- @ReactMethod
289
- public void openWallet(ReadableMap readableMap) {
290
- try {
291
- if(readableMap.hasKey("nudgeConfiguration")) {
292
- Log.e(TAG, "openwallet-----" + readableMap.toString());
293
-
294
- JSONObject nudgeConfigurationdata;
295
- NudgeConfiguration nudgeConfiguration = new NudgeConfiguration();
296
- JSONObject obj = convertMapToJson(readableMap);
297
- nudgeConfigurationdata = obj.getJSONObject("nudgeConfiguration");
298
- if (nudgeConfigurationdata.has("layout")) {
299
- nudgeConfiguration.setLayout(nudgeConfigurationdata.getString("layout"));
300
- }
301
- if (nudgeConfigurationdata.has("opacity")) {
302
- nudgeConfiguration.setOpacity(Double.parseDouble(nudgeConfigurationdata.getString("opacity")));
303
- }
304
- if (nudgeConfigurationdata.has("closeOnDeepLink")) {
305
- nudgeConfiguration.setCloseOnDeepLink(nudgeConfigurationdata.getBoolean("closeOnDeepLink"));
306
- }
307
- if (nudgeConfigurationdata.has("absoluteHeight")) {
308
- nudgeConfiguration.setAbsoluteHeight(Double.parseDouble(nudgeConfigurationdata.getString("absoluteHeight")));
309
- }
310
- if (nudgeConfigurationdata.has("relativeHeight")) {
311
- nudgeConfiguration.setRelativeHeight(Double.parseDouble(nudgeConfigurationdata.getString("relativeHeight")));
312
- }
313
- CustomerGlu.getInstance().openWallet(getReactApplicationContext(), nudgeConfiguration);
314
-
315
-
316
-
317
- }else{
318
- CustomerGlu.getInstance().openWallet(getReactApplicationContext());
319
- }
320
- } catch (JSONException e) {
321
- e.printStackTrace();
322
- }
323
- }
324
-
325
-
326
- @ReactMethod
327
- public void loadCampaignById(String id, ReadableMap readableMap) {
328
- Log.e(TAG,"loadCampaignById-----"+readableMap.toString());
329
- try {
330
- JSONObject nudgeConfigurationdata;
331
- NudgeConfiguration nudgeConfiguration = new NudgeConfiguration();
332
- if(readableMap.hasKey("nudgeConfiguration")) {
333
- JSONObject obj = convertMapToJson(readableMap);
334
- nudgeConfigurationdata = obj.getJSONObject("nudgeConfiguration");
335
- if (nudgeConfigurationdata.has("layout")) {
336
- nudgeConfiguration.setLayout(nudgeConfigurationdata.getString("layout"));
337
- }
338
- if (nudgeConfigurationdata.has("opacity")) {
339
- nudgeConfiguration.setOpacity(Double.parseDouble(nudgeConfigurationdata.getString("opacity")));
340
- }
341
- if (nudgeConfigurationdata.has("closeOnDeepLink")) {
342
- nudgeConfiguration.setCloseOnDeepLink(nudgeConfigurationdata.getBoolean("closeOnDeepLink"));
343
- }
344
- if (nudgeConfigurationdata.has("absoluteHeight")) {
345
- nudgeConfiguration.setAbsoluteHeight(Double.parseDouble(nudgeConfigurationdata.getString("absoluteHeight")));
346
- }
347
- if (nudgeConfigurationdata.has("relativeHeight")) {
348
- nudgeConfiguration.setRelativeHeight(Double.parseDouble(nudgeConfigurationdata.getString("relativeHeight")));
349
- }
350
- CustomerGlu.getInstance().loadCampaignById(getReactApplicationContext(), id, nudgeConfiguration);
351
- } else {
352
- CustomerGlu.getInstance().loadCampaignById(getReactApplicationContext(),id);
353
- }
354
- } catch (JSONException e) {
355
- e.printStackTrace();
356
- }
357
-
358
-
359
- }
360
-
361
- @ReactMethod
362
- public void enableAnalytic(Boolean bool) {
363
- CustomerGlu.getInstance().enableAnalyticsEvent(bool);
364
- }
365
-
366
-
367
- @ReactMethod
368
- public void disableGluSdk(Boolean bool) {
369
- CustomerGlu.getInstance().disableGluSdk(bool);
370
-
371
- }
372
-
373
- @ReactMethod
374
- public void configureLoaderColour(String color) {
375
- CustomerGlu.getInstance().configureLoaderColour(getReactApplicationContext(), color);
376
- }
377
-
378
- @ReactMethod
379
- public void configureStatusBarColour(String color) {
380
- CustomerGlu.getInstance().configureStatusBarColour(color);
381
- }
382
-
383
- @ReactMethod
384
- public void configureSafeArea(ReadableMap map) {
385
- }
386
-
387
- @ReactMethod
388
- public void configureLoadingScreenColor(String clr) {
389
- Log.e(TAG, "color->>>>>>"+clr);
390
- if(clr!=null && clr.length()==9) {
391
- int red = Integer.valueOf(clr.substring(1, 3), 16);
392
- int green = Integer.valueOf(clr.substring(3, 5), 16);
393
- int blue = Integer.valueOf(clr.substring(5, 7), 16);
394
- int alpha = Integer.parseInt(clr.substring(7, 9), 16);
395
- String alphaHex = To00Hex(alpha);
396
- String blueHex = To00Hex(blue);
397
- String greenHex = To00Hex(green);
398
- String redHex = To00Hex(red);
399
- StringBuilder str = new StringBuilder("#");
400
- str.append(alphaHex);
401
- str.append(redHex );
402
- str.append(greenHex);
403
- str.append(blueHex);
404
- Log.e(TAG, "colo1-----" + red + " " + green + " " + blue + " " + alpha+" "+str.toString());
405
-
406
- CustomerGlu.getInstance().configureLoadingScreenColor(str.toString());
407
-
408
- }else
409
- {
410
- CustomerGlu.getInstance().configureLoadingScreenColor(clr);
477
+ //2jan2023
478
+
479
+ @ReactMethod
480
+ public void configureDarkBackgroundColor(String color) {
481
+ if(color!=null){
482
+ CustomerGlu.getInstance().configureDarkBackgroundColor(color);}
411
483
  }
412
- }
413
484
 
414
- private static String To00Hex(int value) {
415
- String hex = "00".concat(Integer.toHexString(value));
416
- return hex.substring(hex.length()-2, hex.length());
417
- }
418
-
419
- @ReactMethod
420
- public void enablePrecaching() {
421
- CustomerGlu.getInstance().enablePrecaching(getReactApplicationContext());
422
- }
423
-
424
- @ReactMethod
425
- public void gluSDKDebuggingMode(Boolean bol) {
426
- CustomerGlu.getInstance().gluSDKDebuggingMode(getCurrentActivity(), bol);
427
- }
428
-
429
- @ReactMethod
430
- public void enableEntryPoints(Boolean bol) {
431
- CustomerGlu.getInstance().enableEntryPoints(getCurrentActivity(), bol);
432
- }
433
-
434
- @ReactMethod
435
- public void closeWebView(Boolean bol) {
436
- CustomerGlu.getInstance().closeWebviewOnDeeplinkEvent(bol);
437
- }
438
-
439
- @ReactMethod
440
- public void SetDefaultBannerImage(String url) {
441
- CustomerGlu.getInstance().setDefaultBannerImage(getCurrentActivity(), url);
442
- }
443
-
444
-
445
-
446
- @ReactMethod
447
- public void UpdateProfile(ReadableMap map, Promise promise) {
448
- JSONObject jsonObject = convertMapToJson(map);
449
- HashMap<String, Object> userData = new Gson().fromJson(jsonObject.toString(), HashMap.class);
450
- CustomerGlu.getInstance().updateProfile(getReactApplicationContext(), userData, new DataListner() {
451
- @Override
452
- public void onSuccess(RegisterModal registerModal) {
453
- // Toast.makeText(getReactApplicationContext(), "Profile Updated", Toast.LENGTH_SHORT).show();
454
- Log.d(TAG,"Profile Updated!...");
485
+ @ReactMethod
486
+ public void configureLightBackgroundColor(String color) {
487
+ if(color!=null){
488
+ CustomerGlu.getInstance().configureLightBackgroundColor(color);}
489
+ }
490
+
491
+ @ReactMethod
492
+ public void listenToDarkMode(boolean isdarkmode) {
493
+ CustomerGlu.getInstance().listenToSystemDarkMode(isdarkmode);
494
+ }
495
+
496
+ @ReactMethod
497
+ public void enableDarkMode(boolean darkmode) {
498
+ CustomerGlu.getInstance().enableDarkMode(darkmode);
499
+ }
500
+ //end
501
+
502
+ //16jan2023
503
+ @ReactMethod
504
+ public void configureLightLoaderURL(String url){
505
+ if(url!=null){
506
+ CustomerGlu.getInstance().configureLightLoaderURL(getReactApplicationContext(), url);
507
+ }
508
+ }
509
+ @ReactMethod
510
+ public void configureDarkLoaderURL(String url){
511
+ if(url!=null){
512
+ CustomerGlu.getInstance().configureDarkLoaderURL(getReactApplicationContext(), url);
513
+ }
514
+
515
+ }
516
+ @ReactMethod
517
+ public void configureLightEmbedLoaderURL(String url){
518
+ if(url!=null){
519
+ CustomerGlu.getInstance().configureLightEmbedLoaderURL(getReactApplicationContext(), url);
520
+ }
521
+
522
+ }
523
+ @ReactMethod
524
+ public void configureDarkEmbedLoaderURL(String url){
525
+ if(url!=null){
526
+ CustomerGlu.getInstance().configureDarkEmbedLoaderURL(getReactApplicationContext(), url);
527
+ }
528
+ }
529
+ //end
530
+ @ReactMethod
531
+ public void configureStatusBarColour(String color) {
532
+ CustomerGlu.getInstance().configureStatusBarColour(color);
533
+ }
455
534
 
456
- }
535
+ @ReactMethod
536
+ public void configureSafeArea(ReadableMap map) {
537
+ }
457
538
 
458
- @Override
459
- public void onFail(String message) {
460
- Log.d(TAG,"Profile Not Updated!..."+message.toString());
539
+ @ReactMethod
540
+ public void configureLoadingScreenColor(String clr) {
541
+ Log.e(TAG, "color->>>>>>" + clr);
542
+ if (clr != null && clr.length() == 9) {
543
+ int red = Integer.valueOf(clr.substring(1, 3), 16);
544
+ int green = Integer.valueOf(clr.substring(3, 5), 16);
545
+ int blue = Integer.valueOf(clr.substring(5, 7), 16);
546
+ int alpha = Integer.parseInt(clr.substring(7, 9), 16);
547
+ String alphaHex = To00Hex(alpha);
548
+ String blueHex = To00Hex(blue);
549
+ String greenHex = To00Hex(green);
550
+ String redHex = To00Hex(red);
551
+ StringBuilder str = new StringBuilder("#");
552
+ str.append(alphaHex);
553
+ str.append(redHex);
554
+ str.append(greenHex);
555
+ str.append(blueHex);
556
+ Log.e(TAG, "colo1-----" + red + " " + green + " " + blue + " " + alpha + " " + str.toString());
557
+
558
+ CustomerGlu.getInstance().configureLoadingScreenColor(str.toString());
559
+
560
+ } else {
561
+ CustomerGlu.getInstance().configureLoadingScreenColor(clr);
562
+ }
563
+ }
461
564
 
462
- }
463
- });
464
- }
565
+ private static String To00Hex(int value) {
566
+ String hex = "00".concat(Integer.toHexString(value));
567
+ return hex.substring(hex.length() - 2, hex.length());
568
+ }
465
569
 
466
- @ReactMethod
467
- public void DisplayCGNotification(ReadableMap data,Boolean autoclosewebview) {
468
- JSONObject jsonObject=convertMapToJson(data);
469
- if(getAppIcon(getReactApplicationContext())!=0) {
470
- CustomerGlu.getInstance().displayCustomerGluNotification(getReactApplicationContext(), jsonObject, getAppIcon(getReactApplicationContext()), 0.5, autoclosewebview);
471
- }else{
472
- CustomerGlu.getInstance().displayCustomerGluNotification(getReactApplicationContext(), jsonObject, R.drawable.notification, 0.5, autoclosewebview);
570
+ @ReactMethod
571
+ public void enablePrecaching() {
572
+ CustomerGlu.getInstance().enablePrecaching(getReactApplicationContext());
573
+ }
473
574
 
575
+ @ReactMethod
576
+ public void gluSDKDebuggingMode(Boolean bol) {
577
+ CustomerGlu.getInstance().gluSDKDebuggingMode(getCurrentActivity(), bol);
474
578
  }
475
- }
476
579
 
477
- private static int getAppIcon(Context context) {
580
+ @ReactMethod
581
+ public void enableEntryPoints(Boolean bol) {
582
+ CustomerGlu.getInstance().enableEntryPoints(getCurrentActivity(), bol);
583
+ }
478
584
 
479
- try {
480
- ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
481
- context.getPackageName(), PackageManager.GET_META_DATA);
482
- Bundle bundle = ai.metaData;
483
- int myAPIKey = bundle.getInt("CUSTOMERGLU_NOTIFICATION_ICON");
484
- printDebugLogs("API KEY : " + myAPIKey);
485
- return myAPIKey;
486
- } catch (Exception e) {
487
- Comman.printErrorLogs(e.toString());
488
- return 0;
585
+ @ReactMethod
586
+ public void closeWebView(Boolean bol) {
587
+ CustomerGlu.getInstance().closeWebviewOnDeeplinkEvent(bol);
489
588
  }
490
- }
491
589
 
590
+ @ReactMethod
591
+ public void SetDefaultBannerImage(String url) {
592
+ CustomerGlu.getInstance().setDefaultBannerImage(getCurrentActivity(), url);
593
+ }
492
594
 
493
595
 
596
+ @ReactMethod
597
+ public void UpdateProfile(ReadableMap map, Promise promise) {
598
+ if (map != null) {
599
+ JSONObject jsonObject = convertMapToJson(map);
600
+ HashMap<String, Object> userData = new Gson().fromJson(jsonObject.toString(), HashMap.class);
601
+ CustomerGlu.getInstance().updateProfile(getReactApplicationContext(), userData, new DataListner() {
602
+ @Override
603
+ public void onSuccess(RegisterModal registerModal) {
604
+ // Toast.makeText(getReactApplicationContext(), "Profile Updated", Toast.LENGTH_SHORT).show();
605
+ Log.d(TAG, "Profile Updated!...");
494
606
 
607
+ }
495
608
 
609
+ @Override
610
+ public void onFail(String message) {
611
+ Log.d(TAG, "Profile Not Updated!..." + message.toString());
496
612
 
613
+ }
614
+ });
615
+ }
616
+ }
497
617
 
618
+ @ReactMethod
619
+ public void DisplayCGNotification(ReadableMap data, Boolean autoclosewebview) {
620
+ JSONObject jsonObject = convertMapToJson(data);
621
+ if (getAppIcon(getReactApplicationContext()) != 0) {
622
+ CustomerGlu.getInstance().displayCustomerGluNotification(getReactApplicationContext(), jsonObject, getAppIcon(getReactApplicationContext()), 0.5, autoclosewebview);
623
+ } else {
624
+ CustomerGlu.getInstance().displayCustomerGluNotification(getReactApplicationContext(), jsonObject, R.drawable.notification, 0.5, autoclosewebview);
498
625
 
626
+ }
627
+ }
499
628
 
500
- @ReactMethod
501
- public void DisplayCGBackgroundNotification(ReadableMap data,Boolean autoclosewebview) {
502
- JSONObject jsonObject=convertMapToJson(data);
503
- Log.d(TAG,"DisplayCGBackgroundNotification---"+jsonObject+" "+ autoclosewebview);
504
- CustomerGlu.getInstance().displayCustomerGluBackgroundNotification(getReactApplicationContext(),jsonObject,autoclosewebview);
629
+ private static int getAppIcon(Context context) {
630
+
631
+ try {
632
+ ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
633
+ context.getPackageName(), PackageManager.GET_META_DATA);
634
+ Bundle bundle = ai.metaData;
635
+ int myAPIKey = bundle.getInt("CUSTOMERGLU_NOTIFICATION_ICON");
636
+ printDebugLogs("API KEY : " + myAPIKey);
637
+ return myAPIKey;
638
+ } catch (Exception e) {
639
+ Comman.printErrorLogs(e.toString());
640
+ return 0;
641
+ }
642
+ }
505
643
 
506
- }
507
644
 
645
+ @ReactMethod
646
+ public void DisplayCGBackgroundNotification(ReadableMap data, Boolean autoclosewebview) {
647
+ JSONObject jsonObject = convertMapToJson(data);
648
+ Log.d(TAG, "DisplayCGBackgroundNotification---" + jsonObject + " " + autoclosewebview);
649
+ CustomerGlu.getInstance().displayCustomerGluBackgroundNotification(getReactApplicationContext(), jsonObject, autoclosewebview);
508
650
 
651
+ }
509
652
 
510
653
 
511
654
  @ReactMethod
512
655
  public void CGApplication() {
513
- }
514
-
515
- @ReactMethod
516
- public void DisplayCustomerGluNotification() {
517
- registerBroadcastReceiver();
518
- }
519
-
520
- @ReactMethod
521
- public void GetRefferalId(String url, Promise promise) throws MalformedURLException {
522
- Uri myURL = Uri.parse(url);
523
- String referID = CustomerGlu.getInstance().getReferralId(myURL);
524
- promise.resolve(referID);
525
- }
526
-
527
- @ReactMethod
528
- public void LoadAllCampagins() {
529
- CustomerGlu.getInstance().loadAllCampaigns(getReactApplicationContext());
530
- }
531
-
532
- @ReactMethod
533
- public void LoadCampaginsByFilter(ReadableMap readableMap) {
534
- try {
535
- JSONObject obj = convertMapToJson(readableMap);
536
- HashMap<String, Object> campaignData = new HashMap<>();
537
- campaignData.put("campaignId", obj.get("campaignId"));
538
- campaignData.put("status", obj.get("status"));
539
- campaignData.put("type", obj.get("type"));
540
- CustomerGlu.getInstance().loadCampaignsByFilter(getReactApplicationContext(), campaignData);
541
- } catch (JSONException e) {
542
- e.printStackTrace();
543
- }
544
- }
545
-
546
- @ReactMethod
547
- public void SetCurrentClassName(String classname) {
548
- this.Myclassname = classname;
549
- runOnUiThread(new Runnable() {
550
- @Override
551
- public void run() {
552
- CustomerGlu.getInstance().setScreenName(getReactApplicationContext(),classname);
553
-
554
- }
555
- });
556
- }
557
-
558
-
559
-
560
- @ReactMethod
561
- public void configureWhiteListedDomains(ReadableArray readableArray) {
562
- try {
563
- JSONArray obj = convertArrayToJson(readableArray);
564
- ArrayList<String> listdata = new ArrayList<String>();
565
- for (int i=0;i<obj.length();i++){
566
- listdata.add((String) obj.get(i));
567
-
568
- }
569
- CustomerGlu.getInstance().configureWhiteListedDomains(listdata);
570
- } catch (JSONException e) {
571
- e.printStackTrace();
572
- }
573
-
574
- }
575
- @ReactMethod
576
- public void OpenNudgeRN(String nudgeid,ReadableMap readableMap){
577
- Log.d(TAG,"nudeg----"+readableMap.hasKey("nudgeConfiguration"));
578
- NudgeConfiguration nudgeConfiguration = new NudgeConfiguration();
579
- try {
580
- if(readableMap.hasKey("nudgeConfiguration")) {
581
- JSONObject nudgeConfigurationdata;
582
-
583
- JSONObject obj = convertMapToJson(readableMap);
584
- if (obj.has("nudgeid")) {
585
- nudgeid = obj.getString("nudgeid");
586
- }
587
- if (obj.has("nudgeConfiguration")) {
588
- nudgeConfigurationdata = obj.getJSONObject("nudgeConfiguration");
589
- if (nudgeConfigurationdata.has("layout")) {
590
- nudgeConfiguration.setLayout(nudgeConfigurationdata.getString("layout"));
591
- }
592
- if (nudgeConfigurationdata.has("opacity")) {
593
- nudgeConfiguration.setOpacity(Double.parseDouble(nudgeConfigurationdata.getString("opacity")));
594
- }
595
- if (nudgeConfigurationdata.has("closeOnDeepLink")) {
596
- nudgeConfiguration.setCloseOnDeepLink(nudgeConfigurationdata.getBoolean("closeOnDeepLink"));
597
- }
598
- if (nudgeConfigurationdata.has("absoluteHeight")) {
599
- nudgeConfiguration.setAbsoluteHeight(Double.parseDouble(nudgeConfigurationdata.getString("absoluteHeight")));
600
- }
601
- if (nudgeConfigurationdata.has("relativeHeight")) {
602
- nudgeConfiguration.setRelativeHeight(Double.parseDouble(nudgeConfigurationdata.getString("relativeHeight")));
603
- }
604
- }
605
- }
606
- CustomerGlu.getInstance().openNudge(getReactApplicationContext(),nudgeid,nudgeConfiguration);
607
- } catch (JSONException e) {
608
- e.printStackTrace();
609
- }
610
-
611
-
612
- }
613
-
614
-
615
- @ReactMethod
616
- public void configureDomainCodeMsg(ReadableMap readableMap) {
617
- try {
618
- JSONObject obj = convertMapToJson(readableMap);
619
- int code = obj.has("code")? (int) obj.get("code"):0;
620
- String msg = obj.has("msg")?(String) obj.get("msg"):"";
621
- CustomerGlu.getInstance().configureDomainCodeMsg(code,msg);
622
- } catch (JSONException e) {
623
- e.printStackTrace();
624
- }
625
-
626
- }
627
-
628
-
629
- private JSONObject convertMapToJson(ReadableMap readableMap) {
630
- JSONObject jsonObject = new JSONObject();
631
- if (readableMap == null) {
632
- return null;
633
- }
634
- ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
635
- if (!iterator.hasNextKey()) {
636
- return null;
637
- }
638
- while (iterator.hasNextKey()) {
639
- String key = iterator.nextKey();
640
- ReadableType readableType = readableMap.getType(key);
641
- try {
642
- switch (readableType) {
643
- case Null:
644
- jsonObject.put(key, null);
645
- break;
646
- case Boolean:
647
- jsonObject.put(key, readableMap.getBoolean(key));
648
- break;
649
- case Number:
650
- // Can be int or double.
651
- jsonObject.put(key, readableMap.getInt(key));
652
- break;
653
- case String:
654
- jsonObject.put(key, readableMap.getString(key));
655
-
656
- break;
657
- case Array:
658
- jsonObject.put(key, convertArrayToJson(readableMap.getArray(key)));
659
- case Map:
660
- jsonObject.put(key, convertMapToJson(readableMap.getMap(key)));
661
- default:
662
- // Do nothing and fail silently
663
- }
664
- } catch (JSONException ex) {
665
- }
666
- }
667
- return jsonObject;
668
- }
669
-
670
- private static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
671
- JSONArray array = new JSONArray();
672
- for (int i = 0; i < readableArray.size(); i++) {
673
- switch (readableArray.getType(i)) {
674
- case Null:
675
- break;
676
- case Boolean:
677
- array.put(readableArray.getBoolean(i));
678
- break;
679
- case Number:
680
- array.put(readableArray.getDouble(i));
681
- break;
682
- case String:
683
- array.put(readableArray.getString(i));
684
- break;
685
- // case Map:
686
- // array.put(readableMapToJson(readableArray.getMap(i)));
687
- // break;
688
- case Array:
689
- array.put(convertArrayToJson(readableArray.getArray(i)));
690
- break;
691
- }
692
- }
693
- return array;
694
- }
695
-
696
-
697
- public static WritableMap jsonToWritableMap(JSONObject jsonObject) {
698
- WritableMap writableMap = new WritableNativeMap();
699
- if (jsonObject == null) {
700
- return null;
701
- }
702
- Iterator<String> iterator = jsonObject.keys();
703
- if (!iterator.hasNext()) {
704
- return null;
705
- }
706
- while (iterator.hasNext()) {
707
- String key = iterator.next();
708
- try {
709
- Object value = jsonObject.get(key);
710
- if (value == null) {
711
- writableMap.putNull(key);
712
- } else if (value instanceof Boolean) {
713
- writableMap.putBoolean(key, (Boolean) value);
714
- } else if (value instanceof Integer) {
715
- writableMap.putInt(key, (Integer) value);
716
- } else if (value instanceof Double) {
717
- writableMap.putDouble(key, (Double) value);
718
- } else if (value instanceof String) {
719
- writableMap.putString(key, (String) value);
720
- } else if (value instanceof JSONObject) {
721
- writableMap.putMap(key, jsonToWritableMap((JSONObject) value));
722
- } else if (value instanceof JSONArray) {
723
- writableMap.putArray(key, jsonArrayToWritableArray((JSONArray) value));
724
- }
725
- } catch (JSONException ex) {
726
- // Do nothing and fail silently
727
- }
728
- }
729
-
730
- return writableMap;
731
- }
732
-
733
- public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) {
734
- WritableArray writableArray = new WritableNativeArray();
735
-
736
- if (jsonArray == null) {
737
- return null;
738
- }
739
-
740
- if (jsonArray.length() <= 0) {
741
- return null;
742
- }
743
-
744
- for (int i = 0; i < jsonArray.length(); i++) {
745
- try {
746
- Object value = jsonArray.get(i);
747
- if (value == null) {
748
- writableArray.pushNull();
749
- } else if (value instanceof Boolean) {
750
- writableArray.pushBoolean((Boolean) value);
751
- } else if (value instanceof Integer) {
752
- writableArray.pushInt((Integer) value);
753
- } else if (value instanceof Double) {
754
- writableArray.pushDouble((Double) value);
755
- } else if (value instanceof String) {
756
- writableArray.pushString((String) value);
757
- } else if (value instanceof JSONObject) {
758
- writableArray.pushMap(jsonToWritableMap((JSONObject) value));
759
- } else if (value instanceof JSONArray) {
760
- writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value));
761
- }
762
- } catch (JSONException e) {
763
- // Do nothing and fail silently
764
- }
765
- }
766
-
767
- return writableArray;
768
- }
656
+ }
657
+
658
+ @ReactMethod
659
+ public void DisplayCustomerGluNotification() {
660
+ registerBroadcastReceiver();
661
+ }
662
+
663
+ @ReactMethod
664
+ public void GetRefferalId(String url, Promise promise) throws MalformedURLException {
665
+ Uri myURL = Uri.parse(url);
666
+ String referID = CustomerGlu.getInstance().getReferralId(myURL);
667
+ promise.resolve(referID);
668
+ }
669
+
670
+ @ReactMethod
671
+ public void LoadAllCampagins() {
672
+ CustomerGlu.getInstance().loadAllCampaigns(getReactApplicationContext());
673
+ }
674
+
675
+ @ReactMethod
676
+ public void LoadCampaginsByFilter(ReadableMap readableMap) {
677
+ try {
678
+ JSONObject obj = convertMapToJson(readableMap);
679
+ HashMap<String, Object> campaignData = new HashMap<>();
680
+ campaignData.put("campaignId", obj.get("campaignId"));
681
+ campaignData.put("status", obj.get("status"));
682
+ campaignData.put("type", obj.get("type"));
683
+ CustomerGlu.getInstance().loadCampaignsByFilter(getReactApplicationContext(), campaignData);
684
+ } catch (JSONException e) {
685
+ e.printStackTrace();
686
+ }
687
+ }
688
+
689
+ @ReactMethod
690
+ public void SetCurrentClassName(String classname) {
691
+ this.Myclassname = classname;
692
+ runOnUiThread(new Runnable() {
693
+ @Override
694
+ public void run() {
695
+ CustomerGlu.getInstance().setScreenName(getReactApplicationContext(), classname);
696
+
697
+ }
698
+ });
699
+ }
700
+
701
+
702
+ @ReactMethod
703
+ public void configureWhiteListedDomains(ReadableArray readableArray) {
704
+ try {
705
+ JSONArray obj = convertArrayToJson(readableArray);
706
+ ArrayList<String> listdata = new ArrayList<String>();
707
+ for (int i = 0; i < obj.length(); i++) {
708
+ listdata.add((String) obj.get(i));
709
+
710
+ }
711
+ CustomerGlu.getInstance().configureWhiteListedDomains(listdata);
712
+ } catch (JSONException e) {
713
+ e.printStackTrace();
714
+ }
715
+
716
+ }
717
+
718
+ @ReactMethod
719
+ public void OpenNudgeRN(String nudgeid, ReadableMap readableMap) {
720
+ Log.d(TAG, "nudeg----" + readableMap.hasKey("nudgeConfiguration"));
721
+ NudgeConfiguration nudgeConfiguration = new NudgeConfiguration();
722
+ try {
723
+ if (readableMap.hasKey("nudgeConfiguration")) {
724
+ JSONObject nudgeConfigurationdata;
725
+
726
+ JSONObject obj = convertMapToJson(readableMap);
727
+ if (obj.has("nudgeid")) {
728
+ nudgeid = obj.getString("nudgeid");
729
+ }
730
+ if (obj.has("nudgeConfiguration")) {
731
+ nudgeConfigurationdata = obj.getJSONObject("nudgeConfiguration");
732
+ if (nudgeConfigurationdata.has("layout")) {
733
+ nudgeConfiguration.setLayout(nudgeConfigurationdata.getString("layout"));
734
+ }
735
+ if (nudgeConfigurationdata.has("opacity")) {
736
+ nudgeConfiguration.setOpacity(Double.parseDouble(nudgeConfigurationdata.getString("opacity")));
737
+ }
738
+ if (nudgeConfigurationdata.has("closeOnDeepLink")) {
739
+ nudgeConfiguration.setCloseOnDeepLink(nudgeConfigurationdata.getBoolean("closeOnDeepLink"));
740
+ }
741
+ if (nudgeConfigurationdata.has("absoluteHeight")) {
742
+ nudgeConfiguration.setAbsoluteHeight(Double.parseDouble(nudgeConfigurationdata.getString("absoluteHeight")));
743
+ }
744
+ if (nudgeConfigurationdata.has("relativeHeight")) {
745
+ nudgeConfiguration.setRelativeHeight(Double.parseDouble(nudgeConfigurationdata.getString("relativeHeight")));
746
+ }
747
+ }
748
+ }
749
+ CustomerGlu.getInstance().openNudge(getReactApplicationContext(), nudgeid, nudgeConfiguration);
750
+ } catch (JSONException e) {
751
+ e.printStackTrace();
752
+ }
753
+
754
+
755
+ }
756
+
757
+
758
+ @ReactMethod
759
+ public void configureDomainCodeMsg(ReadableMap readableMap) {
760
+ try {
761
+ JSONObject obj = convertMapToJson(readableMap);
762
+ int code = obj.has("code") ? (int) obj.get("code") : 0;
763
+ String msg = obj.has("msg") ? (String) obj.get("msg") : "";
764
+ CustomerGlu.getInstance().configureDomainCodeMsg(code, msg);
765
+ } catch (JSONException e) {
766
+ e.printStackTrace();
767
+ }
768
+
769
+ }
770
+
771
+
772
+ private static JSONObject convertMapToJson(ReadableMap readableMap) {
773
+ JSONObject jsonObject = new JSONObject();
774
+ if (readableMap == null) {
775
+ return null;
776
+ }
777
+ ReadableMapKeySetIterator iterator = readableMap.keySetIterator();
778
+ if (!iterator.hasNextKey()) {
779
+ return null;
780
+ }
781
+ while (iterator.hasNextKey()) {
782
+ String key = iterator.nextKey();
783
+ ReadableType readableType = readableMap.getType(key);
784
+ Log.e(TAG, "readableType" + readableType + " " + readableMap.toString());
785
+ try {
786
+ switch (readableType) {
787
+ case Null:
788
+ jsonObject.put(key, null);
789
+ break;
790
+ case Boolean:
791
+ jsonObject.put(key, readableMap.getBoolean(key));
792
+ break;
793
+ case Number:
794
+ // Can be int or double.
795
+ jsonObject.put(key, readableMap.getInt(key));
796
+ break;
797
+ case String:
798
+ jsonObject.put(key, readableMap.getString(key));
799
+ break;
800
+ case Array:
801
+ jsonObject.put(key, convertArrayToJson(readableMap.getArray(key)));
802
+ break;
803
+ case Map:
804
+ jsonObject.put(key, convertMapToJson(readableMap.getMap(key)));
805
+ break;
806
+ default:
807
+ // Do nothing and fail silently
808
+ }
809
+ } catch (JSONException ex) {
810
+ }
811
+ }
812
+ return jsonObject;
813
+ }
814
+
815
+ private static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException {
816
+ JSONArray array = new JSONArray();
817
+ for (int i = 0; i < readableArray.size(); i++) {
818
+ switch (readableArray.getType(i)) {
819
+ case Null:
820
+ break;
821
+ case Boolean:
822
+ array.put(readableArray.getBoolean(i));
823
+ break;
824
+ case Number:
825
+ array.put(readableArray.getDouble(i));
826
+ break;
827
+ case String:
828
+ array.put(readableArray.getString(i));
829
+ break;
830
+ case Map:
831
+ array.put(convertMapToJson(readableArray.getMap(i)));
832
+ break;
833
+ case Array:
834
+ array.put(convertArrayToJson(readableArray.getArray(i)));
835
+ break;
836
+ }
837
+ }
838
+ return array;
839
+ }
840
+
841
+
842
+ public static WritableMap jsonToWritableMap(JSONObject jsonObject) {
843
+ WritableMap writableMap = new WritableNativeMap();
844
+ if (jsonObject == null) {
845
+ return null;
846
+ }
847
+ Iterator<String> iterator = jsonObject.keys();
848
+ if (!iterator.hasNext()) {
849
+ return null;
850
+ }
851
+ while (iterator.hasNext()) {
852
+ String key = iterator.next();
853
+ try {
854
+ Object value = jsonObject.get(key);
855
+ if (value == null) {
856
+ writableMap.putNull(key);
857
+ } else if (value instanceof Boolean) {
858
+ writableMap.putBoolean(key, (Boolean) value);
859
+ } else if (value instanceof Integer) {
860
+ writableMap.putInt(key, (Integer) value);
861
+ } else if (value instanceof Double) {
862
+ writableMap.putDouble(key, (Double) value);
863
+ } else if (value instanceof String) {
864
+ writableMap.putString(key, (String) value);
865
+ } else if (value instanceof JSONObject) {
866
+ writableMap.putMap(key, jsonToWritableMap((JSONObject) value));
867
+ } else if (value instanceof JSONArray) {
868
+ writableMap.putArray(key, jsonArrayToWritableArray((JSONArray) value));
869
+ }
870
+ } catch (JSONException ex) {
871
+ // Do nothing and fail silently
872
+ }
873
+ }
874
+
875
+ return writableMap;
876
+ }
877
+
878
+ public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) {
879
+ WritableArray writableArray = new WritableNativeArray();
880
+
881
+ if (jsonArray == null) {
882
+ return null;
883
+ }
884
+
885
+ if (jsonArray.length() <= 0) {
886
+ return null;
887
+ }
888
+
889
+ for (int i = 0; i < jsonArray.length(); i++) {
890
+ try {
891
+ Object value = jsonArray.get(i);
892
+ if (value == null) {
893
+ writableArray.pushNull();
894
+ } else if (value instanceof Boolean) {
895
+ writableArray.pushBoolean((Boolean) value);
896
+ } else if (value instanceof Integer) {
897
+ writableArray.pushInt((Integer) value);
898
+ } else if (value instanceof Double) {
899
+ writableArray.pushDouble((Double) value);
900
+ } else if (value instanceof String) {
901
+ writableArray.pushString((String) value);
902
+ } else if (value instanceof JSONObject) {
903
+ writableArray.pushMap(jsonToWritableMap((JSONObject) value));
904
+ } else if (value instanceof JSONArray) {
905
+ writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value));
906
+ }
907
+ } catch (JSONException e) {
908
+ // Do nothing and fail silently
909
+ }
910
+ }
911
+
912
+ return writableArray;
913
+ }
769
914
 
770
915
 
771
916
  // public static native int nativeMultiply(int a, int b);