Skip to content

Commit 46ab077

Browse files
authored
Merge pull request #85 from Iterable/feature/MOB-180-add-inAppDisplayInterval
[MOB-180] Add inAppDisplayInterval to IterableConfig
2 parents b68cde1 + ef39f95 commit 46ab077

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public Bundle getPayloadData() {
109109
*/
110110
public IterableInAppManager getInAppManager() {
111111
if (inAppManager == null) {
112-
inAppManager = new IterableInAppManager(this, config.inAppHandler);
112+
inAppManager = new IterableInAppManager(this, config.inAppHandler, config.inAppDisplayInterval);
113113
}
114114
return inAppManager;
115115
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public class IterableConfig {
5353
*/
5454
final IterableInAppHandler inAppHandler;
5555

56+
/**
57+
* The number of seconds to wait before showing the next in-app message, if there are multiple
58+
* messages in the queue
59+
*/
60+
final double inAppDisplayInterval;
61+
5662
private IterableConfig(Builder builder) {
5763
pushIntegrationName = builder.pushIntegrationName;
5864
urlHandler = builder.urlHandler;
@@ -62,6 +68,7 @@ private IterableConfig(Builder builder) {
6268
checkForDeferredDeeplink = builder.checkForDeferredDeeplink;
6369
logLevel = builder.logLevel;
6470
inAppHandler = builder.inAppHandler;
71+
inAppDisplayInterval = builder.inAppDisplayInterval;
6572
}
6673

6774
public static class Builder {
@@ -73,6 +80,7 @@ public static class Builder {
7380
private boolean checkForDeferredDeeplink;
7481
private int logLevel = Log.ERROR;
7582
private IterableInAppHandler inAppHandler = new IterableDefaultInAppHandler();
83+
private double inAppDisplayInterval = 30.0;
7684

7785
public Builder() {}
7886

@@ -155,6 +163,16 @@ public Builder setInAppHandler(IterableInAppHandler inAppHandler) {
155163
return this;
156164
}
157165

166+
/**
167+
* Set the in-app message display interval: the number of seconds to wait before showing
168+
* the next in-app message, if there are multiple messages in the queue
169+
* @param inAppDisplayInterval display interval in seconds
170+
*/
171+
public Builder setInAppDisplayInterval(double inAppDisplayInterval) {
172+
this.inAppDisplayInterval = inAppDisplayInterval;
173+
return this;
174+
}
175+
158176
public IterableConfig build() {
159177
return new IterableConfig(this);
160178
}

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,31 @@
2828
*/
2929
public class IterableInAppManager implements IterableActivityMonitor.AppStateCallback {
3030
static final String TAG = "IterableInAppManager";
31-
static final int IN_APP_DELAY_SECONDS = 30;
3231
static final long MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS = 60 * 1000;
3332

3433
private final IterableApi api;
3534
private final Context context;
3635
private final IterableInAppStorage storage;
3736
private final IterableInAppHandler handler;
37+
private final double inAppDisplayInterval;
3838

3939
private long lastSyncTime = 0;
4040
private long lastInAppShown = 0;
4141

42-
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler) {
42+
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval) {
4343
this(iterableApi,
4444
handler,
45+
inAppDisplayInterval,
4546
new IterableInAppFileStorage(iterableApi.getMainActivityContext()),
4647
IterableActivityMonitor.getInstance());
4748
}
4849

4950
@VisibleForTesting
50-
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, IterableInAppStorage storage, IterableActivityMonitor activityMonitor) {
51+
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval, IterableInAppStorage storage, IterableActivityMonitor activityMonitor) {
5152
this.api = iterableApi;
5253
this.context = iterableApi.getMainActivityContext();
5354
this.handler = handler;
55+
this.inAppDisplayInterval = inAppDisplayInterval;
5456
this.storage = storage;
5557
activityMonitor.addCallback(this);
5658
}
@@ -222,20 +224,20 @@ void scheduleProcessing() {
222224
public void run() {
223225
processMessages();
224226
}
225-
}, (IN_APP_DELAY_SECONDS - getSecondsSinceLastInApp() + 2) * 1000);
227+
}, (long) ((inAppDisplayInterval - getSecondsSinceLastInApp() + 2.0) * 1000));
226228
}
227229
}
228230

229231
private boolean isShowingInApp() {
230232
return IterableInAppHTMLNotification.getInstance() != null;
231233
}
232234

233-
private int getSecondsSinceLastInApp() {
234-
return (int) ((IterableUtil.currentTimeMillis() - lastInAppShown) / 1000);
235+
private double getSecondsSinceLastInApp() {
236+
return (IterableUtil.currentTimeMillis() - lastInAppShown) / 1000.0;
235237
}
236238

237239
private boolean canShowInAppAfterPrevious() {
238-
return getSecondsSinceLastInApp() >= IN_APP_DELAY_SECONDS;
240+
return getSecondsSinceLastInApp() >= inAppDisplayInterval;
239241
}
240242

241243
/**

iterableapi/src/test/java/com/iterable/iterableapi/IterableInAppManagerSyncTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class IterableInAppManagerSyncTest extends BaseTest {
3535
@Before
3636
public void setUp() throws Exception {
3737
MockitoAnnotations.initMocks(this);
38-
inAppManager = spy(new IterableInAppManager(iterableApiMock, handlerMock, storageMock, activityMonitorMock));
38+
inAppManager = spy(new IterableInAppManager(iterableApiMock, handlerMock, 30.0, storageMock, activityMonitorMock));
3939
doAnswer(new Answer() {
4040
@Override
4141
public Object answer(InvocationOnMock invocation) throws Throwable {

0 commit comments

Comments
 (0)