Skip to content

Commit bbabeab

Browse files
committed
Using singleton OSInAppMessageController.java instead of new
* Created singleton based `getInAppMessageRepository` method inside of `OSInAppMessageController.java` class * This allows the synchronized to apply to multiple methods being called from the class instance * Deleted unused thread name since new Thread was moved toi cache cleaning file with different thread name now
1 parent 8c9d3dc commit bbabeab

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageController.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class OSInAppMessageController implements OSDynamicTriggerControllerObserver, OS
3232

3333
public static final String IN_APP_MESSAGES_JSON_KEY = "in_app_messages";
3434
private static final String OS_SAVE_IN_APP_MESSAGE = "OS_SAVE_IN_APP_MESSAGE";
35-
private static final String OS_DELETE_IN_APP_MESSAGE = "OS_DELETE_IN_APP_MESSAGE";
3635

3736
OSTriggerController triggerController;
3837
private OSSystemConditionController systemConditionController;
@@ -122,8 +121,15 @@ protected OSInAppMessageController(OneSignalDbHelper dbHelper) {
122121
initRedisplayData(dbHelper);
123122
}
124123

124+
OSInAppMessageRepository getInAppMessageRepository(OneSignalDbHelper dbHelper) {
125+
if (inAppMessageRepository == null)
126+
inAppMessageRepository = new OSInAppMessageRepository(dbHelper);
127+
128+
return inAppMessageRepository;
129+
}
130+
125131
protected void initRedisplayData(OneSignalDbHelper dbHelper) {
126-
inAppMessageRepository = new OSInAppMessageRepository(dbHelper);
132+
inAppMessageRepository = getInAppMessageRepository(dbHelper);
127133
redisplayedInAppMessages = inAppMessageRepository.getCachedInAppMessages();
128134

129135
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "redisplayedInAppMessages: " + redisplayedInAppMessages.toString());

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalCacheCleaner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ synchronized static void cleanCachedInAppMessages(final OneSignalDbHelper dbHelp
7171
@Override
7272
public void run() {
7373
Thread.currentThread().setPriority(Process.THREAD_PRIORITY_BACKGROUND);
74-
new OSInAppMessageRepository(dbHelper).cleanCachedInAppMessages();
74+
75+
OSInAppMessageRepository inAppMessageRepository = OSInAppMessageController
76+
.getController()
77+
.getInAppMessageRepository(dbHelper);
78+
inAppMessageRepository.cleanCachedInAppMessages();
7579
}
7680
}, OS_DELETE_CACHED_REDISPLAYED_IAMS_THREAD).start();
7781
}

0 commit comments

Comments
 (0)