36
36
import com .webengage .sdk .android .actions .render .PushNotificationData ;
37
37
import com .webengage .sdk .android .actions .render .InAppNotificationData ;
38
38
import com .webengage .sdk .android .callbacks .InAppNotificationCallbacks ;
39
- import com .webengage .sdk .android .callbacks .LifeCycleCallbacks ;
40
39
import com .webengage .sdk .android .UserProfile ;
41
40
import com .webengage .sdk .android .utils .Gender ;
42
41
43
42
44
- public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks , InAppNotificationCallbacks , LifeCycleCallbacks {
43
+ public class WebEngagePlugin extends CordovaPlugin implements PushNotificationCallbacks , InAppNotificationCallbacks {
45
44
private static final String TAG = "WebEngagePlugin" ;
46
45
private static CordovaWebView webView ;
47
46
@@ -89,7 +88,6 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
89
88
if ("engage" .equals (action )) {
90
89
WebEngage .registerPushNotificationCallback (this );
91
90
WebEngage .registerInAppNotificationCallback (this );
92
- WebEngage .registerLifeCycleCallback (this );
93
91
94
92
if (args != null && args .length () > 0 && args .get (0 ) instanceof JSONObject ) {
95
93
// Dynamic config
@@ -265,6 +263,10 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
265
263
}
266
264
} else if ("logout" .equals (action )) {
267
265
WebEngage .get ().user ().logout ();
266
+ } else if ("setDevicePushOptIn" .equals (action )) {
267
+ if (args .length () == 1 && args .get (0 ) instanceof Boolean ) {
268
+ WebEngage .get ().user ().setDevicePushOptIn (args .getBoolean (0 ));
269
+ }
268
270
}
269
271
270
272
return true ;
@@ -336,10 +338,21 @@ public PushNotificationData onPushNotificationReceived(Context context, PushNoti
336
338
return notificationData ;
337
339
}
338
340
339
- public static void handlePushClick (String uri , Bundle data ) {
341
+ public static void handlePushClick (String uri , Bundle customData ) {
340
342
IS_PUSH_CALLBACK_PENDING = true ;
341
343
PENDING_PUSH_URI = uri ;
342
- PENDING_PUSH_CUSTOM_DATA = bundleToJson (data );
344
+ JSONObject data = bundleToJson (customData );
345
+ JSONObject pushPayload = null ;
346
+ try {
347
+ if (customData != null && customData .containsKey ("we_pushPayload" )) {
348
+ pushPayload = new JSONObject (customData .getString ("we_pushPayload" ));
349
+ data .remove ("we_pushPayload" );
350
+ mergeJson (data , pushPayload );
351
+ }
352
+ } catch (JSONException e ) {
353
+ Logger .e (TAG , "error merging json" );
354
+ }
355
+ PENDING_PUSH_CUSTOM_DATA = data ;
343
356
Logger .d (TAG , "handlePushClick invoked" );
344
357
}
345
358
@@ -354,6 +367,12 @@ public void onPushNotificationShown(Context context, PushNotificationData notifi
354
367
public boolean onPushNotificationClicked (Context context , PushNotificationData notificationData ) {
355
368
String uri = notificationData .getPrimeCallToAction ().getAction ();
356
369
JSONObject customData = bundleToJson (notificationData .getCustomData ());
370
+ try {
371
+ customData = mergeJson (bundleToJson (notificationData .getCustomData ()), notificationData .getPushPayloadJSON ());
372
+ } catch (JSONException e ) {
373
+ e .printStackTrace ();
374
+ Logger .e (TAG , "Exception while merging JSON" );
375
+ }
357
376
webView .sendJavascript ("javascript:webengage.push.onCallbackReceived( 'click', '" + uri + "'," + customData + ");" );
358
377
return false ;
359
378
}
@@ -362,6 +381,12 @@ public boolean onPushNotificationClicked(Context context, PushNotificationData n
362
381
public boolean onPushNotificationActionClicked (Context context , PushNotificationData notificationData , String buttonID ) {
363
382
String uri = notificationData .getCallToActionById (buttonID ).getAction ();
364
383
JSONObject customData = bundleToJson (notificationData .getCustomData ());
384
+ try {
385
+ customData = mergeJson (bundleToJson (notificationData .getCustomData ()), notificationData .getPushPayloadJSON ());
386
+ } catch (JSONException e ) {
387
+ e .printStackTrace ();
388
+ Logger .e (TAG , "Exception while merging JSON" );
389
+ }
365
390
webView .sendJavascript ("javascript:webengage.push.onCallbackReceived( 'click', '" + uri + "'," + customData + ");" );
366
391
return false ;
367
392
}
@@ -396,25 +421,6 @@ public boolean onInAppNotificationClicked(Context context, InAppNotificationData
396
421
return false ;
397
422
}
398
423
399
- @ Override
400
- public void onGCMRegistered (Context context , String regID ) {
401
- Logger .d (TAG , regID );
402
- }
403
-
404
- @ Override
405
- public void onGCMMessageReceived (Context context , Intent intent ) {
406
- Logger .d (TAG , intent .getExtras ().toString ());
407
- }
408
-
409
- @ Override
410
- public void onAppInstalled (Context context , Intent intent ) {
411
- Logger .d (TAG + "Install Referrer" , intent .getExtras ().getString ("referrer" ));
412
- }
413
-
414
- @ Override
415
- public void onAppUpgraded (Context context , int oldVersion , int newVersion ) {
416
- }
417
-
418
424
private static JSONObject bundleToJson (Bundle bundle ) {
419
425
if (bundle != null ) {
420
426
JSONObject result = new JSONObject ();
@@ -472,4 +478,11 @@ private List<Object> toList(JSONArray jsonArray) throws JSONException {
472
478
return list ;
473
479
}
474
480
481
+ private static JSONObject mergeJson (JSONObject jsonObject1 , JSONObject jsonObject2 ) throws JSONException {
482
+ for (Iterator <String > it = jsonObject2 .keys (); it .hasNext (); ) {
483
+ String key = it .next ();
484
+ jsonObject1 .put (key , jsonObject2 .get (key ));
485
+ }
486
+ return jsonObject1 ;
487
+ }
475
488
}
0 commit comments