@customerglu/react-native-customerglu 1.1.0 → 1.2.0

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