Skip to content

Commit 504fd8a

Browse files
authored
Merge pull request #14 from Iterable/feature/ITBL-2397-in-app-consume
Feature/itbl 2397 in app consume
2 parents bb58cb5 + e8af255 commit 504fd8a

File tree

6 files changed

+45
-51
lines changed

6 files changed

+45
-51
lines changed

iterableapi/src/androidTest/java/com/iterable/iterableapi/IterableNotificationDataTest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ public class IterableNotificationDataTest extends ApplicationTestCase<Applicatio
1010
public IterableNotificationDataTest() {
1111
super(Application.class);
1212
}
13-
14-
public void testPayloadParams() throws Exception {
15-
int campaignId = 1;
16-
int templateId = 2;
17-
String messageId = "abc123";
18-
IterableNotificationData iterableNotificationData = new IterableNotificationData(campaignId, templateId, messageId);
19-
assertEquals(1, iterableNotificationData.getCampaignId());
20-
assertEquals(2, iterableNotificationData.getTemplateId());
21-
assertEquals("abc123", iterableNotificationData.getMessageId());
22-
assertEquals(false, iterableNotificationData.getIsGhostPush());
23-
}
2413

2514
public void testPayloadString() throws Exception {
2615
String userInfo = "{\"campaignId\": 1,\n" +

iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ public void execute(String payload) {
539539
String messageId = dialogOptions.optString(IterableConstants.KEY_MESSAGE_ID);
540540

541541
IterableApi.sharedInstance.trackInAppOpen(campaignId, templateId, messageId);
542-
IterableNotificationData trackParams = new IterableNotificationData(campaignId, templateId, messageId);
543-
IterableInAppManager.showNotification(context, message, trackParams, clickCallback);
542+
IterableApi.sharedInstance.inAppConsume(messageId);
543+
IterableInAppManager.showNotification(context, message, messageId, clickCallback);
544544

545545
}
546546
}
@@ -589,18 +589,14 @@ public void trackInAppOpen(int campaignId, int templateId, String messageId) {
589589

590590
/**
591591
* Tracks an InApp click.
592-
* @param campaignId
593-
* @param templateId
594592
* @param messageId
595593
* @param buttonIndex
596594
*/
597-
public void trackInAppClick(int campaignId, int templateId, String messageId, int buttonIndex) {
595+
public void trackInAppClick(String messageId, int buttonIndex) {
598596
JSONObject requestJSON = new JSONObject();
599597

600598
try {
601599
addEmailOrUserIdToJson(requestJSON);
602-
requestJSON.put(IterableConstants.KEY_CAMPAIGN_ID, campaignId);
603-
requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
604600
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
605601
requestJSON.put(IterableConstants.ITERABLE_IN_APP_BUTTON_INDEX, buttonIndex);
606602
}
@@ -611,6 +607,24 @@ public void trackInAppClick(int campaignId, int templateId, String messageId, in
611607
sendPostRequest(IterableConstants.ENDPOINT_TRACK_INAPP_CLICK, requestJSON);
612608
}
613609

610+
/**
611+
* Consumes an InApp message.
612+
* @param messageId
613+
*/
614+
public void inAppConsume(String messageId) {
615+
JSONObject requestJSON = new JSONObject();
616+
617+
try {
618+
addEmailOrUserIdToJson(requestJSON);
619+
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
620+
}
621+
catch (JSONException e) {
622+
e.printStackTrace();
623+
}
624+
625+
sendPostRequest(IterableConstants.ENDPOINT_INAPP_CONSUME, requestJSON);
626+
}
627+
614628
//---------------------------------------------------------------------------------------
615629
//endregion
616630

iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public final class IterableConstants {
3333
//API Endpoint Key Constants
3434
public static final String ENDPOINT_DISABLE_DEVICE = "users/disableDevice";
3535
public static final String ENDPOINT_GET_INAPP_MESSAGES = "inApp/getMessages";
36+
public static final String ENDPOINT_INAPP_CONSUME = "events/inAppConsume";
3637
public static final String ENDPOINT_PUSH_TARGET = "push/target";
3738
public static final String ENDPOINT_REGISTER_DEVICE_TOKEN = "users/registerDeviceToken";
3839
public static final String ENDPOINT_TRACK = "events/track";

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppActionListener.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ public class IterableInAppActionListener implements View.OnClickListener {
1313
int index;
1414
String actionName;
1515
IterableHelper.IterableActionHandler onClickCallback;
16-
IterableNotificationData trackParams;
16+
String messageId;
1717

1818
/**
1919
* A custom onClickListener which stores data about the dialog context.
2020
* @param dialog
2121
* @param index
2222
* @param actionName
23-
* @param trackParams
23+
* @param messageId
2424
* @param onClickCallback
2525
*/
26-
public IterableInAppActionListener(Dialog dialog, int index, String actionName, IterableNotificationData trackParams, IterableHelper.IterableActionHandler onClickCallback){
26+
public IterableInAppActionListener(Dialog dialog, int index, String actionName, String messageId, IterableHelper.IterableActionHandler onClickCallback){
2727
this.index = index;
2828
this.actionName = actionName;
2929
this.onClickCallback = onClickCallback;
3030
this.dialog = dialog;
31-
this.trackParams = trackParams;
31+
this.messageId = messageId;
3232
}
3333

3434
/**
@@ -37,8 +37,8 @@ public IterableInAppActionListener(Dialog dialog, int index, String actionName,
3737
*/
3838
@Override
3939
public void onClick(View v) {
40-
if (trackParams != null) {
41-
IterableApi.sharedInstance.trackInAppClick(trackParams.getCampaignId(), trackParams.getTemplateId(), trackParams.getMessageId(), index);
40+
if (messageId != null) {
41+
IterableApi.sharedInstance.trackInAppClick(messageId, index);
4242
}
4343
if (onClickCallback != null) {
4444
onClickCallback.execute(actionName);

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ public class IterableInAppManager {
3737
* @param dialogOptions
3838
* @param clickCallback
3939
*/
40-
public static void showNotification(Context context, JSONObject dialogOptions, IterableNotificationData trackParams, IterableHelper.IterableActionHandler clickCallback) {
40+
public static void showNotification(Context context, JSONObject dialogOptions, String messageId, IterableHelper.IterableActionHandler clickCallback) {
4141
if(dialogOptions != null) {
4242
String type = dialogOptions.optString(IterableConstants.ITERABLE_IN_APP_TYPE);
4343
if (type.equalsIgnoreCase(IterableConstants.ITERABLE_IN_APP_TYPE_FULL)) {
44-
showFullScreenDialog(context, dialogOptions, trackParams, clickCallback);
44+
showFullScreenDialog(context, dialogOptions, messageId, clickCallback);
4545
} else {
46-
showNotificationDialog(context, dialogOptions, trackParams, clickCallback);
46+
showNotificationDialog(context, dialogOptions, messageId, clickCallback);
4747
}
4848
} else {
4949
IterableLogger.d(TAG, "In-App notification not displayed: showNotification must contain valid dialogOptions");
@@ -56,7 +56,7 @@ public static void showNotification(Context context, JSONObject dialogOptions, I
5656
* @param dialogParameters
5757
* @param clickCallback
5858
*/
59-
static void showNotificationDialog(Context context, JSONObject dialogParameters, IterableNotificationData trackParams, IterableHelper.IterableActionHandler clickCallback) {
59+
static void showNotificationDialog(Context context, JSONObject dialogParameters, String messageId, IterableHelper.IterableActionHandler clickCallback) {
6060
Dialog dialog = new Dialog(context, android.R.style.Theme_Material_NoActionBar);
6161
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
6262
dialog.setCanceledOnTouchOutside(true);
@@ -105,7 +105,7 @@ static void showNotificationDialog(Context context, JSONObject dialogParameters,
105105
//Buttons
106106
JSONArray buttonJson = dialogParameters.optJSONArray(IterableConstants.ITERABLE_IN_APP_BUTTONS);
107107
if (buttonJson != null) {
108-
verticalLayout.addView(createButtons(context, dialog, buttonJson, null, clickCallback));
108+
verticalLayout.addView(createButtons(context, dialog, buttonJson, messageId, clickCallback));
109109
}
110110

111111
dialog.setContentView(verticalLayout);
@@ -118,7 +118,7 @@ static void showNotificationDialog(Context context, JSONObject dialogParameters,
118118
* @param dialogParameters
119119
* @param clickCallback
120120
*/
121-
static void showFullScreenDialog(Context context, JSONObject dialogParameters, IterableNotificationData trackParams, IterableHelper.IterableActionHandler clickCallback) {
121+
static void showFullScreenDialog(Context context, JSONObject dialogParameters, String messageId, IterableHelper.IterableActionHandler clickCallback) {
122122
Dialog dialog = new Dialog(context, android.R.style.Theme_Light);
123123
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
124124

@@ -184,7 +184,7 @@ static void showFullScreenDialog(Context context, JSONObject dialogParameters, I
184184
//Buttons
185185
JSONArray buttonJson = dialogParameters.optJSONArray(IterableConstants.ITERABLE_IN_APP_BUTTONS);
186186
if (buttonJson != null) {
187-
View buttons = createButtons(context, dialog, buttonJson, trackParams, clickCallback);
187+
View buttons = createButtons(context, dialog, buttonJson, messageId, clickCallback);
188188
LinearLayout.LayoutParams buttonParams = new LinearLayout.LayoutParams(
189189
LinearLayout.LayoutParams.MATCH_PARENT,
190190
LinearLayout.LayoutParams.WRAP_CONTENT);
@@ -223,11 +223,11 @@ public static JSONObject getNextMessageFromPayload(String payload) {
223223
* @param context
224224
* @param dialog
225225
* @param buttons
226-
* @param trackParams
226+
* @param messageId
227227
* @param clickCallback
228228
* @return
229229
*/
230-
private static View createButtons(Context context, Dialog dialog, JSONArray buttons, IterableNotificationData trackParams, IterableHelper.IterableActionHandler clickCallback) {
230+
private static View createButtons(Context context, Dialog dialog, JSONArray buttons, String messageId, IterableHelper.IterableActionHandler clickCallback) {
231231
LinearLayout.LayoutParams equalParamWidth = new LinearLayout.LayoutParams(
232232
LinearLayout.LayoutParams.MATCH_PARENT,
233233
LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
@@ -244,7 +244,7 @@ private static View createButtons(Context context, Dialog dialog, JSONArray butt
244244
button.setBackgroundColor(getIntColorFromJson(buttonJson, IterableConstants.ITERABLE_IN_APP_BACKGROUND_COLOR, Color.LTGRAY));
245245
String action = buttonJson.optString(IterableConstants.ITERABLE_IN_APP_BUTTON_ACTION);
246246
if (!action.isEmpty()) {
247-
button.setOnClickListener(new IterableInAppActionListener(dialog, i, action, trackParams, clickCallback));
247+
button.setOnClickListener(new IterableInAppActionListener(dialog, i, action, messageId, clickCallback));
248248
}
249249

250250
JSONObject textJson = buttonJson.optJSONObject(IterableConstants.ITERABLE_IN_APP_CONTENT);

iterableapi/src/main/java/com/iterable/iterableapi/IterableNotificationData.java

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
* Created by davidtruong on 5/23/16.
88
*/
99
class IterableNotificationData {
10-
private int campaignId;
11-
private int templateId;
12-
private String messageId;
13-
private boolean isGhostPush;
10+
static final String TAG = "IterableNoticationData";
11+
12+
private int campaignId;
13+
private int templateId;
14+
private String messageId;
15+
private boolean isGhostPush;
1416

1517
/**
1618
* Creates the notification data from a string
@@ -35,22 +37,10 @@ class IterableNotificationData {
3537
isGhostPush = iterableJson.getBoolean(IterableConstants.IS_GHOST_PUSH);
3638
}
3739
} catch (JSONException e) {
38-
e.printStackTrace();
40+
IterableLogger.e(TAG, e.toString());
3941
}
4042
}
4143

42-
/**
43-
* Creates the notification data
44-
* @param campaignId
45-
* @param templateId
46-
* @param messageId
47-
*/
48-
IterableNotificationData(int campaignId, int templateId, String messageId) {
49-
this.campaignId = campaignId;
50-
this.templateId = templateId;
51-
this.messageId = messageId;
52-
}
53-
5444
/**
5545
* Returns the campaignId
5646
* @return

0 commit comments

Comments
 (0)