Skip to content

Commit 77c8309

Browse files
Merge pull request #31 from comapi/push_deep_links_v2
Push deep links v2
2 parents 16393d3 + 4b28de2 commit 77c8309

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

COMAPI/foundation/src/main/java/com/comapi/BaseClient.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import com.comapi.internal.push.PushManager;
5555
import com.google.firebase.messaging.RemoteMessage;
5656

57+
import org.json.JSONException;
5758
import org.json.JSONObject;
5859

5960
import java.io.File;
@@ -414,7 +415,7 @@ public void removeListener(StateListener listener) {
414415
listenerListAdapter.removeListener(listener);
415416
}
416417

417-
protected Observable<PushHandleResult> handlePushNotification(Context activityContext, Intent i, boolean startActivity) {
418+
protected Observable<PushHandleResult> handlePush(Context activityContext, Intent i, boolean startActivity) {
418419
if (i.hasExtra(PushDataKeys.KEY_PUSH_DEEP_LINK)) {
419420
JSONObject deepLinkData;
420421
try {
@@ -463,30 +464,33 @@ protected Observable<PushHandleResult> handlePushNotification(Context activityCo
463464
return Observable.fromCallable(() -> new PushHandleResult(null, null, false, false));
464465
}
465466

466-
static protected Observable<PushDetails> parsePush(RemoteMessage message) {
467+
/**
468+
* Parse Firebase Push RemoteNotification to extract deep link url or data send with Dotdigital program
469+
* @param message RemoteMessage received in a push handler implementing PushMessageListener registered with SDK initialisation call.
470+
* @return parsed deep link url or data
471+
*/
472+
static public PushDetails parsePushMessage(RemoteMessage message) throws JSONException {
467473
RemoteMessage.Notification n = message.getNotification();
468474
if (message.getData().containsKey(PushDataKeys.KEY_PUSH_DEEP_LINK)) {
469475
String deepLinkDataJson = message.getData().get(PushDataKeys.KEY_PUSH_DEEP_LINK);
470-
try {
471-
assert deepLinkDataJson != null;
476+
if (deepLinkDataJson != null) {
472477
JSONObject deepLinkData = new JSONObject(deepLinkDataJson);
473478
if (deepLinkData.has(PushDataKeys.KEY_PUSH_URL)) {
474479
String url = deepLinkData.getString(PushDataKeys.KEY_PUSH_URL);
475-
return Observable.fromCallable(() -> new PushDetails(url, null));
480+
return new PushDetails(url, null);
476481
}
477-
} catch (Exception e) {
478-
return Observable.error(e);
482+
} else {
483+
return new PushDetails(null, null);
479484
}
480485
} else if (message.getData().containsKey(PushDataKeys.KEY_PUSH_DATA)) {
481486
String dataJson = message.getData().get(PushDataKeys.KEY_PUSH_DATA);
482-
try {
483-
assert dataJson != null;
487+
if (dataJson != null) {
484488
JSONObject data = new JSONObject(dataJson);
485-
return Observable.fromCallable(() -> new PushDetails(null, data));
486-
} catch (Exception e) {
487-
return Observable.error(e);
489+
return new PushDetails(null, data);
490+
} else {
491+
return new PushDetails(null, null);
488492
}
489493
}
490-
return Observable.fromCallable(() -> new PushDetails(null, null));
494+
return new PushDetails(null, null);
491495
}
492496
}

COMAPI/foundation/src/main/java/com/comapi/ComapiClient.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import android.content.Intent;
2626

2727
import androidx.annotation.NonNull;
28+
import androidx.annotation.Nullable;
2829

2930
import com.comapi.internal.CallbackAdapter;
30-
import com.google.firebase.messaging.RemoteMessage;
3131

3232
import java.io.File;
3333

@@ -120,16 +120,12 @@ public void clean(@NonNull Context context) {
120120
* @param i intent that is retrieved by getIntent() in onCreate or intent passed to onNewIntent lifecycle callbacks
121121
* @param startActivity should start activity from deep link url
122122
* @param callback Contains result of the push notification processing
123-
* getUrl - url passed as a deep link with the notification
123+
* getUrl - url passed as a deep link with the notification by dotdigital program
124+
* getData - data passed with the notification by dotdigital program
124125
* isTrackingSuccessful - was call to record a click for analytics successful;
125126
* isStartActivitySuccessful - was starting activity from url successful
126127
*/
127-
public void handlePush(Context activityContext, Intent i, boolean startActivity, Callback<PushHandleResult> callback) {
128-
adapter.adapt(super.handlePushNotification(activityContext, i, startActivity),callback);
129-
}
130-
131-
public static void parsePushMessage(RemoteMessage message, Callback<PushDetails> callback) {
132-
CallbackAdapter adapter = new CallbackAdapter();
133-
adapter.adapt(BaseClient.parsePush(message), callback);
128+
public void handlePushNotification(@NonNull Context activityContext, @NonNull Intent i, boolean startActivity, @Nullable Callback<PushHandleResult> callback) {
129+
adapter.adapt(super.handlePush(activityContext, i, startActivity),callback);
134130
}
135131
}

COMAPI/foundation/src/main/java/com/comapi/RxComapiClient.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.comapi.internal.lifecycle.LifecycleListener;
3131
import com.comapi.internal.log.Logger;
3232
import com.comapi.internal.network.api.RxComapiService;
33-
import com.google.firebase.messaging.RemoteMessage;
3433

3534
import java.io.File;
3635

@@ -141,11 +140,18 @@ protected RxComapiService getComapiService() {
141140
return service;
142141
}
143142

144-
public Observable<PushHandleResult> handlePush(Context activityContext, Intent i, boolean startActivity) {
145-
return super.handlePushNotification(activityContext, i, startActivity);
146-
}
147-
148-
public Observable<PushDetails> parsePushMessage(RemoteMessage message) {
149-
return BaseClient.parsePush(message);
143+
/**
144+
* Handles click push notification tracking and opens deep link
145+
* @param activityContext pass calling activity here
146+
* @param i intent that is retrieved by getIntent() in onCreate or intent passed to onNewIntent lifecycle callbacks
147+
* @param startActivity should start activity from deep link url
148+
* @return Observable containing result of the push notification processing
149+
* getUrl - url passed as a deep link with the notification
150+
* getData - data passed with the notification by dotdigital program
151+
* isTrackingSuccessful - was call to record a click for analytics successful;
152+
* isStartActivitySuccessful - was starting activity from url successful
153+
*/
154+
public Observable<PushHandleResult> handlePushNotification(Context activityContext, Intent i, boolean startActivity) {
155+
return super.handlePush(activityContext, i, startActivity);
150156
}
151157
}

0 commit comments

Comments
 (0)