Skip to content

Commit fdf5a84

Browse files
committed
add in app in memory config switch
1 parent 842b03d commit fdf5a84

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,11 @@ public static void initialize(@NonNull Context context, @NonNull String apiKey,
494494
IterableActivityMonitor.getInstance().addCallback(sharedInstance.activityMonitorListener);
495495

496496
if (sharedInstance.inAppManager == null) {
497-
sharedInstance.inAppManager = new IterableInAppManager(sharedInstance, sharedInstance.config.inAppHandler,
498-
sharedInstance.config.inAppDisplayInterval);
497+
sharedInstance.inAppManager = new IterableInAppManager(
498+
sharedInstance,
499+
sharedInstance.config.inAppHandler,
500+
sharedInstance.config.inAppDisplayInterval,
501+
sharedInstance.config.useInMemoryStorageForInApps);
499502
}
500503

501504
loadLastSavedConfiguration(context);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ public Builder setAllowedProtocols(@NonNull String[] allowedProtocols) {
226226
return this;
227227
}
228228

229+
/**
230+
* Set whether the SDK should store in-apps only in memory, or in file storage
231+
* @param useInMemoryStorageForInApps `true` will have in-apps be only in memory
232+
*/
233+
229234
@NonNull
230235
public Builder setUseInMemoryStorageForInApps(boolean useInMemoryStorageForInApps) {
231236
this.useInMemoryStorageForInApps = useInMemoryStorageForInApps;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public interface Listener {
5050
private long lastInAppShown = 0;
5151
private boolean autoDisplayPaused = false;
5252

53-
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval) {
53+
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval, boolean useInMemoryStorageForInApps) {
5454
this(iterableApi,
5555
handler,
5656
inAppDisplayInterval,
57-
new IterableInAppFileStorage(iterableApi.getMainActivityContext()),
57+
IterableInAppManager.getInAppStorageModel(iterableApi, useInMemoryStorageForInApps),
5858
IterableActivityMonitor.getInstance(),
5959
new IterableInAppDisplayer(IterableActivityMonitor.getInstance()));
6060
}
@@ -435,6 +435,14 @@ private void handleIterableCustomAction(String actionName, IterableInAppMessage
435435
}
436436
}
437437

438+
private static IterableInAppStorage getInAppStorageModel(IterableApi iterableApi, boolean useInMemoryForInAppStorage) {
439+
if (useInMemoryForInAppStorage) {
440+
return new IterableInAppMemoryStorage();
441+
} else {
442+
return new IterableInAppFileStorage(iterableApi.getMainActivityContext());
443+
}
444+
}
445+
438446
@Override
439447
public void onSwitchToForeground() {
440448
if (IterableUtil.currentTimeMillis() - lastSyncTime > MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS) {

0 commit comments

Comments
 (0)