Skip to content

Commit d3a231d

Browse files
authored
Merge pull request #526 from Countly/refactor_refresh
Refactor refresh content zone
2 parents 1e9f103 + 2838cd8 commit d3a231d

6 files changed

Lines changed: 23 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## XX.XX.XX
2+
* Improved Content refresh mechanics.
3+
14
## 26.1.0
25
* Extended server configuration capabilities with server-controlled listing filters:
36
* Event filters (blacklist/whitelist) to control which events are recorded.

sdk/src/androidTest/java/ly/count/android/sdk/ModuleConfigurationTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,6 @@ private int[] setupTest_allFeatures(JSONObject serverConfig) {
12581258
countlyConfig.metricProviderOverride = new MockedMetricProvider();
12591259
Countly.sharedInstance().init(countlyConfig);
12601260
Countly.sharedInstance().moduleContent.CONTENT_START_DELAY_MS = 0; // make it zero to catch content immediate request
1261-
Countly.sharedInstance().moduleContent.REFRESH_CONTENT_ZONE_DELAY_MS = 0; // make it zero to catch content immediate request
12621261
return counts;
12631262
}
12641263

@@ -2346,7 +2345,6 @@ private void testJTEWithMockedWebServer(BiConsumer<RecordedRequest, MockResponse
23462345
countlyConfig.setServerURL(serverUrl);
23472346
Countly.sharedInstance().init(countlyConfig);
23482347
Countly.sharedInstance().moduleContent.CONTENT_START_DELAY_MS = 0;
2349-
Countly.sharedInstance().moduleContent.REFRESH_CONTENT_ZONE_DELAY_MS = 0;
23502348

23512349
Thread.sleep(1000);
23522350

sdk/src/main/java/ly/count/android/sdk/ConnectionQueue.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public ConnectionQueue() {
113113
}
114114
}
115115
}
116+
flushInternalGlobalRequestCallbackActions();
116117
}
117118
});
118119
}
@@ -945,6 +946,12 @@ public void tick() {
945946
L.d("[ConnectionQueue] tick, Starting ConnectionProcessor");
946947
ensureExecutor();
947948
connectionProcessorFuture_ = executor_.submit(createConnectionProcessor());
949+
} else if (rqEmpty) {
950+
// only fire callback when queue is genuinely empty
951+
InternalRequestCallback globalCallback = internalRequestCallbacks.get(GLOBAL_RC_CALLBACK);
952+
if (globalCallback != null) {
953+
globalCallback.onRQFinished();
954+
}
948955
}
949956
}
950957

@@ -1015,7 +1022,7 @@ void addRequestToQueue(final @NonNull String requestData, final boolean writeInS
10151022
*
10161023
* @param runnable The action to execute when the queue finishes
10171024
*/
1018-
void registerInternalGlobalRequestCallbackAction(Runnable runnable) {
1025+
public void registerInternalGlobalRequestCallbackAction(Runnable runnable) {
10191026
internalGlobalRequestCallbackActions.add(runnable);
10201027
}
10211028

@@ -1053,4 +1060,4 @@ Future<?> getConnectionProcessorFuture() {
10531060
void setConnectionProcessorFuture(final Future<?> connectionProcessorFuture) {
10541061
connectionProcessorFuture_ = connectionProcessorFuture;
10551062
}
1056-
}
1063+
}

sdk/src/main/java/ly/count/android/sdk/ModuleContent.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public class ModuleContent extends ModuleBase {
2828
private final ContentCallback globalContentCallback;
2929
private int waitForDelay = 0;
3030
int CONTENT_START_DELAY_MS = 4000; // 4 seconds
31-
int REFRESH_CONTENT_ZONE_DELAY_MS = 2500; // 2.5 seconds
3231

3332
ModuleContent(@NonNull Countly cly, @NonNull CountlyConfig config) {
3433
super(cly, config);
@@ -68,8 +67,8 @@ void onActivityStarted(Activity activity, int updatedActivityCount) {
6867
UtilsDevice.getCutout(activity);
6968
}
7069
if (isCurrentlyInContentZone
71-
&& activity != null
72-
&& !(activity instanceof TransparentActivity)) {
70+
&& activity != null
71+
&& !(activity instanceof TransparentActivity)) {
7372
try {
7473
Intent bringToFront = new Intent(activity, TransparentActivity.class);
7574
bringToFront.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
@@ -404,8 +403,12 @@ void refreshContentZoneInternal(boolean callRQFlush) {
404403
}
405404

406405
if (callRQFlush) {
406+
requestQueueProvider.registerInternalGlobalRequestCallbackAction(new Runnable() {
407+
@Override public void run() {
408+
enterContentZoneInternal(null, 0, null);
409+
}
410+
});
407411
_cly.moduleRequestQueue.attemptToSendStoredRequestsInternal();
408-
enterContentZoneInternal(null, REFRESH_CONTENT_ZONE_DELAY_MS, null);
409412
} else {
410413
enterContentZoneWithRetriesInternal();
411414
}
@@ -455,4 +458,4 @@ public void refreshContentZone() {
455458
refreshContentZoneInternal(true);
456459
}
457460
}
458-
}
461+
}

sdk/src/main/java/ly/count/android/sdk/ModuleRequestQueue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,4 @@ public void addCustomNetworkRequestHeaders(@Nullable Map<String, String> customH
492492
}
493493
}
494494
}
495-
}
495+
}

sdk/src/main/java/ly/count/android/sdk/RequestQueueProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,6 @@ interface RequestQueueProvider {
7575
String prepareHealthCheckRequest(String preparedMetrics);
7676

7777
String prepareFetchContents(int portraitWidth, int portraitHeight, int landscapeWidth, int landscapeHeight, String[] categories, String language, String deviceType);
78+
79+
void registerInternalGlobalRequestCallbackAction(Runnable runnable);
7880
}

0 commit comments

Comments
 (0)