diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleContent.java b/sdk/src/main/java/ly/count/android/sdk/ModuleContent.java index ade4eb2eb..6fab5428b 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleContent.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleContent.java @@ -85,36 +85,28 @@ void fetchContentsInternal(@NonNull String[] categories) { if (validateResponse(checkResponse)) { L.d("[ModuleContent] fetchContentsInternal, got new content data, showing it"); - iRGenerator.CreatePreflightRequestMaker().doWork(checkResponse.optString("html"), null, cp, false, true, preflightResponse -> { - if (preflightResponse == null) { - L.d("[ModuleContent] fetchContentsInternal, preflight check failed, skipping showing content"); - return; - } - - Map placementCoordinates = parseContent(checkResponse, displayMetrics); - if (placementCoordinates.isEmpty()) { - L.d("[ModuleContent] fetchContentsInternal, placement coordinates are empty, skipping"); - return; - } - - L.d("[ModuleContent] fetchContentsInternal, preflight check succeeded"); - Intent intent = new Intent(_cly.context_, TransparentActivity.class); - intent.putExtra(TransparentActivity.CONFIGURATION_LANDSCAPE, placementCoordinates.get(Configuration.ORIENTATION_LANDSCAPE)); - intent.putExtra(TransparentActivity.CONFIGURATION_PORTRAIT, placementCoordinates.get(Configuration.ORIENTATION_PORTRAIT)); - intent.putExtra(TransparentActivity.ORIENTATION, _cly.context_.getResources().getConfiguration().orientation); - - Long id = System.currentTimeMillis(); - intent.putExtra(TransparentActivity.ID_CALLBACK, id); - if (globalContentCallback != null) { - TransparentActivity.contentCallbacks.put(id, globalContentCallback); - } - - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - _cly.context_.startActivity(intent); - - shouldFetchContents = false; // disable fetching contents until the next time, this will disable the timer fetching - isCurrentlyInContentZone = true; - }, L); + Map placementCoordinates = parseContent(checkResponse, displayMetrics); + if (placementCoordinates.isEmpty()) { + L.d("[ModuleContent] fetchContentsInternal, placement coordinates are empty, skipping"); + return; + } + + Intent intent = new Intent(_cly.context_, TransparentActivity.class); + intent.putExtra(TransparentActivity.CONFIGURATION_LANDSCAPE, placementCoordinates.get(Configuration.ORIENTATION_LANDSCAPE)); + intent.putExtra(TransparentActivity.CONFIGURATION_PORTRAIT, placementCoordinates.get(Configuration.ORIENTATION_PORTRAIT)); + intent.putExtra(TransparentActivity.ORIENTATION, _cly.context_.getResources().getConfiguration().orientation); + + Long id = System.currentTimeMillis(); + intent.putExtra(TransparentActivity.ID_CALLBACK, id); + if (globalContentCallback != null) { + TransparentActivity.contentCallbacks.put(id, globalContentCallback); + } + + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + _cly.context_.startActivity(intent); + + shouldFetchContents = false; // disable fetching contents until the next time, this will disable the timer fetching + isCurrentlyInContentZone = true; } else { L.w("[ModuleContent] fetchContentsInternal, response is not valid, skipping"); } @@ -204,13 +196,13 @@ private String prepareContentFetchRequest(@NonNull DisplayMetrics displayMetrics if (displayOption == WebViewDisplayOption.SAFE_AREA) { L.d("[ModuleContent] prepareContentFetchRequest, calculating safe area dimensions..."); SafeAreaDimensions safeArea = SafeAreaCalculator.calculateSafeAreaDimensions(_cly.context_, L); - + // px to dp portraitWidth = (int) Math.ceil(safeArea.portraitWidth / displayMetrics.density); portraitHeight = (int) Math.ceil(safeArea.portraitHeight / displayMetrics.density); landscapeWidth = (int) Math.ceil(safeArea.landscapeWidth / displayMetrics.density); landscapeHeight = (int) Math.ceil(safeArea.landscapeHeight / displayMetrics.density); - + L.d("[ModuleContent] prepareContentFetchRequest, safe area dimensions (px->dp) - Portrait: [" + safeArea.portraitWidth + "x" + safeArea.portraitHeight + " px] -> [" + portraitWidth + "x" + portraitHeight + " dp], topOffset: [" + safeArea.portraitTopOffset + " px]"); L.d("[ModuleContent] prepareContentFetchRequest, safe area dimensions (px->dp) - Landscape: [" + safeArea.landscapeWidth + "x" + safeArea.landscapeHeight + " px] -> [" + landscapeWidth + "x" + landscapeHeight + " dp], topOffset: [" + safeArea.landscapeTopOffset + " px]"); } else { @@ -221,7 +213,7 @@ private String prepareContentFetchRequest(@NonNull DisplayMetrics displayMetrics portraitHeight = portrait ? scaledHeight : scaledWidth; landscapeWidth = portrait ? scaledHeight : scaledWidth; landscapeHeight = portrait ? scaledWidth : scaledHeight; - + L.d("[ModuleContent] prepareContentFetchRequest, using immersive mode (full screen) dimensions (dp) - Portrait: [" + portraitWidth + "x" + portraitHeight + "], Landscape: [" + landscapeWidth + "x" + landscapeHeight + "]"); } @@ -250,24 +242,24 @@ Map parseContent(@NonNull JSONObject respons WebViewDisplayOption displayOption = _cly.config_.webViewDisplayOption; SafeAreaDimensions safeArea = null; - + if (displayOption == WebViewDisplayOption.SAFE_AREA) { L.d("[ModuleContent] parseContent, calculating safe area for coordinate adjustment..."); safeArea = SafeAreaCalculator.calculateSafeAreaDimensions(_cly.context_, L); } - placementCoordinates.put(Configuration.ORIENTATION_PORTRAIT, - extractOrientationPlacements(coordinates, displayMetrics.density, "p", content, + placementCoordinates.put(Configuration.ORIENTATION_PORTRAIT, + extractOrientationPlacements(coordinates, displayMetrics.density, "p", content, displayOption, safeArea != null ? safeArea.portraitTopOffset : 0, safeArea != null ? safeArea.portraitLeftOffset : 0)); - placementCoordinates.put(Configuration.ORIENTATION_LANDSCAPE, - extractOrientationPlacements(coordinates, displayMetrics.density, "l", content, + placementCoordinates.put(Configuration.ORIENTATION_LANDSCAPE, + extractOrientationPlacements(coordinates, displayMetrics.density, "l", content, displayOption, safeArea != null ? safeArea.landscapeTopOffset : 0, safeArea != null ? safeArea.landscapeLeftOffset : 0)); return placementCoordinates; } - private TransparentActivityConfig extractOrientationPlacements(@NonNull JSONObject placements, - float density, @NonNull String orientation, @NonNull String content, + private TransparentActivityConfig extractOrientationPlacements(@NonNull JSONObject placements, + float density, @NonNull String orientation, @NonNull String content, WebViewDisplayOption displayOption, int topOffset, int leftOffset) { if (placements.has(orientation)) { JSONObject orientationPlacements = placements.optJSONObject(orientation); @@ -277,21 +269,21 @@ private TransparentActivityConfig extractOrientationPlacements(@NonNull JSONObje int w = orientationPlacements.optInt("w"); int h = orientationPlacements.optInt("h"); L.d("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], x: [" + x + "], y: [" + y + "], w: [" + w + "], h: [" + h + "]"); - + int xPx = Math.round(x * density); int yPx = Math.round(y * density); int wPx = Math.round(w * density); int hPx = Math.round(h * density); L.d("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], converting dp->px: [" + w + "x" + h + " dp] -> [" + wPx + "x" + hPx + " px], density: [" + density + "]"); - + TransparentActivityConfig config = new TransparentActivityConfig(xPx, yPx, wPx, hPx); config.url = content; config.useSafeArea = (displayOption == WebViewDisplayOption.SAFE_AREA); config.topOffset = topOffset; config.leftOffset = leftOffset; - + L.d("[ModuleContent] extractOrientationPlacements, orientation: [" + orientation + "], created config - useSafeArea: [" + config.useSafeArea + "], topOffset: [" + config.topOffset + "], leftOffset: [" + config.leftOffset + "]"); - + return config; } 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 d8e4b78c3..06919a82a 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java @@ -270,19 +270,18 @@ void presentFeedbackWidgetInternal(@Nullable final CountlyFeedbackWidget widgetI String preparedWidgetUrl = widgetListUrl.toString(); L.d("[ModuleFeedback] Using following url for widget:[" + preparedWidgetUrl + "]"); - iRGenerator.CreatePreflightRequestMaker().doWork(preparedWidgetUrl, null, requestQueueProvider.createConnectionProcessor(), false, true, preflightResponse -> { - if (preflightResponse == null) { - L.e("[ModuleFeedback] Failed to do preflight check for the widget url"); - if (devCallback != null) { - devCallback.onFinished("Failed to do preflight check for the widget url"); + if (!Utils.isNullOrEmpty(widgetInfo.widgetVersion)) { + L.d("[ModuleFeedback] Will use transparent activity for displaying the widget"); + showFeedbackWidget_newActivity(context, preparedWidgetUrl, widgetInfo, devCallback); + } else { + iRGenerator.CreatePreflightRequestMaker().doWork(preparedWidgetUrl, null, requestQueueProvider.createConnectionProcessor(), false, true, preflightResponse -> { + if (preflightResponse == null) { + L.e("[ModuleFeedback] Failed to do preflight check for the widget url"); + if (devCallback != null) { + devCallback.onFinished("Failed to do preflight check for the widget url"); + } + return; } - return; - } - - if (!Utils.isNullOrEmpty(widgetInfo.widgetVersion)) { - L.d("[ModuleFeedback] Will use transparent activity for displaying the widget"); - showFeedbackWidget_newActivity(context, preparedWidgetUrl, widgetInfo, devCallback); - } else { L.d("[ModuleFeedback] Will use dialog for displaying the widget"); //enable for chrome debugging // WebView.setWebContentsDebuggingEnabled(true); @@ -305,8 +304,8 @@ public void run() { } } }); - } - }, L); + }, L); + } } private void showFeedbackWidget(Context context, CountlyFeedbackWidget widgetInfo, String closeButtonText, FeedbackCallback devCallback, String url) { @@ -360,7 +359,7 @@ private void showFeedbackWidget_newActivity(@NonNull Context context, String url if (displayOption == WebViewDisplayOption.SAFE_AREA) { L.d("[ModuleFeedback] showFeedbackWidget_newActivity, calculating safe area dimensions..."); SafeAreaDimensions safeArea = SafeAreaCalculator.calculateSafeAreaDimensions(context, L); - + portraitWidth = safeArea.portraitWidth; portraitHeight = safeArea.portraitHeight; landscapeWidth = safeArea.landscapeWidth; @@ -369,7 +368,7 @@ private void showFeedbackWidget_newActivity(@NonNull Context context, String url landscapeTopOffset = safeArea.landscapeTopOffset; portraitLeftOffset = safeArea.portraitLeftOffset; landscapeLeftOffset = safeArea.landscapeLeftOffset; - + L.d("[ModuleFeedback] showFeedbackWidget_newActivity, safe area dimensions (px) - Portrait: [" + portraitWidth + "x" + portraitHeight + "], topOffset: [" + portraitTopOffset + "], leftOffset: [" + portraitLeftOffset + "]"); L.d("[ModuleFeedback] showFeedbackWidget_newActivity, safe area dimensions (px) - Landscape: [" + landscapeWidth + "x" + landscapeHeight + "], topOffset: [" + landscapeTopOffset + "], leftOffset: [" + landscapeLeftOffset + "]"); } else { @@ -380,7 +379,7 @@ private void showFeedbackWidget_newActivity(@NonNull Context context, String url portraitHeight = portrait ? height : width; landscapeWidth = portrait ? height : width; landscapeHeight = portrait ? width : height; - + L.d("[ModuleFeedback] showFeedbackWidget_newActivity, using immersive mode (full screen) dimensions (px) - Portrait: [" + portraitWidth + "x" + portraitHeight + "], Landscape: [" + landscapeWidth + "x" + landscapeHeight + "]"); }