Skip to content

Commit e1c9184

Browse files
authored
[MOB-2063] Make sure we refresh in-app on app launch (#263)
[MOB-2063] Make sure we refresh in-app on app launch
2 parents 4f708bb + d576be5 commit e1c9184

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

app/src/androidTest/java/com/iterable/iterableapi/testapp/InboxUITest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import androidx.test.ext.junit.runners.AndroidJUnit4;
44
import androidx.test.rule.ActivityTestRule;
55

6+
import com.iterable.iterableapi.IterableApi;
67
import com.iterable.iterableapi.ui.R;
78
import com.iterable.iterableapi.ui.inbox.IterableInboxActivity;
89

910
import org.junit.Rule;
1011
import org.junit.Test;
1112
import org.junit.runner.RunWith;
1213

14+
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
1315
import static androidx.test.espresso.Espresso.onView;
1416
import static androidx.test.espresso.action.ViewActions.click;
1517
import static androidx.test.espresso.matcher.ViewMatchers.withId;
@@ -18,7 +20,13 @@
1820
@RunWith(AndroidJUnit4.class)
1921
public class InboxUITest {
2022
@Rule
21-
public ActivityTestRule rule = new ActivityTestRule<>(IterableInboxActivity.class);
23+
public ActivityTestRule<IterableInboxActivity> rule = new ActivityTestRule<IterableInboxActivity>(IterableInboxActivity.class) {
24+
@Override
25+
protected void beforeActivityLaunched() {
26+
super.beforeActivityLaunched();
27+
IterableApi.initialize(getApplicationContext(), "apiKey");
28+
}
29+
};
2230

2331
@Test
2432
public void basicTest() {

app/src/test/java/com/iterable/iterableapi/InboxUITest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import androidx.test.ext.junit.runners.AndroidJUnit4;
44
import androidx.test.rule.ActivityTestRule;
55

6-
import com.iterable.iterableapi.ui.inbox.IterableInboxActivity;
76
import com.iterable.iterableapi.ui.R;
7+
import com.iterable.iterableapi.ui.inbox.IterableInboxActivity;
88

99
import org.junit.Rule;
1010
import org.junit.Test;
11-
import org.junit.rules.TestRule;
1211
import org.junit.runner.RunWith;
1312

13+
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
1414
import static androidx.test.espresso.Espresso.onView;
1515
import static androidx.test.espresso.action.ViewActions.click;
1616
import static androidx.test.espresso.matcher.ViewMatchers.withId;
@@ -19,7 +19,13 @@
1919
@RunWith(AndroidJUnit4.class)
2020
public class InboxUITest {
2121
@Rule
22-
public ActivityTestRule rule = new ActivityTestRule<>(IterableInboxActivity.class);
22+
public ActivityTestRule<IterableInboxActivity> rule = new ActivityTestRule<IterableInboxActivity>(IterableInboxActivity.class) {
23+
@Override
24+
protected void beforeActivityLaunched() {
25+
super.beforeActivityLaunched();
26+
IterableApi.initialize(getApplicationContext(), "apiKey");
27+
}
28+
};
2329

2430
@Test
2531
public void basicTest() {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class IterableApi {
5252
private String _deviceId;
5353
private boolean _firstForegroundHandled;
5454

55-
private IterableInAppManager inAppManager;
55+
private @Nullable IterableInAppManager inAppManager;
5656
private String inboxSessionId;
5757
private HashMap<String, String> deviceAttributes = new HashMap<>();
5858

@@ -115,8 +115,8 @@ public Bundle getPayloadData() {
115115
@NonNull
116116
public IterableInAppManager getInAppManager() {
117117
if (inAppManager == null) {
118-
inAppManager = new IterableInAppManager(this, config.inAppHandler, config.inAppDisplayInterval);
119-
inAppManager.syncInApp();
118+
throw new RuntimeException("IterableApi must be initialized before calling getInAppManager(). " +
119+
"Make sure you call IterableApi#initialize() in Application#onCreate");
120120
}
121121
return inAppManager;
122122
}
@@ -266,6 +266,7 @@ public static void initialize(@NonNull Context context, @NonNull String apiKey,
266266
sharedInstance.checkForDeferredDeeplink();
267267
IterableActivityMonitor.getInstance().registerLifecycleCallbacks(context);
268268
IterableActivityMonitor.getInstance().addCallback(sharedInstance.activityMonitorListener);
269+
sharedInstance.inAppManager = new IterableInAppManager(sharedInstance, sharedInstance.config.inAppHandler, sharedInstance.config.inAppDisplayInterval);
269270
}
270271

271272
/**

0 commit comments

Comments
 (0)