@customerglu/react-native-customerglu 1.1.1 → 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.
- package/README.md +1 -1
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativerncustomerglu/RncustomergluModule.java +754 -639
- package/ios/Rncustomerglu.m +9 -0
- package/ios/Rncustomerglu.swift +99 -47
- package/lib/commonjs/index.js +29 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +19 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +5 -0
- package/package.json +2 -2
- package/react-native-customerglu.podspec +1 -1
- package/src/index.tsx +21 -0
|
@@ -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,829 @@ import java.util.Map;
|
|
|
53
58
|
|
|
54
59
|
|
|
55
60
|
@ReactModule(name = RncustomergluModule.NAME)
|
|
56
|
-
public class RncustomergluModule extends ReactContextBaseJavaModule implements LifecycleEventListener
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
}
|
|
124
|
-
}
|
|
125
157
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
WritableMap map = jsonToWritableMap(jsonObject);
|
|
132
|
-
sendEventToJs("CG_INVALID_CAMPAIGN_ID", map);
|
|
133
|
-
}
|
|
158
|
+
private void sendEventToJs(String eventName, WritableMap map) {
|
|
159
|
+
try {
|
|
160
|
+
getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
161
|
+
.emit(eventName, map);
|
|
162
|
+
} catch (Exception e) {
|
|
134
163
|
}
|
|
135
164
|
|
|
165
|
+
}
|
|
136
166
|
|
|
137
167
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
168
|
+
@Override
|
|
169
|
+
@NonNull
|
|
170
|
+
public String getName() {
|
|
171
|
+
return NAME;
|
|
141
172
|
}
|
|
142
173
|
|
|
143
|
-
|
|
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
|
+
});
|
|
144
244
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
}
|
|
150
263
|
|
|
151
|
-
}
|
|
152
264
|
|
|
265
|
+
}
|
|
266
|
+
}
|
|
153
267
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
.emit(eventName, map);
|
|
158
|
-
} catch (Exception e) {
|
|
268
|
+
@Override
|
|
269
|
+
public void onHostPause() {
|
|
270
|
+
// mContext.unregisterReceiver(mMessageReceiver);
|
|
159
271
|
}
|
|
160
272
|
|
|
161
|
-
|
|
273
|
+
@Override
|
|
274
|
+
public void onHostDestroy() {
|
|
275
|
+
// mContext.unregisterReceiver(mMessageReceiver);
|
|
162
276
|
|
|
277
|
+
}
|
|
163
278
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
public String getName() {
|
|
167
|
-
return NAME;
|
|
168
|
-
}
|
|
279
|
+
// Example method
|
|
280
|
+
// See https://reactnative.dev/docs/native-modules-android
|
|
169
281
|
|
|
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"));
|
|
178
282
|
|
|
179
|
-
|
|
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();
|
|
180
295
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
296
|
+
RegisterModal remodal = registerModal;
|
|
297
|
+
Log.d(TAG, "Registered!..." + " " + new Date().getTime());
|
|
298
|
+
promise.resolve(true);
|
|
185
299
|
|
|
186
|
-
@Override
|
|
187
|
-
public void onHostDestroy() {
|
|
188
|
-
// mContext.unregisterReceiver(mMessageReceiver);
|
|
189
300
|
|
|
190
|
-
|
|
301
|
+
}
|
|
191
302
|
|
|
192
|
-
|
|
193
|
-
|
|
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
|
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
196
313
|
|
|
197
|
-
|
|
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());
|
|
314
|
+
}
|
|
202
315
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// Toast.makeText(getReactApplicationContext(), "Registered", Toast.LENGTH_SHORT).show();
|
|
316
|
+
@ReactMethod
|
|
317
|
+
public void dataClear() {
|
|
318
|
+
CustomerGlu.getInstance().clearGluData(getCurrentActivity());
|
|
319
|
+
}
|
|
208
320
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
|
|
347
|
+
}
|
|
213
348
|
|
|
214
|
-
|
|
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
|
+
}
|
|
215
356
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
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"));
|
|
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);
|
|
337
370
|
}
|
|
338
|
-
|
|
339
|
-
|
|
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);
|
|
340
384
|
}
|
|
341
|
-
|
|
342
|
-
|
|
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();
|
|
343
421
|
}
|
|
344
|
-
|
|
345
|
-
|
|
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();
|
|
346
455
|
}
|
|
347
|
-
|
|
348
|
-
|
|
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);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
//2jan2023
|
|
478
|
+
|
|
479
|
+
@ReactMethod
|
|
480
|
+
public void configureDarkBackgroundColor(String color) {
|
|
481
|
+
// CustomerGlu.getInstance().listenToSystemDarkLightMode(getReactApplicationContext(), color);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
@ReactMethod
|
|
485
|
+
public void configureLightBackgroundColor(String color) {
|
|
486
|
+
// CustomerGlu.getInstance().configureLightBackgroundColor(getReactApplicationContext(), color);
|
|
487
|
+
}
|
|
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
|
|
499
|
+
|
|
500
|
+
@ReactMethod
|
|
501
|
+
public void configureStatusBarColour(String color) {
|
|
502
|
+
CustomerGlu.getInstance().configureStatusBarColour(color);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
@ReactMethod
|
|
506
|
+
public void configureSafeArea(ReadableMap map) {
|
|
507
|
+
}
|
|
508
|
+
|
|
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);
|
|
349
532
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
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);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
|
|
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) {
|
|
533
|
+
}
|
|
534
|
+
|
|
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
|
+
}
|
|
539
|
+
|
|
540
|
+
@ReactMethod
|
|
541
|
+
public void enablePrecaching() {
|
|
542
|
+
CustomerGlu.getInstance().enablePrecaching(getReactApplicationContext());
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
@ReactMethod
|
|
546
|
+
public void gluSDKDebuggingMode(Boolean bol) {
|
|
547
|
+
CustomerGlu.getInstance().gluSDKDebuggingMode(getCurrentActivity(), bol);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
@ReactMethod
|
|
551
|
+
public void enableEntryPoints(Boolean bol) {
|
|
552
|
+
CustomerGlu.getInstance().enableEntryPoints(getCurrentActivity(), bol);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
@ReactMethod
|
|
556
|
+
public void closeWebView(Boolean bol) {
|
|
557
|
+
CustomerGlu.getInstance().closeWebviewOnDeeplinkEvent(bol);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
@ReactMethod
|
|
561
|
+
public void SetDefaultBannerImage(String url) {
|
|
562
|
+
CustomerGlu.getInstance().setDefaultBannerImage(getCurrentActivity(), url);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
|
|
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) {
|
|
453
574
|
// Toast.makeText(getReactApplicationContext(), "Profile Updated", Toast.LENGTH_SHORT).show();
|
|
454
|
-
|
|
575
|
+
Log.d(TAG, "Profile Updated!...");
|
|
576
|
+
|
|
577
|
+
}
|
|
455
578
|
|
|
456
|
-
|
|
579
|
+
@Override
|
|
580
|
+
public void onFail(String message) {
|
|
581
|
+
Log.d(TAG, "Profile Not Updated!..." + message.toString());
|
|
457
582
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
}
|
|
461
587
|
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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);
|
|
465
595
|
|
|
466
|
-
|
|
467
|
-
|
|
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);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
473
598
|
|
|
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
|
+
}
|
|
474
612
|
}
|
|
475
|
-
}
|
|
476
613
|
|
|
477
|
-
private static int getAppIcon(Context context) {
|
|
478
614
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
return myAPIKey;
|
|
486
|
-
} catch (Exception e) {
|
|
487
|
-
Comman.printErrorLogs(e.toString());
|
|
488
|
-
return 0;
|
|
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);
|
|
620
|
+
|
|
489
621
|
}
|
|
490
|
-
}
|
|
491
622
|
|
|
492
623
|
|
|
624
|
+
@ReactMethod
|
|
625
|
+
public void CGApplication() {
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
@ReactMethod
|
|
629
|
+
public void DisplayCustomerGluNotification() {
|
|
630
|
+
registerBroadcastReceiver();
|
|
631
|
+
}
|
|
493
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
|
+
}
|
|
494
639
|
|
|
640
|
+
@ReactMethod
|
|
641
|
+
public void LoadAllCampagins() {
|
|
642
|
+
CustomerGlu.getInstance().loadAllCampaigns(getReactApplicationContext());
|
|
643
|
+
}
|
|
495
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
|
+
}
|
|
496
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
|
+
}
|
|
497
670
|
|
|
498
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
|
+
}
|
|
499
685
|
|
|
500
|
-
|
|
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);
|
|
686
|
+
}
|
|
505
687
|
|
|
506
|
-
|
|
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
|
+
}
|
|
507
723
|
|
|
508
724
|
|
|
725
|
+
}
|
|
509
726
|
|
|
510
727
|
|
|
511
728
|
@ReactMethod
|
|
512
|
-
public void
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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");
|
|
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;
|
|
586
750
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
+
}
|
|
604
781
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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
|
|
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;
|
|
663
816
|
}
|
|
664
|
-
|
|
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));
|
|
817
|
+
Iterator<String> iterator = jsonObject.keys();
|
|
818
|
+
if (!iterator.hasNext()) {
|
|
819
|
+
return null;
|
|
724
820
|
}
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
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));
|
|
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
|
+
}
|
|
761
843
|
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
}
|
|
844
|
+
|
|
845
|
+
return writableMap;
|
|
765
846
|
}
|
|
766
847
|
|
|
767
|
-
|
|
768
|
-
|
|
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
|
+
}
|
|
769
884
|
|
|
770
885
|
|
|
771
886
|
// public static native int nativeMultiply(int a, int b);
|