Skip to content

Commit

Permalink
Merge pull request #341 from Iterable/next-version
Browse files Browse the repository at this point in the history
[MOB-2774] SDK version 3.2.13 release
  • Loading branch information
roninopf authored Apr 30, 2021
2 parents d538da4 + 395da9e commit 2a81b48
Showing 9 changed files with 86 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
#### Fixed
- nothing yet

## [3.2.13](https://github.com/Iterable/iterable-android-sdk/releases/tag/3.2.13)
#### Added
- In-app message prioritization - Ordering the display of in-app messages based on a priority you select in Iterable when creating in-app campaigns

## [3.2.12](https://github.com/Iterable/iterable-android-sdk/releases/tag/3.2.12)
#### Added
- Support for the display of a custom message (title and body) in an empty mobile inbox.
2 changes: 1 addition & 1 deletion iterableapi-ui/build.gradle
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ ext {
siteUrl = 'https://github.com/Iterable/iterable-android-sdk'
gitUrl = 'https://github.com/Iterable/iterable-android-sdk.git'

libraryVersion = '3.2.12'
libraryVersion = '3.2.13'

developerId = 'davidtruong'
developerName = 'David Truong'
4 changes: 2 additions & 2 deletions iterableapi/build.gradle
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ android {
minSdkVersion 15
targetSdkVersion 27

buildConfigField "String", "ITERABLE_SDK_VERSION", "\"3.2.12\""
buildConfigField "String", "ITERABLE_SDK_VERSION", "\"3.2.13\""

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
@@ -72,7 +72,7 @@ ext {
siteUrl = 'https://github.com/Iterable/iterable-android-sdk'
gitUrl = 'https://github.com/Iterable/iterable-android-sdk.git'

libraryVersion = '3.2.12'
libraryVersion = '3.2.13'

developerId = 'davidtruong'
developerName = 'David Truong'
Original file line number Diff line number Diff line change
@@ -185,6 +185,7 @@ public final class IterableConstants {
public static final String ITERABLE_IN_APP_CUSTOM_PAYLOAD = "customPayload";
public static final String ITERABLE_IN_APP_TRIGGER = "trigger";
public static final String ITERABLE_IN_APP_TRIGGER_TYPE = "type";
public static final String ITERABLE_IN_APP_PRIORITY_LEVEL = "priorityLevel";
public static final String ITERABLE_IN_APP_SAVE_TO_INBOX = "saveToInbox";
public static final String ITERABLE_IN_APP_SILENT_INBOX = "silentInbox";
public static final String ITERABLE_IN_APP_INBOX_METADATA = "inboxMetadata";
@@ -210,6 +211,12 @@ public final class IterableConstants {
public static final int ITERABLE_IN_APP_ANIMATION_DURATION = 500;
public static final int ITERABLE_IN_APP_BACKGROUND_ANIMATION_DURATION = 300;

public static final double ITERABLE_IN_APP_PRIORITY_LEVEL_LOW = 400.0;
public static final double ITERABLE_IN_APP_PRIORITY_LEVEL_MEDIUM = 300.0;
public static final double ITERABLE_IN_APP_PRIORITY_LEVEL_HIGH = 200.0;
public static final double ITERABLE_IN_APP_PRIORITY_LEVEL_CRITICAL = 100.0;
public static final double ITERABLE_IN_APP_PRIORITY_LEVEL_UNASSIGNED = 300.5;

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";
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -345,6 +347,25 @@ private void syncWithRemoteQueue(List<IterableInAppMessage> remoteQueue) {
}
}

private List<IterableInAppMessage> getMessagesSortedByPriorityLevel(List<IterableInAppMessage> messages) {
List<IterableInAppMessage> messagesByPriorityLevel = messages;

Collections.sort(messagesByPriorityLevel, new Comparator<IterableInAppMessage>() {
@Override
public int compare(IterableInAppMessage message1, IterableInAppMessage message2) {
if (message1.getPriorityLevel() < message2.getPriorityLevel()) {
return -1;
} else if (message1.getPriorityLevel() == message2.getPriorityLevel()) {
return 0;
} else {
return 1;
}
}
});

return messagesByPriorityLevel;
}

private void processMessages() {
if (!activityMonitor.isInForeground() || isShowingInApp() || !canShowInAppAfterPrevious() || isAutoDisplayPaused()) {
return;
@@ -353,7 +374,10 @@ private void processMessages() {
IterableLogger.printInfo();

List<IterableInAppMessage> messages = getMessages();
for (IterableInAppMessage message : messages) {

List<IterableInAppMessage> messagesByPriorityLevel = getMessagesSortedByPriorityLevel(messages);

for (IterableInAppMessage message : messagesByPriorityLevel) {
if (!message.isProcessed() && !message.isConsumed() && message.getTriggerType() == TriggerType.IMMEDIATE) {
IterableLogger.d(TAG, "Calling onNewInApp on " + message.getMessageId());
InAppResponse response = handler.onNewInApp(message);
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ public class IterableInAppMessage {
private final @NonNull Date createdAt;
private final @NonNull Date expiresAt;
private final @NonNull Trigger trigger;
private final @NonNull double priorityLevel;
private final @Nullable Boolean saveToInbox;
private final @Nullable InboxMetadata inboxMetadata;
private final @Nullable Long campaignId;
@@ -37,6 +38,7 @@ public class IterableInAppMessage {
@NonNull Date createdAt,
@NonNull Date expiresAt,
@NonNull Trigger trigger,
@NonNull Double priorityLevel,
@Nullable Boolean saveToInbox,
@Nullable InboxMetadata inboxMetadata,
@Nullable Long campaignId) {
@@ -47,6 +49,7 @@ public class IterableInAppMessage {
this.createdAt = createdAt;
this.expiresAt = expiresAt;
this.trigger = trigger;
this.priorityLevel = priorityLevel;
this.saveToInbox = saveToInbox;
this.inboxMetadata = inboxMetadata;
this.campaignId = campaignId;
@@ -276,6 +279,10 @@ Trigger.TriggerType getTriggerType() {
return trigger.type;
}

public double getPriorityLevel() {
return priorityLevel;
}

public boolean isInboxMessage() {
return saveToInbox != null ? saveToInbox : false;
}
@@ -358,6 +365,8 @@ static IterableInAppMessage fromJSONObject(@NonNull JSONObject messageJson, @Nul
customPayload = new JSONObject();
}

double priorityLevel = messageJson.optDouble(IterableConstants.ITERABLE_IN_APP_PRIORITY_LEVEL, IterableConstants.ITERABLE_IN_APP_PRIORITY_LEVEL_UNASSIGNED);

Boolean saveToInbox = messageJson.has(IterableConstants.ITERABLE_IN_APP_SAVE_TO_INBOX) ? messageJson.optBoolean(IterableConstants.ITERABLE_IN_APP_SAVE_TO_INBOX) : null;
JSONObject inboxPayloadJson = messageJson.optJSONObject(IterableConstants.ITERABLE_IN_APP_INBOX_METADATA);
InboxMetadata inboxMetadata = InboxMetadata.fromJSONObject(inboxPayloadJson);
@@ -370,6 +379,7 @@ static IterableInAppMessage fromJSONObject(@NonNull JSONObject messageJson, @Nul
createdAt,
expiresAt,
trigger,
priorityLevel,
saveToInbox,
inboxMetadata,
campaignId);
@@ -400,7 +410,11 @@ JSONObject toJSONObject() {
if (expiresAt != null) {
messageJson.putOpt(IterableConstants.ITERABLE_IN_APP_EXPIRES_AT, expiresAt.getTime());
}

messageJson.putOpt(IterableConstants.ITERABLE_IN_APP_TRIGGER, trigger.toJSONObject());

messageJson.putOpt(IterableConstants.ITERABLE_IN_APP_PRIORITY_LEVEL, priorityLevel);

inAppDisplaySettingsJson = encodePaddingRectToJson(content.padding);

inAppDisplaySettingsJson.put(IterableConstants.ITERABLE_IN_APP_SHOULD_ANIMATE, content.inAppDisplaySettings.shouldAnimate);
Original file line number Diff line number Diff line change
@@ -397,7 +397,7 @@ public void testAuthTokenPresentInRequest() throws Exception {
public void testAuthFailureReturns401() throws InterruptedException {
doReturn(expiredJWT).when(authHandler).onAuthTokenRequested();
dispatcher.enqueueResponse("/events/inAppConsume", new MockResponse().setResponseCode(401).setBody("{\"code\": \"InvalidJwtPayload\"}"));
IterableApi.getInstance().inAppConsume(new IterableInAppMessage("asd", null, null, null, null, null, null, null, (long) 2), null, null);
IterableApi.getInstance().inAppConsume(new IterableInAppMessage("asd", null, null, null, null, null, 0.0, null, null, (long) 2), null, null);
Robolectric.flushForegroundThreadScheduler();
assertEquals(IterableApi.getInstance().getAuthToken(), expiredJWT);
}
41 changes: 30 additions & 11 deletions iterableapi/src/test/resources/inapp_payload_multiple.json
Original file line number Diff line number Diff line change
@@ -22,14 +22,19 @@
"left": {
"percentage": 0
},
"bgColor": {"hex": "#ABCDEF", "alpha": 0.5},
"bgColor": {
"hex": "#ABCDEF",
"alpha": 0.5
},
"shouldAnimate": true
}
},
"customPayload": {
"intValue": 123
}
},{
},
"priorityLevel": 300.5
},
{
"messageId": "7kx2MmoGdCpuZao9fDueuQoXVAZuDaVY",
"content": {
"html": "<html><head></head><body>Test2</body></html>",
@@ -46,14 +51,19 @@
"left": {
"percentage": 0
},
"bgColor": {"hex": "#ABCDEF", "alpha": 0.5},
"bgColor": {
"hex": "#ABCDEF",
"alpha": 0.5
},
"shouldAnimate": true
}
},
"customPayload": {
"intValue": 123
}
},{
},
"priorityLevel": 100.0
},
{
"messageId": "7kx2MmoGdCpuZao9fDueuQoXVAZuDaVZ",
"expiresAt": 1549157312395,
"trigger": {
@@ -78,14 +88,19 @@
"left": {
"percentage": 0
},
"bgColor": {"hex": "#ABCDEF", "alpha": 0.5},
"bgColor": {
"hex": "#ABCDEF",
"alpha": 0.5
},
"shouldAnimate": true
}
},
"customPayload": {
"intValue": 123
}
},{
},
"priorityLevel": 200.5
},
{
"messageId": "7kx2MmoGdCpuZao9fDueuQoXVAZuDaV0",
"expiresAt": 1549157312395,
"trigger": {
@@ -106,7 +121,10 @@
"left": {
"percentage": 0
},
"bgColor": {"hex": "#ABCDEF", "alpha": 0.5},
"bgColor": {
"hex": "#ABCDEF",
"alpha": 0.5
},
"shouldAnimate": true
}
},
@@ -115,7 +133,8 @@
"title": "Title",
"subtitle": "Subtitle",
"icon": "icon.png"
}
},
"priorityLevel": 400.0
}
]
}
4 changes: 2 additions & 2 deletions sample-apps/inbox-customization/app/build.gradle
Original file line number Diff line number Diff line change
@@ -33,8 +33,8 @@ dependencies {
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
implementation 'com.google.android.material:material:1.1.0'

implementation 'com.iterable:iterableapi:3.2.12'
implementation 'com.iterable:iterableapi-ui:3.2.12'
implementation 'com.iterable:iterableapi:3.2.13'
implementation 'com.iterable:iterableapi-ui:3.2.13'
implementation 'com.squareup.okhttp3:mockwebserver:4.2.2'

testImplementation 'junit:junit:4.12'

0 comments on commit 2a81b48

Please sign in to comment.