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
Expand Up @@ -494,8 +494,11 @@ public static void initialize(@NonNull Context context, @NonNull String apiKey,
IterableActivityMonitor.getInstance().addCallback(sharedInstance.activityMonitorListener);

if (sharedInstance.inAppManager == null) {
sharedInstance.inAppManager = new IterableInAppManager(sharedInstance, sharedInstance.config.inAppHandler,
sharedInstance.config.inAppDisplayInterval);
sharedInstance.inAppManager = new IterableInAppManager(
sharedInstance,
sharedInstance.config.inAppHandler,
sharedInstance.config.inAppDisplayInterval,
sharedInstance.config.useInMemoryStorageForInApps);
}

loadLastSavedConfiguration(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ public class IterableConfig {
*/
final String[] allowedProtocols;

/**
* This controls whether the in-app content should be saved to disk, or only kept in memory.
* By default, the SDK will save in-apps to disk.
*/
final boolean useInMemoryStorageForInApps;

private IterableConfig(Builder builder) {
pushIntegrationName = builder.pushIntegrationName;
urlHandler = builder.urlHandler;
Expand All @@ -83,6 +89,7 @@ private IterableConfig(Builder builder) {
authHandler = builder.authHandler;
expiringAuthTokenRefreshPeriod = builder.expiringAuthTokenRefreshPeriod;
allowedProtocols = builder.allowedProtocols;
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
}

public static class Builder {
Expand All @@ -97,6 +104,8 @@ public static class Builder {
private IterableAuthHandler authHandler;
private long expiringAuthTokenRefreshPeriod = 60000L;
private String[] allowedProtocols = new String[0];
private boolean useInMemoryStorageForInApps = false;

public Builder() {}

/**
Expand Down Expand Up @@ -217,6 +226,17 @@ public Builder setAllowedProtocols(@NonNull String[] allowedProtocols) {
return this;
}

/**
* Set whether the SDK should store in-apps only in memory, or in file storage
* @param useInMemoryStorageForInApps `true` will have in-apps be only in memory
*/

@NonNull
public Builder setUseInMemoryStorageForInApps(boolean useInMemoryStorageForInApps) {
this.useInMemoryStorageForInApps = useInMemoryStorageForInApps;
return this;
}

@NonNull
public IterableConfig build() {
return new IterableConfig(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
Expand Down Expand Up @@ -50,11 +51,11 @@ public interface Listener {
private long lastInAppShown = 0;
private boolean autoDisplayPaused = false;

IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval) {
IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval, boolean useInMemoryStorageForInApps) {
this(iterableApi,
handler,
inAppDisplayInterval,
new IterableInAppFileStorage(iterableApi.getMainActivityContext()),
IterableInAppManager.getInAppStorageModel(iterableApi, useInMemoryStorageForInApps),
IterableActivityMonitor.getInstance(),
new IterableInAppDisplayer(IterableActivityMonitor.getInstance()));
}
Expand Down Expand Up @@ -435,6 +436,26 @@ private void handleIterableCustomAction(String actionName, IterableInAppMessage
}
}

private static IterableInAppStorage getInAppStorageModel(IterableApi iterableApi, boolean useInMemoryForInAppStorage) {
if (useInMemoryForInAppStorage) {
checkAndDeleteUnusedInAppFileStorage(iterableApi.getMainActivityContext());

return new IterableInAppMemoryStorage();
} else {
return new IterableInAppFileStorage(iterableApi.getMainActivityContext());
}
}

private static void checkAndDeleteUnusedInAppFileStorage(Context context) {
File sdkFilesDirectory = IterableUtil.getSDKFilesDirectory(context);
File inAppContentFolder = IterableUtil.getDirectory(sdkFilesDirectory, "IterableInAppFileStorage");
File inAppBlob = new File(inAppContentFolder, "itbl_inapp.json");

if (inAppBlob.exists()) {
inAppBlob.delete();
}
}

@Override
public void onSwitchToForeground() {
if (IterableUtil.currentTimeMillis() - lastSyncTime > MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS) {
Expand Down