Skip to content

Commit b1e9c7f

Browse files
authored
Merge pull request #19 from Iterable/feature/ITBL-2763-html-in-app-notifcation
<In-Progress> Feature/itbl 2763 html in app notifcation
2 parents bce9623 + a9284a1 commit b1e9c7f

File tree

6 files changed

+464
-21
lines changed

6 files changed

+464
-21
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.iterable.iterableapi;
2+
3+
import android.app.Application;
4+
import android.graphics.Rect;
5+
import android.test.ApplicationTestCase;
6+
import android.view.Gravity;
7+
8+
/**
9+
* Tests
10+
* Created by David Truong [email protected].
11+
*/
12+
public class IterableInAppTest extends ApplicationTestCase<Application> {
13+
public IterableInAppTest() {
14+
super(Application.class);
15+
}
16+
17+
IterableInAppHTMLNotification notification;
18+
19+
public void setUp() throws Exception {
20+
super.setUp();
21+
22+
notification = IterableInAppHTMLNotification.createInstance(getContext().getApplicationContext(), "");
23+
}
24+
25+
public void testGetLocationFull() {
26+
Rect padding = new Rect(0,0,0,0);
27+
int verticalLocation = notification.getVerticalLocation(padding);
28+
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
29+
}
30+
31+
public void testGetLocationTop() {
32+
Rect padding = new Rect(0,0,0,-1);
33+
int verticalLocation = notification.getVerticalLocation(padding);
34+
assertEquals(Gravity.TOP, verticalLocation);
35+
}
36+
37+
public void testGetLocationBottom() throws Exception {
38+
Rect padding = new Rect(0,-1,0,0);
39+
int verticalLocation = notification.getVerticalLocation(padding);
40+
assertEquals(Gravity.BOTTOM, verticalLocation);
41+
}
42+
43+
public void testGetLocationCenter() {
44+
Rect padding = new Rect(0,-1,0,-1);
45+
int verticalLocation = notification.getVerticalLocation(padding);
46+
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
47+
}
48+
49+
public void testGetLocationRandom() {
50+
Rect padding = new Rect(0,20,0,30);
51+
int verticalLocation = notification.getVerticalLocation(padding);
52+
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
53+
}
54+
}

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

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.content.SharedPreferences;
7+
import android.graphics.Rect;
78
import android.os.Build;
89
import android.os.Bundle;
910

