diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/CoreFeature.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/CoreFeature.java index c384254e1..55e365b2c 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/CoreFeature.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/CoreFeature.java @@ -25,7 +25,8 @@ public enum CoreFeature { TestDummy(1 << 19),//used during testing DeviceId(1 << 20, ModuleDeviceIdCore::new), Requests(1 << 21, ModuleRequests::new), - Logs(1 << 22); + Logs(1 << 22), + Feedback(1 << 23, ModuleFeedback::new); private final int index; @@ -62,6 +63,7 @@ public int getIndex() { put(DeviceId.index, DeviceId); put(Requests.index, Requests); put(Logs.index, Logs); + put(Feedback.index, Feedback); }}; static CoreFeature byIndex(int index) { diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java new file mode 100644 index 000000000..e32685063 --- /dev/null +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/ModuleFeedback.java @@ -0,0 +1,145 @@ +package ly.count.sdk.java.internal; + +import java.util.List; +import java.util.Map; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.json.JSONObject; + +public class ModuleFeedback extends ModuleBase { + + public enum FeedbackWidgetType {SURVEY, NPS, RATING} + + public static class CountlyFeedbackWidget { + public String widgetId; + public FeedbackWidgetType type; + public String name; + public String[] tags; + } + + final static String NPS_EVENT_KEY = "[CLY]_nps"; + final static String SURVEY_EVENT_KEY = "[CLY]_survey"; + final static String RATING_EVENT_KEY = "[CLY]_star_rating"; + + String cachedAppVersion; + Feedback feedbackInterface = null; + private CtxCore ctx; + + public interface RetrieveFeedbackWidgets { + void onFinished(List retrievedWidgets, String error); + } + + public interface RetrieveFeedbackWidgetData { + void onFinished(JSONObject retrievedWidgetData, String error); + } + + public interface FeedbackCallback { + void onFinished(String url, String error); + } + + ModuleFeedback() { + } + + @Override + public void init(InternalConfig config, Log logger) { + L.v("[ModuleFeedback] Initializing"); + super.init(config, logger); + + cachedAppVersion = Device.dev.getAppVersion(); + feedbackInterface = new Feedback(); + } + + @Override + public void onContextAcquired(@Nonnull CtxCore ctx) { + this.ctx = ctx; + L.d("[ModuleFeedback] onContextAcquired: " + ctx); + } + + @Override + public Boolean onRequest(Request request) { + return true; + } + + @Override + public void stop(CtxCore ctx, boolean clear) { + super.stop(ctx, clear); + feedbackInterface = null; + } + + private List getAvailableFeedbackWidgetsInternal() { + return null; + } + + private void reportFeedbackWidgetManuallyInternal(CountlyFeedbackWidget widgetInfo, JSONObject widgetData, Map widgetResult) { + + } + + private JSONObject getFeedbackWidgetDataInternal(CountlyFeedbackWidget widgetInfo) { + return null; + } + + private String constructFeedbackWidgetUrlInternal(CountlyFeedbackWidget widgetInfo) { + return null; + } + + public class Feedback { + + /** + * Get a list of available feedback widgets for this device ID + * + * @return list of available feedback widgets + */ + public List getAvailableFeedbackWidgets() { + synchronized (internalConfig) { + L.i("[Feedback] Trying to retrieve feedback widget list"); + + return getAvailableFeedbackWidgetsInternal(); + } + } + + /** + * Construct a URL that can be used to present a feedback widget in a web viewer + * + * @param widgetInfo + * @return feedback widget URL + */ + public String constructFeedbackWidgetUrl(@Nullable CountlyFeedbackWidget widgetInfo) { + synchronized (internalConfig) { + L.i("[Feedback] Trying to present feedback widget in an alert dialog"); + + return constructFeedbackWidgetUrlInternal(widgetInfo); + } + } + + /** + * Download data for a specific widget so that it can be displayed with a custom UI + * When requesting this data, it will count as a shown widget (will increment that "shown" count in the dashboard) + * + * @param widgetInfo + * @return feedback widget data + */ + public JSONObject getFeedbackWidgetData(@Nullable CountlyFeedbackWidget widgetInfo) { + synchronized (internalConfig) { + L.i("[Feedback] Trying to retrieve feedback widget data"); + + return getFeedbackWidgetDataInternal(widgetInfo); + } + } + + /** + * Manually report a feedback widget in case the client used a custom interface + * In case widgetResult is passed as "null," it would be assumed that the widget was canceled + * + * @param widgetInfo + * @param widgetData + * @param widgetResult + */ + public void reportFeedbackWidgetManually(@Nullable CountlyFeedbackWidget widgetInfo, @Nullable JSONObject widgetData, @Nullable Map widgetResult) { + synchronized (internalConfig) { + L.i("[Feedback] Trying to report feedback widget manually"); + + reportFeedbackWidgetManuallyInternal(widgetInfo, widgetData, widgetResult); + } + } + } +}