Skip to content

Commit b0a5804

Browse files
authored
Merge pull request #342 from Countly/refresh_content_zone
Refresh content zone
2 parents fc1a997 + 0cd8ea6 commit b0a5804

File tree

5 files changed

+31
-9
lines changed

5 files changed

+31
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## XX.XX.XX
22
* Extended server configuration capabilities of the SDK.
3+
* Added a Content feature method "refreshContentZone" that does a manual refresh.
34

45
## 25.1.1
56
* Removed Android v1 embedding support

android/src/main/java/ly/count/dart/countly_flutter/CountlyFlutterPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,9 @@ else if ("getRequestQueue".equals(call.method)) {
14101410
} else if ("exitContentZone".equals(call.method)) {
14111411
Countly.sharedInstance().contents().exitContentZone();
14121412
result.success(null);
1413+
} else if ("refreshContentZone".equals(call.method)) {
1414+
Countly.sharedInstance().contents().refreshContentZone();
1415+
result.success(null);
14131416
}
14141417
//------------------End------------------------------------
14151418

ios/Classes/CountlyFlutterPlugin.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,16 +1373,17 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
13731373
[Countly.sharedInstance.content enterContentZone];
13741374
result(nil);
13751375
});
1376-
1377-
// setRequiresConsent
13781376
} else if ([@"exitContentZone" isEqualToString:call.method]) {
13791377
dispatch_async(dispatch_get_main_queue(), ^{
13801378
[Countly.sharedInstance.content exitContentZone];
13811379
result(nil);
13821380
});
1383-
1384-
// setRequiresConsent
1385-
} else {
1381+
} else if ([@"refreshContentZone" isEqualToString:call.method]) {
1382+
dispatch_async(dispatch_get_main_queue(), ^{
1383+
[Countly.sharedInstance.content refreshContentZone];
1384+
result(nil);
1385+
});
1386+
} else {
13861387
result(FlutterMethodNotImplemented);
13871388
}
13881389
}

lib/src/content_builder.dart

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ enum ContentStatus { completed, closed}
44
typedef ContentCallback = void Function(ContentStatus contentStatus, Map<String, dynamic> contentData);
55

66
abstract class ContentBuilder {
7-
/// This is an experimental feature and it can have breaking changes
8-
// Opt in user for the content fetching and updates
7+
/// Enables content fetching and updates for the user.
8+
/// This method opts the user into receiving content updates
9+
/// and ensures that relevant data is fetched accordingly.
910
Future<void> enterContentZone();
1011

11-
/// This is an experimental feature and it can have breaking changes
12-
// Opt out user for the content fetching and updates
12+
/// Disables content fetching and updates for the user.
13+
/// This method opts the user out of receiving content updates
14+
/// and stops any ongoing content retrieval processes.
1315
Future<void> exitContentZone();
16+
17+
/// Triggers a manual refresh of the content zone.
18+
/// This method forces an update by fetching the latest content,
19+
/// ensuring the user receives the most up-to-date information.
20+
Future<void> refreshContentZone();
1421
}

lib/src/content_builder_internal.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ class ContentBuilderInternal implements ContentBuilder {
2828
await _countlyState.channel.invokeMethod('exitContentZone');
2929
}
3030

31+
@override
32+
Future<void> refreshContentZone() async {
33+
if (!_countlyState.isInitialized) {
34+
Countly.log('refreshContentZone, "initWithConfig" must be called before "clear"', logLevel: LogLevel.ERROR);
35+
return;
36+
}
37+
Countly.log('Calling "refreshContentZone"');
38+
await _countlyState.channel.invokeMethod('refreshContentZone');
39+
}
40+
3141
void registerContentCallback(ContentCallback callback) {
3242
_contentCallback = callback;
3343
}

0 commit comments

Comments
 (0)