Skip to content

Commit 4bd2209

Browse files
committed
rename dismissDuration to displayDuration to match JSON
1 parent 829b1f6 commit 4bd2209

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/InAppMessageView.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ interface InAppMessageViewListener {
7171
private int marginPxSizeRight = dpToPx(24);
7272
private int marginPxSizeTop = dpToPx(24);
7373
private int marginPxSizeBottom = dpToPx(24);
74-
private double dismissDuration;
74+
private double displayDuration;
7575
private boolean hasBackground;
7676
private boolean shouldDismissWhenActive = false;
7777
private boolean isDragging = false;
@@ -88,9 +88,30 @@ interface InAppMessageViewListener {
8888
this.displayLocation = content.getDisplayLocation();
8989
this.pageHeight = content.getPageHeight();
9090
this.pageWidth = ViewGroup.LayoutParams.MATCH_PARENT;
91-
this.dismissDuration = content.getDismissDuration() == null ? 0 : dismissDuration;
91+
this.displayDuration = content.getDisplayDuration() == null ? 0 : content.getDisplayDuration();
9292
this.hasBackground = !displayLocation.isBanner();
9393
this.disableDragDismiss = disableDragDismiss;
94+
setMarginsFromContent(content);
95+
}
96+
97+
/**
98+
* For now we only support default margin or no margin.
99+
* Any non-zero value will be treated as default margin
100+
* @param content in app message content and style
101+
*/
102+
private void setMarginsFromContent(OSInAppMessageContent content) {
103+
if (content.getTopMargin() != null && content.getTopMargin() == 0) {
104+
this.marginPxSizeTop = content.getTopMargin();
105+
}
106+
if (content.getBottomMargin() != null && content.getBottomMargin() == 0) {
107+
this.marginPxSizeBottom = content.getBottomMargin();
108+
}
109+
if (content.getLeftMargin() != null && content.getLeftMargin() == 0) {
110+
this.marginPxSizeLeft = content.getLeftMargin();
111+
}
112+
if (content.getRightMargin() != null && content.getRightMargin() == 0) {
113+
this.marginPxSizeRight = content.getRightMargin();
114+
}
94115
}
95116

96117
void setWebView(WebView webView) {
@@ -299,9 +320,7 @@ private void createPopupWindow(@NonNull RelativeLayout parentRelativeLayout) {
299320
0
300321
);
301322
}
302-
/*
303323

304-
*/
305324
private void setUpParentRelativeLayout(Context context) {
306325
parentRelativeLayout = new RelativeLayout(context);
307326
parentRelativeLayout.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
@@ -394,7 +413,7 @@ private CardView createCardView(Context context) {
394413
* Schedule dismiss behavior, if IAM has a dismiss after X number of seconds timer.
395414
*/
396415
private void startDismissTimerIfNeeded() {
397-
if (dismissDuration <= 0)
416+
if (displayDuration <= 0)
398417
return;
399418

400419
if (scheduleDismissRunnable != null)
@@ -414,7 +433,7 @@ public void run() {
414433
}
415434
}
416435
};
417-
handler.postDelayed(scheduleDismissRunnable, (long) dismissDuration * 1_000);
436+
handler.postDelayed(scheduleDismissRunnable, (long) displayDuration * 1_000);
418437
}
419438

420439
// Do not add view until activity is ready
@@ -627,7 +646,7 @@ public String toString() {
627646
"currentActivity=" + currentActivity +
628647
", pageWidth=" + pageWidth +
629648
", pageHeight=" + pageHeight +
630-
", dismissDuration=" + dismissDuration +
649+
", displayDuration=" + displayDuration +
631650
", hasBackground=" + hasBackground +
632651
", shouldDismissWhenActive=" + shouldDismissWhenActive +
633652
", isDragging=" + isDragging +

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageContent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal open class OSInAppMessageContent constructor(jsonObject: JSONObject) {
1818
var rightMargin: Int? = 1
1919
// The following properties are populated from Javascript events
2020
var displayLocation: WebViewManager.Position? = null
21-
var dismissDuration: Double? = null
21+
var displayDuration: Double? = null
2222
var pageHeight: Int = 0
2323

2424
init {

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSInAppMessageController.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,7 @@ public void tagsAvailable(JSONObject tags) {
790790

791791
private OSInAppMessageContent parseMessageContentData(JSONObject data, OSInAppMessageInternal message) {
792792
OSInAppMessageContent content = new OSInAppMessageContent(data);
793-
double displayDuration = data.optDouble("display_duration");
794-
message.setDisplayDuration(displayDuration);
793+
message.setDisplayDuration(content.getDisplayDuration());
795794
return content;
796795
}
797796

0 commit comments

Comments
 (0)