Skip to content

Commit e4654e9

Browse files
authored
Merge pull request #385 from Countly/preview_content
feat: preview content
2 parents f2eceab + 6f18c53 commit e4654e9

6 files changed

Lines changed: 31 additions & 0 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"dart.lineLength": 300,
3+
"editor.formatOnSave": true,
34
"java.configuration.updateBuildConfiguration": "interactive",
45
"emeraldwalk.runonsave": {
56
"commands": [

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## XX.XX.XX
2+
* Added Content feature method `previewContent(String contentId)` (Experimental!).
23
* Added a new config option disableViewRestartForManualRecording to disable auto close/restart behavior of manual views on app background/foreground actions.
34
* Added a new config option "setWebviewDisplayOption: WebViewDisplayOption" to control how Content and Feedback Widgets are presented.
45
* IMMERSIVE mode (default): Full-screen display (except cutouts).

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,10 @@ else if ("enterContentZone".equals(call.method)) {
14611461
} else if ("refreshContentZone".equals(call.method)) {
14621462
Countly.sharedInstance().contents().refreshContentZone();
14631463
result.success(null);
1464+
} else if ("previewContent".equals(call.method)) {
1465+
String contentId = call.argument("contentId");
1466+
Countly.sharedInstance().contents().previewContent(contentId);
1467+
result.success(null);
14641468
}
14651469

14661470
else {

ios/Classes/CountlyFlutterPlugin.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,12 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
14211421
[Countly.sharedInstance.content refreshContentZone];
14221422
result(nil);
14231423
});
1424+
} else if ([@"previewContent" isEqualToString:call.method]) {
1425+
NSString* contentId = call.arguments[@"contentId"];
1426+
dispatch_async(dispatch_get_main_queue(), ^{
1427+
[Countly.sharedInstance.content previewContent:contentId];
1428+
result(nil);
1429+
});
14241430
} else if ([@"attemptToSendStoredRequests" isEqualToString:call.method]) {
14251431
dispatch_async(dispatch_get_main_queue(), ^{
14261432
[Countly.sharedInstance attemptToSendStoredRequests];

lib/src/content_builder.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,9 @@ abstract class ContentBuilder {
2121
/// This method forces an update by fetching the latest content,
2222
/// ensuring the user receives the most up-to-date information.
2323
Future<void> refreshContentZone();
24+
25+
/// This is an experimental feature and it can have breaking changes
26+
/// Previews the content associated with the given [contentId].
27+
/// This method fetches and displays the content for preview purposes.
28+
Future<void> previewContent(String contentId);
2429
}

lib/src/content_builder_internal.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ class ContentBuilderInternal implements ContentBuilder {
3838
await _countlyState.channel.invokeMethod('refreshContentZone');
3939
}
4040

41+
@override
42+
Future<void> previewContent(String contentId) async {
43+
if (!_countlyState.isInitialized) {
44+
Countly.log('previewContent, "initWithConfig" must be called before "previewContent"', logLevel: LogLevel.ERROR);
45+
return;
46+
}
47+
if (contentId.isEmpty) {
48+
Countly.log('previewContent, contentId cannot be null or empty', logLevel: LogLevel.ERROR);
49+
return;
50+
}
51+
Countly.log('Calling "previewContent" with contentId: [$contentId]');
52+
await _countlyState.channel.invokeMethod('previewContent', {'contentId': contentId});
53+
}
54+
4155
void registerContentCallback(ContentCallback callback) {
4256
_contentCallback = callback;
4357
}

0 commit comments

Comments
 (0)