|
17 | 17 | import org.json.JSONException;
|
18 | 18 | import org.json.JSONObject;
|
19 | 19 |
|
| 20 | +import java.io.File; |
20 | 21 | import java.util.ArrayList;
|
21 | 22 | import java.util.Collections;
|
22 | 23 | import java.util.Comparator;
|
@@ -50,11 +51,11 @@ public interface Listener {
|
50 | 51 | private long lastInAppShown = 0;
|
51 | 52 | private boolean autoDisplayPaused = false;
|
52 | 53 |
|
53 |
| - IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval) { |
| 54 | + IterableInAppManager(IterableApi iterableApi, IterableInAppHandler handler, double inAppDisplayInterval, boolean useInMemoryStorageForInApps) { |
54 | 55 | this(iterableApi,
|
55 | 56 | handler,
|
56 | 57 | inAppDisplayInterval,
|
57 |
| - new IterableInAppFileStorage(iterableApi.getMainActivityContext()), |
| 58 | + IterableInAppManager.getInAppStorageModel(iterableApi, useInMemoryStorageForInApps), |
58 | 59 | IterableActivityMonitor.getInstance(),
|
59 | 60 | new IterableInAppDisplayer(IterableActivityMonitor.getInstance()));
|
60 | 61 | }
|
@@ -435,6 +436,26 @@ private void handleIterableCustomAction(String actionName, IterableInAppMessage
|
435 | 436 | }
|
436 | 437 | }
|
437 | 438 |
|
| 439 | + private static IterableInAppStorage getInAppStorageModel(IterableApi iterableApi, boolean useInMemoryForInAppStorage) { |
| 440 | + if (useInMemoryForInAppStorage) { |
| 441 | + checkAndDeleteUnusedInAppFileStorage(iterableApi.getMainActivityContext()); |
| 442 | + |
| 443 | + return new IterableInAppMemoryStorage(); |
| 444 | + } else { |
| 445 | + return new IterableInAppFileStorage(iterableApi.getMainActivityContext()); |
| 446 | + } |
| 447 | + } |
| 448 | + |
| 449 | + private static void checkAndDeleteUnusedInAppFileStorage(Context context) { |
| 450 | + File sdkFilesDirectory = IterableUtil.getSDKFilesDirectory(context); |
| 451 | + File inAppContentFolder = IterableUtil.getDirectory(sdkFilesDirectory, "IterableInAppFileStorage"); |
| 452 | + File inAppBlob = new File(inAppContentFolder, "itbl_inapp.json"); |
| 453 | + |
| 454 | + if (inAppBlob.exists()) { |
| 455 | + inAppBlob.delete(); |
| 456 | + } |
| 457 | + } |
| 458 | + |
438 | 459 | @Override
|
439 | 460 | public void onSwitchToForeground() {
|
440 | 461 | if (IterableUtil.currentTimeMillis() - lastSyncTime > MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS) {
|
|
0 commit comments