From 70d90f6a79349cb569b24cf31f8b8689d338d8fc Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Thu, 10 Oct 2024 12:36:40 +0300 Subject: [PATCH 1/5] feat: tweak functions for feedback widgets --- .../ly/count/android/sdk/ModuleFeedback.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java index c32a145c7..ae057e4e3 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java @@ -596,6 +596,58 @@ void reportFeedbackWidgetManuallyInternal(@Nullable CountlyFeedbackWidget widget eventProvider.recordEventInternal(usedEventKey, segm, 1, 0, 0, null, null); } + /** + * Present a feedback widget based on the provided selector, internal function to use + * + * @param type the type of the feedback widget to present + * @param selector the widget id, widget name or widget tag of the feedback widget to present + */ + private void presentFeedbackWidgetSelector(@NonNull Context context, @NonNull FeedbackWidgetType type, @NonNull String selector) { + getAvailableFeedbackWidgetsInternal(new RetrieveFeedbackWidgets() { + @Override public void onFinished(List retrievedWidgets, String error) { + if (error != null) { + L.e("[ModuleFeedback] presentFeedbackWidgetSelector, Failed to retrieve feedback widget list, [" + error + "]"); + return; + } + + if (retrievedWidgets.isEmpty()) { + L.e("[ModuleFeedback] presentFeedbackWidgetSelector, No feedback widgets available"); + return; + } + + CountlyFeedbackWidget selectedWidget = null; + + for (CountlyFeedbackWidget widget : retrievedWidgets) { + if (widget.type == type) { + if (!selector.isEmpty()) { + if (widget.widgetId.equals(selector) || widget.name.equals(selector)) { + selectedWidget = widget; + break; + } + + for (String tag : widget.tags) { + if (tag.equals(selector)) { + selectedWidget = widget; + break; + } + } + } else { + selectedWidget = widget; + break; + } + } + } + + if (selectedWidget == null) { + L.e("[ModuleFeedback] presentFeedbackWidgetSelector, No feedback widget found with the provided selector"); + return; + } + + presentFeedbackWidgetInternal(selectedWidget, context, null, null); + } + }); + } + @Override void initFinished(@NonNull CountlyConfig config) { @@ -666,5 +718,71 @@ public void reportFeedbackWidgetManually(@Nullable CountlyFeedbackWidget widgetI reportFeedbackWidgetManuallyInternal(widgetInfo, widgetData, widgetResult); } } + + /** + * Present an NPS feedback widget from the top of the list of available NPS widgets by the selector string + * + * @param context the context to use for displaying the feedback widget + * @param selector the widget id, widget name or widget tag of the NPS feedback widget to present, if empty, the top widget will be presented + */ + public void presentNPS(@NonNull Context context, @NonNull String selector) { + synchronized (_cly) { + L.i("[Feedback] presentNPS, got selector:[" + selector + "]"); + presentFeedbackWidgetSelector(context, FeedbackWidgetType.nps, selector); + } + } + + /** + * Present an NPS feedback widget from the top of the list of available NPS widgets + * + * @param context the context to use for displaying the feedback widget + */ + public void presentNPS(@NonNull Context context) { + presentNPS(context, ""); + } + + /** + * Present a Survey feedback widget from the top of the list of available Survey widgets by the selector string + * + * @param context the context to use for displaying the feedback widget + * @param selector the widget id, widget name or widget tag of the Survey feedback widget to present, if empty, the top widget will be presented + */ + public void presentSurvey(@NonNull Context context, @NonNull String selector) { + synchronized (_cly) { + L.i("[Feedback] presentSurvey, got selector:[" + selector + "]"); + presentFeedbackWidgetSelector(context, FeedbackWidgetType.survey, selector); + } + } + + /** + * Present a Survey feedback widget from the top of the list of available Survey widgets + * + * @param context the context to use for displaying the feedback widget + */ + public void presentSurvey(@NonNull Context context) { + presentSurvey(context, ""); + } + + /** + * Present a Rating feedback widget from the top of the list of available Rating widgets by the selector string + * + * @param context the context to use for displaying the feedback widget + * @param selector the widget id, widget name or widget tag of the Rating feedback widget to present, if empty, the top widget will be presented + */ + public void presentRating(@NonNull Context context, @NonNull String selector) { + synchronized (_cly) { + L.i("[Feedback] presentRating, got selector:[" + selector + "]"); + presentFeedbackWidgetSelector(context, FeedbackWidgetType.rating, selector); + } + } + + /** + * Present a Rating feedback widget from the top of the list of available Rating widgets + * + * @param context the context to use for displaying the feedback widget + */ + public void presentRating(@NonNull Context context) { + presentRating(context, ""); + } } } From a617af908c15ddc6791a7d79f586de0f4ad40d30 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Thu, 10 Oct 2024 13:54:36 +0300 Subject: [PATCH 2/5] refactor: rename selector to nameIDorTag --- .../ly/count/android/sdk/ModuleFeedback.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java index ae057e4e3..9e417464c 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java @@ -597,21 +597,21 @@ void reportFeedbackWidgetManuallyInternal(@Nullable CountlyFeedbackWidget widget } /** - * Present a feedback widget based on the provided selector, internal function to use + * Present a feedback widget based on the provided nameIDorTag, internal function to use * * @param type the type of the feedback widget to present - * @param selector the widget id, widget name or widget tag of the feedback widget to present + * @param nameIDorTag the widget id, widget name or widget tag of the feedback widget to present */ - private void presentFeedbackWidgetSelector(@NonNull Context context, @NonNull FeedbackWidgetType type, @NonNull String selector) { + private void presentFeedbackWidgetnameIDorTag(@NonNull Context context, @NonNull FeedbackWidgetType type, @NonNull String nameIDorTag) { getAvailableFeedbackWidgetsInternal(new RetrieveFeedbackWidgets() { @Override public void onFinished(List retrievedWidgets, String error) { if (error != null) { - L.e("[ModuleFeedback] presentFeedbackWidgetSelector, Failed to retrieve feedback widget list, [" + error + "]"); + L.e("[ModuleFeedback] presentFeedbackWidgetnameIDorTag, Failed to retrieve feedback widget list, [" + error + "]"); return; } if (retrievedWidgets.isEmpty()) { - L.e("[ModuleFeedback] presentFeedbackWidgetSelector, No feedback widgets available"); + L.e("[ModuleFeedback] presentFeedbackWidgetnameIDorTag, No feedback widgets available"); return; } @@ -619,14 +619,14 @@ private void presentFeedbackWidgetSelector(@NonNull Context context, @NonNull Fe for (CountlyFeedbackWidget widget : retrievedWidgets) { if (widget.type == type) { - if (!selector.isEmpty()) { - if (widget.widgetId.equals(selector) || widget.name.equals(selector)) { + if (!nameIDorTag.isEmpty()) { + if (widget.widgetId.equals(nameIDorTag) || widget.name.equals(nameIDorTag)) { selectedWidget = widget; break; } for (String tag : widget.tags) { - if (tag.equals(selector)) { + if (tag.equals(nameIDorTag)) { selectedWidget = widget; break; } @@ -639,7 +639,7 @@ private void presentFeedbackWidgetSelector(@NonNull Context context, @NonNull Fe } if (selectedWidget == null) { - L.e("[ModuleFeedback] presentFeedbackWidgetSelector, No feedback widget found with the provided selector"); + L.e("[ModuleFeedback] presentFeedbackWidgetnameIDorTag, No feedback widget found with the provided nameIDorTag"); return; } @@ -720,15 +720,15 @@ public void reportFeedbackWidgetManually(@Nullable CountlyFeedbackWidget widgetI } /** - * Present an NPS feedback widget from the top of the list of available NPS widgets by the selector string + * Present an NPS feedback widget from the top of the list of available NPS widgets by the nameIDorTag string * * @param context the context to use for displaying the feedback widget - * @param selector the widget id, widget name or widget tag of the NPS feedback widget to present, if empty, the top widget will be presented + * @param nameIDorTag the widget id, widget name or widget tag of the NPS feedback widget to present, if empty, the top widget will be presented */ - public void presentNPS(@NonNull Context context, @NonNull String selector) { + public void presentNPS(@NonNull Context context, @NonNull String nameIDorTag) { synchronized (_cly) { - L.i("[Feedback] presentNPS, got selector:[" + selector + "]"); - presentFeedbackWidgetSelector(context, FeedbackWidgetType.nps, selector); + L.i("[Feedback] presentNPS, got nameIDorTag:[" + nameIDorTag + "]"); + presentFeedbackWidgetnameIDorTag(context, FeedbackWidgetType.nps, nameIDorTag); } } @@ -742,15 +742,15 @@ public void presentNPS(@NonNull Context context) { } /** - * Present a Survey feedback widget from the top of the list of available Survey widgets by the selector string + * Present a Survey feedback widget from the top of the list of available Survey widgets by the nameIDorTag string * * @param context the context to use for displaying the feedback widget - * @param selector the widget id, widget name or widget tag of the Survey feedback widget to present, if empty, the top widget will be presented + * @param nameIDorTag the widget id, widget name or widget tag of the Survey feedback widget to present, if empty, the top widget will be presented */ - public void presentSurvey(@NonNull Context context, @NonNull String selector) { + public void presentSurvey(@NonNull Context context, @NonNull String nameIDorTag) { synchronized (_cly) { - L.i("[Feedback] presentSurvey, got selector:[" + selector + "]"); - presentFeedbackWidgetSelector(context, FeedbackWidgetType.survey, selector); + L.i("[Feedback] presentSurvey, got nameIDorTag:[" + nameIDorTag + "]"); + presentFeedbackWidgetnameIDorTag(context, FeedbackWidgetType.survey, nameIDorTag); } } @@ -764,15 +764,15 @@ public void presentSurvey(@NonNull Context context) { } /** - * Present a Rating feedback widget from the top of the list of available Rating widgets by the selector string + * Present a Rating feedback widget from the top of the list of available Rating widgets by the nameIDorTag string * * @param context the context to use for displaying the feedback widget - * @param selector the widget id, widget name or widget tag of the Rating feedback widget to present, if empty, the top widget will be presented + * @param nameIDorTag the widget id, widget name or widget tag of the Rating feedback widget to present, if empty, the top widget will be presented */ - public void presentRating(@NonNull Context context, @NonNull String selector) { + public void presentRating(@NonNull Context context, @NonNull String nameIDorTag) { synchronized (_cly) { - L.i("[Feedback] presentRating, got selector:[" + selector + "]"); - presentFeedbackWidgetSelector(context, FeedbackWidgetType.rating, selector); + L.i("[Feedback] presentRating, got nameIDorTag:[" + nameIDorTag + "]"); + presentFeedbackWidgetnameIDorTag(context, FeedbackWidgetType.rating, nameIDorTag); } } From 885574a12d3e298e68e69a0bffef8911a2ca5363 Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray <57103426+arifBurakDemiray@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:25:18 +0300 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c84da36df..c1bbd3b08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## XX.XX.XX +* Added tweak functions to enhance the feedback module for more precise adjustments: + * presentNPS + * presentSurvey + * presentRating + ## 24.7.4 * Disabled caching for webviews. * Expanded the flag (enablePreviousNameRecording) to add current view name as segmentation to custom events. (Experimental!) From 1dbbb8abcfd385dfe745401394014096a09f6a9c Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Fri, 11 Oct 2024 13:38:31 +0300 Subject: [PATCH 4/5] refactor: fixes after review --- CHANGELOG.md | 14 ++++++++++---- .../java/ly/count/android/sdk/ModuleFeedback.java | 14 +++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c1bbd3b08..bc543658b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ ## XX.XX.XX -* Added tweak functions to enhance the feedback module for more precise adjustments: - * presentNPS - * presentSurvey - * presentRating +* Implemented new tweak functions to improve the feedback module, allowing for more precise control. These functions + accept a second parameter that filters widgets based on their ID, name, or tag. If the second parameter is provided + as an empty string, no filtering is applied. The first widget that matches the filter criteria will be displayed + from the widget list. + * presentNPS(Context) + * presentNPS(Context, String) + * presentSurvey(Context) + * presentSurvey(Context, String) + * presentRating(Context) + * presentRating(Context, String) ## 24.7.4 * Disabled caching for webviews. diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java index 9e417464c..da06bfdcb 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java @@ -602,16 +602,16 @@ void reportFeedbackWidgetManuallyInternal(@Nullable CountlyFeedbackWidget widget * @param type the type of the feedback widget to present * @param nameIDorTag the widget id, widget name or widget tag of the feedback widget to present */ - private void presentFeedbackWidgetnameIDorTag(@NonNull Context context, @NonNull FeedbackWidgetType type, @NonNull String nameIDorTag) { + private void presentFeedbackWidgetNameIDorTag(@NonNull Context context, @NonNull FeedbackWidgetType type, @NonNull String nameIDorTag) { getAvailableFeedbackWidgetsInternal(new RetrieveFeedbackWidgets() { @Override public void onFinished(List retrievedWidgets, String error) { if (error != null) { - L.e("[ModuleFeedback] presentFeedbackWidgetnameIDorTag, Failed to retrieve feedback widget list, [" + error + "]"); + L.e("[ModuleFeedback] presentFeedbackWidgetNameIDorTag, Failed to retrieve feedback widget list, [" + error + "]"); return; } if (retrievedWidgets.isEmpty()) { - L.e("[ModuleFeedback] presentFeedbackWidgetnameIDorTag, No feedback widgets available"); + L.e("[ModuleFeedback] presentFeedbackWidgetNameIDorTag, No feedback widgets available"); return; } @@ -639,7 +639,7 @@ private void presentFeedbackWidgetnameIDorTag(@NonNull Context context, @NonNull } if (selectedWidget == null) { - L.e("[ModuleFeedback] presentFeedbackWidgetnameIDorTag, No feedback widget found with the provided nameIDorTag"); + L.e("[ModuleFeedback] presentFeedbackWidgetNameIDorTag, No feedback widget found with the provided nameIDorTag or type"); return; } @@ -728,7 +728,7 @@ public void reportFeedbackWidgetManually(@Nullable CountlyFeedbackWidget widgetI public void presentNPS(@NonNull Context context, @NonNull String nameIDorTag) { synchronized (_cly) { L.i("[Feedback] presentNPS, got nameIDorTag:[" + nameIDorTag + "]"); - presentFeedbackWidgetnameIDorTag(context, FeedbackWidgetType.nps, nameIDorTag); + presentFeedbackWidgetNameIDorTag(context, FeedbackWidgetType.nps, nameIDorTag); } } @@ -750,7 +750,7 @@ public void presentNPS(@NonNull Context context) { public void presentSurvey(@NonNull Context context, @NonNull String nameIDorTag) { synchronized (_cly) { L.i("[Feedback] presentSurvey, got nameIDorTag:[" + nameIDorTag + "]"); - presentFeedbackWidgetnameIDorTag(context, FeedbackWidgetType.survey, nameIDorTag); + presentFeedbackWidgetNameIDorTag(context, FeedbackWidgetType.survey, nameIDorTag); } } @@ -772,7 +772,7 @@ public void presentSurvey(@NonNull Context context) { public void presentRating(@NonNull Context context, @NonNull String nameIDorTag) { synchronized (_cly) { L.i("[Feedback] presentRating, got nameIDorTag:[" + nameIDorTag + "]"); - presentFeedbackWidgetnameIDorTag(context, FeedbackWidgetType.rating, nameIDorTag); + presentFeedbackWidgetNameIDorTag(context, FeedbackWidgetType.rating, nameIDorTag); } } From 55838f4e93940eadc31a4765bfbe1d06ba3c9b7d Mon Sep 17 00:00:00 2001 From: Arif Burak Demiray Date: Fri, 11 Oct 2024 14:24:18 +0300 Subject: [PATCH 5/5] refactor: fixes after review --- CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc543658b..2ffdcf156 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,5 @@ ## XX.XX.XX -* Implemented new tweak functions to improve the feedback module, allowing for more precise control. These functions - accept a second parameter that filters widgets based on their ID, name, or tag. If the second parameter is provided - as an empty string, no filtering is applied. The first widget that matches the filter criteria will be displayed - from the widget list. +* Added new functions to ease the presenting the feedback widgets. Functions present the first matching feedback widget from the list. * presentNPS(Context) * presentNPS(Context, String) * presentSurvey(Context)