@@ -533,15 +534,22 @@ public void execute(String payload) {
533534
JSONObject dialogOptions = IterableInAppManager.getNextMessageFromPayload(payload);
534535
if (dialogOptions != null) {
535536
JSONObject message = dialogOptions.optJSONObject(IterableConstants.ITERABLE_IN_APP_CONTENT);
536-
int templateId = message.optInt(IterableConstants.KEY_TEMPLATE_ID);
537-
538-
int campaignId = dialogOptions.optInt(IterableConstants.KEY_CAMPAIGN_ID);
539-
String messageId = dialogOptions.optString(IterableConstants.KEY_MESSAGE_ID);
540-
541-
IterableApi.sharedInstance.trackInAppOpen(campaignId, templateId, messageId);
542-
IterableApi.sharedInstance.inAppConsume(messageId);
543-
IterableInAppManager.showNotification(context, message, messageId, clickCallback);
544-
537+
if (message != null) {
538+
String messageId = dialogOptions.optString(IterableConstants.KEY_MESSAGE_ID);
539+
String html = message.optString("html");
540+
if (html.toLowerCase().contains("href")) {
541+
JSONObject paddingOptions = message.optJSONObject("inAppDisplaySettings");
542+
Rect padding = IterableInAppManager.getPaddingFromPayload(paddingOptions);
543+
544+
double backgroundAlpha = message.optDouble("backgroundAlpha", 0);
545+
IterableInAppManager.showIterableNotificationHTML(context, html, messageId, clickCallback, backgroundAlpha, padding);
546+
} else {
547+
IterableLogger.w(TAG, "No href tag in found in the in-app html payload: "+ html);
548+
}
549+
550+
IterableApi.sharedInstance.inAppConsume(messageId);
551+
552+
}
545553
}
546554
}
547555
});
@@ -558,6 +566,8 @@ public void getInAppMessages(int count, IterableHelper.IterableActionHandler onC
558566
try {
559567
addEmailOrUserIdToJson(requestJSON);
560568
requestJSON.put(IterableConstants.ITERABLE_IN_APP_COUNT, count);
569+
requestJSON.put(IterableConstants.KEY_PLATFORM, IterableConstants.ITBL_PLATFORM_ANDROID);
570+
requestJSON.put(IterableConstants.ITBL_KEY_SDK_VERSION, IterableConstants.ITBL_KEY_SDK_VERSION_NUMBER);
561571
}
562572
catch (JSONException e) {
563573
e.printStackTrace();
@@ -567,17 +577,13 @@ public void getInAppMessages(int count, IterableHelper.IterableActionHandler onC
567577

568578
/**
569579
* Tracks an InApp open.
570-
* @param campaignId
571-
* @param templateId
572580
* @param messageId
573581
*/
574-
public void trackInAppOpen(int campaignId, int templateId, String messageId) {
582+
public void trackInAppOpen(String messageId) {
575583
JSONObject requestJSON = new JSONObject();
576584

577585
try {
578586
addEmailOrUserIdToJson(requestJSON);
579-
requestJSON.put(IterableConstants.KEY_CAMPAIGN_ID, campaignId);
580-
requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
581587
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
582588
}
583589
catch (JSONException e) {
@@ -590,15 +596,15 @@ public void trackInAppOpen(int campaignId, int templateId, String messageId) {
590596
/**
591597
* Tracks an InApp click.
592598
* @param messageId
593-
* @param buttonIndex
599+
* @param urlClick
594600
*/
595-
public void trackInAppClick(String messageId, int buttonIndex) {
601+
public void trackInAppClick(String messageId, String urlClick) {
596602
JSONObject requestJSON = new JSONObject();
597603

598604
try {
599605
addEmailOrUserIdToJson(requestJSON);
600606
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
601-
requestJSON.put(IterableConstants.ITERABLE_IN_APP_BUTTON_INDEX, buttonIndex);
607+
requestJSON.put(IterableConstants.ITERABLE_IN_APP_URL_CLICK, urlClick);
602608
}
603609
catch (JSONException e) {
604610
e.printStackTrace();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public final class IterableConstants {
7676
public static final String DEFAULT_SOUND = "default";
7777
public static final String SOUND_FOLDER_IDENTIFIER = "raw";
7878
public static final String ANDROID_RESOURCE_PATH = "android.resource://";
79-
public static final String ANDROID_STRING = "string";
79+
public static final String ANDROID_STRING = "string";
8080

8181
//Firebase
8282
public static final String FIREBASE_RESOURCE_ID = "firebase_database_url";
@@ -104,9 +104,14 @@ public final class IterableConstants {
104104
public static final String ITERABLE_IN_APP_TEXT = "text";
105105
public static final String ITERABLE_IN_APP_TITLE = "title";
106106
public static final String ITERABLE_IN_APP_TYPE = "displayType";
107+
public static final String ITERABLE_IN_APP_URL_CLICK = "urlClick";
107108

108109
public static final String ITERABLE_IN_APP_TYPE_BOTTOM = "BOTTOM";
109110
public static final String ITERABLE_IN_APP_TYPE_CENTER = "MIDDLE";
110111
public static final String ITERABLE_IN_APP_TYPE_FULL = "FULL";
111112
public static final String ITERABLE_IN_APP_TYPE_TOP = "TOP";
113+
114+
public static final String ITBL_KEY_SDK_VERSION = "SDKVersion";
115+
public static final String ITBL_PLATFORM_ANDROID = "Android";
116+
public static final String ITBL_KEY_SDK_VERSION_NUMBER = "0.0.0";
112117
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ public IterableInAppActionListener(Dialog dialog, int index, String actionName,
3737
*/
3838
@Override
3939
public void onClick(View v) {
40-
if (messageId != null) {
41-
IterableApi.sharedInstance.trackInAppClick(messageId, index);
42-
}
4340
if (onClickCallback != null) {
4441
onClickCallback.execute(actionName);
4542
}

0 commit comments

Comments
 (0)