Skip to content

Commit 3c4447e

Browse files
authored
Merge pull request #230 from Iterable/MOB-1573-Replace-Dialog-with-DialogFragment
[MOB-1573] - Replace Dialog with DialogFragments
2 parents 892c750 + 9f1d00b commit 3c4447e

File tree

6 files changed

+21
-341
lines changed

6 files changed

+21
-341
lines changed

app/src/androidTest/java/com/iterable/iterableapi/MainActivityTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.iterable.iterableapi;
22

33
import android.content.Intent;
4-
import androidx.recyclerview.widget.RecyclerView;
54
import android.view.View;
65

6+
import androidx.recyclerview.widget.RecyclerView;
77
import androidx.test.espresso.action.ViewActions;
88
import androidx.test.espresso.intent.rule.IntentsTestRule;
99
import androidx.test.espresso.web.webdriver.Locator;
@@ -69,7 +69,7 @@ public void setUp() throws Exception {
6969
server.setDispatcher(dispatcher);
7070
// This is done so we don't hold a reference to the previous in-app notification.
7171
// We should handle in-app dismissal when the parent activity is destroyed though.
72-
IterableInAppHTMLNotification.notification = null;
72+
IterableInAppFragmentHTMLNotification.notification = null;
7373
IterableApi.overrideURLEndpointPath(server.url("").toString());
7474
IterableApi.sharedInstance = new IterableApi();
7575
IterableTestUtils.createIterableApiNew(new IterableTestUtils.ConfigBuilderExtender() {

iterableapi/src/androidTest/java/com/iterable/iterableapi/IterableInAppTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.junit.Test;
1212
import org.junit.runner.RunWith;
1313

14-
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
1514
import static junit.framework.Assert.assertEquals;
1615

1716
/**
@@ -22,12 +21,12 @@
2221
@MediumTest
2322
public class IterableInAppTest {
2423

25-
IterableInAppHTMLNotification notification;
24+
IterableInAppFragmentHTMLNotification notification;
2625

2726
@Before
2827
@UiThreadTest
2928
public void setUp() throws Exception {
30-
notification = IterableInAppHTMLNotification.createInstance(getApplicationContext(), "");
29+
notification = new IterableInAppFragmentHTMLNotification();
3130
}
3231

3332
@Test

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppDisplayer.java

+2-48
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
import android.app.Activity;
44
import android.content.Context;
5-
import android.content.DialogInterface;
65
import android.graphics.Rect;
76

87
import androidx.annotation.NonNull;
9-
import androidx.annotation.Nullable;
108
import androidx.fragment.app.FragmentActivity;
119

1210
class IterableInAppDisplayer {
@@ -18,14 +16,14 @@ class IterableInAppDisplayer {
1816
}
1917

2018
boolean isShowingInApp() {
21-
return IterableInAppHTMLNotification.getInstance() != null;
19+
return IterableInAppFragmentHTMLNotification.getInstance() != null;
2220
}
2321

2422
boolean showMessage(@NonNull IterableInAppMessage message, IterableInAppLocation location, @NonNull final IterableHelper.IterableUrlCallback clickCallback) {
2523
Activity currentActivity = activityMonitor.getCurrentActivity();
2624
// Prevent double display
2725
if (currentActivity != null) {
28-
return IterableInAppDisplayer.showIterableNotificationHTML(currentActivity,
26+
return IterableInAppDisplayer.showIterableFragmentNotificationHTML(currentActivity,
2927
message.getContent().html,
3028
message.getMessageId(),
3129
clickCallback,
@@ -36,50 +34,6 @@ boolean showMessage(@NonNull IterableInAppMessage message, IterableInAppLocation
3634
return false;
3735
}
3836

39-
/**
40-
* Displays an html rendered InApp Notification
41-
* @param context
42-
* @param htmlString
43-
* @param messageId
44-
* @param clickCallback
45-
* @param backgroundAlpha
46-
* @param padding
47-
*/
48-
static boolean showIterableNotificationHTML(@NonNull Context context, @Nullable String htmlString, String messageId, final IterableHelper.IterableUrlCallback clickCallback, double backgroundAlpha, Rect padding, boolean callbackOnCancel, IterableInAppLocation location) {
49-
if (context instanceof Activity) {
50-
Activity currentActivity = (Activity) context;
51-
if (htmlString != null) {
52-
if (IterableInAppHTMLNotification.getInstance() != null) {
53-
IterableLogger.w(IterableInAppManager.TAG, "Skipping the in-app notification: another notification is already being displayed");
54-
return false;
55-
}
56-
57-
IterableInAppHTMLNotification notification = IterableInAppHTMLNotification.createInstance(context, htmlString);
58-
notification.setTrackParams(messageId);
59-
notification.setCallback(clickCallback);
60-
notification.setBackgroundAlpha(backgroundAlpha);
61-
notification.setPadding(padding);
62-
notification.setOwnerActivity(currentActivity);
63-
notification.setLocation(location);
64-
65-
if (callbackOnCancel) {
66-
notification.setOnCancelListener(new DialogInterface.OnCancelListener() {
67-
@Override
68-
public void onCancel(DialogInterface dialog) {
69-
clickCallback.execute(null);
70-
}
71-
});
72-
}
73-
74-
notification.show();
75-
return true;
76-
}
77-
} else {
78-
IterableLogger.w(IterableInAppManager.TAG, "To display in-app notifications, the context must be of an instance of: Activity");
79-
}
80-
return false;
81-
}
82-
8337
/**
8438
* Displays an html rendered InApp Notification
8539
* @param context

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppHTMLNotification.java

-272
This file was deleted.

0 commit comments

Comments
 (0)