Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.iterable.iterableapi;

import android.app.Application;
import android.graphics.Rect;
import android.test.ApplicationTestCase;
import android.view.Gravity;

/**
* Tests
* Created by David Truong dt@iterable.com.
*/
public class IterableInAppTest extends ApplicationTestCase<Application> {
public IterableInAppTest() {
super(Application.class);
}

IterableInAppHTMLNotification notification;

public void setUp() throws Exception {
super.setUp();

notification = IterableInAppHTMLNotification.createInstance(getContext().getApplicationContext(), "");
}

public void testGetLocationFull() {
Rect padding = new Rect(0,0,0,0);
int verticalLocation = notification.getVerticalLocation(padding);
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
}

public void testGetLocationTop() {
Rect padding = new Rect(0,0,0,-1);
int verticalLocation = notification.getVerticalLocation(padding);
assertEquals(Gravity.TOP, verticalLocation);
}

public void testGetLocationBottom() throws Exception {
Rect padding = new Rect(0,-1,0,0);
int verticalLocation = notification.getVerticalLocation(padding);
assertEquals(Gravity.BOTTOM, verticalLocation);
}

public void testGetLocationCenter() {
Rect padding = new Rect(0,-1,0,-1);
int verticalLocation = notification.getVerticalLocation(padding);
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
}

public void testGetLocationRandom() {
Rect padding = new Rect(0,20,0,30);
int verticalLocation = notification.getVerticalLocation(padding);
assertEquals(Gravity.CENTER_VERTICAL, verticalLocation);
}
}
40 changes: 23 additions & 17 deletions iterableapi/src/main/java/com/iterable/iterableapi/IterableApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;

Expand Down Expand Up @@ -533,15 +534,22 @@ public void execute(String payload) {
JSONObject dialogOptions = IterableInAppManager.getNextMessageFromPayload(payload);
if (dialogOptions != null) {
JSONObject message = dialogOptions.optJSONObject(IterableConstants.ITERABLE_IN_APP_CONTENT);
int templateId = message.optInt(IterableConstants.KEY_TEMPLATE_ID);

int campaignId = dialogOptions.optInt(IterableConstants.KEY_CAMPAIGN_ID);
String messageId = dialogOptions.optString(IterableConstants.KEY_MESSAGE_ID);

IterableApi.sharedInstance.trackInAppOpen(campaignId, templateId, messageId);
IterableApi.sharedInstance.inAppConsume(messageId);
IterableInAppManager.showNotification(context, message, messageId, clickCallback);

if (message != null) {
String messageId = dialogOptions.optString(IterableConstants.KEY_MESSAGE_ID);
String html = message.optString("html");
if (html.toLowerCase().contains("href")) {
JSONObject paddingOptions = message.optJSONObject("inAppDisplaySettings");
Rect padding = IterableInAppManager.getPaddingFromPayload(paddingOptions);

double backgroundAlpha = message.optDouble("backgroundAlpha", 0);
IterableInAppManager.showIterableNotificationHTML(context, html, messageId, clickCallback, backgroundAlpha, padding);
} else {
IterableLogger.w(TAG, "No href tag in found in the in-app html payload: "+ html);
}

IterableApi.sharedInstance.inAppConsume(messageId);

}
}
}
});
Expand All @@ -558,6 +566,8 @@ public void getInAppMessages(int count, IterableHelper.IterableActionHandler onC
try {
addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.ITERABLE_IN_APP_COUNT, count);
requestJSON.put(IterableConstants.KEY_PLATFORM, IterableConstants.ITBL_PLATFORM_ANDROID);
requestJSON.put(IterableConstants.ITBL_KEY_SDK_VERSION, IterableConstants.ITBL_KEY_SDK_VERSION_NUMBER);
}
catch (JSONException e) {
e.printStackTrace();
Expand All @@ -567,17 +577,13 @@ public void getInAppMessages(int count, IterableHelper.IterableActionHandler onC

/**
* Tracks an InApp open.
* @param campaignId
* @param templateId
* @param messageId
*/
public void trackInAppOpen(int campaignId, int templateId, String messageId) {
public void trackInAppOpen(String messageId) {
JSONObject requestJSON = new JSONObject();

try {
addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.KEY_CAMPAIGN_ID, campaignId);
requestJSON.put(IterableConstants.KEY_TEMPLATE_ID, templateId);
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
}
catch (JSONException e) {
Expand All @@ -590,15 +596,15 @@ public void trackInAppOpen(int campaignId, int templateId, String messageId) {
/**
* Tracks an InApp click.
* @param messageId
* @param buttonIndex
* @param urlClick
*/
public void trackInAppClick(String messageId, int buttonIndex) {
public void trackInAppClick(String messageId, String urlClick) {
JSONObject requestJSON = new JSONObject();

try {
addEmailOrUserIdToJson(requestJSON);
requestJSON.put(IterableConstants.KEY_MESSAGE_ID, messageId);
requestJSON.put(IterableConstants.ITERABLE_IN_APP_BUTTON_INDEX, buttonIndex);
requestJSON.put(IterableConstants.ITERABLE_IN_APP_URL_CLICK, urlClick);
}
catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final class IterableConstants {
public static final String DEFAULT_SOUND = "default";
public static final String SOUND_FOLDER_IDENTIFIER = "raw";
public static final String ANDROID_RESOURCE_PATH = "android.resource://";
public static final String ANDROID_STRING = "string";
public static final String ANDROID_STRING = "string";

//Firebase
public static final String FIREBASE_RESOURCE_ID = "firebase_database_url";
Expand Down Expand Up @@ -104,9 +104,14 @@ public final class IterableConstants {
public static final String ITERABLE_IN_APP_TEXT = "text";
public static final String ITERABLE_IN_APP_TITLE = "title";
public static final String ITERABLE_IN_APP_TYPE = "displayType";
public static final String ITERABLE_IN_APP_URL_CLICK = "urlClick";

public static final String ITERABLE_IN_APP_TYPE_BOTTOM = "BOTTOM";
public static final String ITERABLE_IN_APP_TYPE_CENTER = "MIDDLE";
public static final String ITERABLE_IN_APP_TYPE_FULL = "FULL";
public static final String ITERABLE_IN_APP_TYPE_TOP = "TOP";

public static final String ITBL_KEY_SDK_VERSION = "SDKVersion";
public static final String ITBL_PLATFORM_ANDROID = "Android";
public static final String ITBL_KEY_SDK_VERSION_NUMBER = "0.0.0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public IterableInAppActionListener(Dialog dialog, int index, String actionName,
*/
@Override
public void onClick(View v) {
if (messageId != null) {
IterableApi.sharedInstance.trackInAppClick(messageId, index);
}
if (onClickCallback != null) {
onClickCallback.execute(actionName);
}
Expand Down
Loading