Skip to content

Commit c637e67

Browse files
committed
Clean up from merge from other branches and new unique outcome logic
* When sending unique outcomes it should be per notification in attributed sessions and per session for unattributed sessions * Added integration tests to validate the unique outcome work makes the measure endpoint at correct times * Reorganized the example app to make more sense with buttons and fields placement
1 parent 662e3da commit c637e67

File tree

13 files changed

+411
-153
lines changed

13 files changed

+411
-153
lines changed

OneSignalSDK/app/src/main/res/layout/activity_main.xml

Lines changed: 74 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
xmlns:tools="http://schemas.android.com/tools"
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
5-
android:paddingLeft="@dimen/activity_horizontal_margin"
6-
android:paddingTop="@dimen/activity_vertical_margin"
7-
android:paddingRight="@dimen/activity_horizontal_margin"
8-
android:paddingBottom="@dimen/activity_vertical_margin"
95
android:scrollbarStyle="outsideOverlay"
106
tools:context="com.onesignal.MainActivity">
117

128
<LinearLayout
139
android:layout_width="match_parent"
1410
android:layout_height="wrap_content"
11+
android:paddingLeft="@dimen/activity_horizontal_margin"
12+
android:paddingTop="@dimen/activity_vertical_margin"
13+
android:paddingRight="@dimen/activity_horizontal_margin"
14+
android:paddingBottom="@dimen/activity_vertical_margin"
1515
android:orientation="vertical">
1616

1717
<Button
@@ -28,6 +28,30 @@
2828
android:onClick="onConsentButtonClicked"
2929
android:text="Provide Consent" />
3030

31+
<LinearLayout
32+
android:layout_width="match_parent"
33+
android:layout_height="match_parent"
34+
android:orientation="horizontal">
35+
36+
<EditText
37+
android:id="@+id/triggerKey"
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:layout_weight="1"
41+
android:ems="10"
42+
android:hint="Trigger Key"
43+
android:inputType="textPersonName" />
44+
45+
<EditText
46+
android:id="@+id/triggerValue"
47+
android:layout_width="wrap_content"
48+
android:layout_height="wrap_content"
49+
android:layout_weight="1"
50+
android:ems="10"
51+
android:hint="Trigger Value"
52+
android:inputType="textPersonName" />
53+
54+
</LinearLayout>
3155

3256
<Button
3357
android:id="@+id/setTrigger"
@@ -36,19 +60,28 @@
3660
android:onClick="onSetTrigger"
3761
android:text="Set Trigger" />
3862

63+
<EditText
64+
android:id="@+id/outcomeName"
65+
android:layout_width="match_parent"
66+
android:layout_height="wrap_content"
67+
android:ems="10"
68+
android:hint="Outcome Name"
69+
android:inputType="textPersonName" />
70+
3971
<Button
4072
android:id="@+id/sendEvent"
4173
android:layout_width="match_parent"
4274
android:layout_height="wrap_content"
4375
android:onClick="onSendOutcomeClicked"
4476
android:text="Send Outcome" />
4577

46-
<Button
47-
android:id="@+id/sendEventWithValue"
78+
<EditText
79+
android:id="@+id/outcomeUniqueName"
4880
android:layout_width="match_parent"
4981
android:layout_height="wrap_content"
50-
android:onClick="onSendOutcomeWithValueClicked"
51-
android:text="Send Outcome With Value" />
82+
android:ems="10"
83+
android:hint="Unique Outcome Name"
84+
android:inputType="textPersonName" />
5285

5386
<Button
5487
android:id="@+id/sendUniqueEvent"
@@ -57,6 +90,37 @@
5790
android:onClick="onSendUniqueOutcomeClicked"
5891
android:text="Send Unique Outcome" />
5992

93+
<LinearLayout
94+
android:layout_width="match_parent"
95+
android:layout_height="wrap_content">
96+
97+
<EditText
98+
android:id="@+id/outcomeNameValue"
99+
android:layout_width="0dp"
100+
android:layout_height="wrap_content"
101+
android:layout_weight="1"
102+
android:ems="10"
103+
android:hint="Outcome Name"
104+
android:inputType="textPersonName" />
105+
106+
<EditText
107+
android:id="@+id/outcomeValue"
108+
android:layout_width="0dp"
109+
android:layout_height="wrap_content"
110+
android:layout_weight="1"
111+
android:ems="10"
112+
android:hint="Outcome Value"
113+
android:inputType="numberDecimal" />
114+
115+
</LinearLayout>
116+
117+
<Button
118+
android:id="@+id/sendEventWithValue"
119+
android:layout_width="match_parent"
120+
android:layout_height="wrap_content"
121+
android:onClick="onSendOutcomeWithValueClicked"
122+
android:text="Send Outcome With Value" />
123+
60124
<Button
61125
android:id="@+id/logoutEmail"
62126
android:layout_width="match_parent"
@@ -72,22 +136,6 @@
72136
android:hint="YOUR_APP_ID_HERE"
73137
android:inputType="textPersonName" />
74138

75-
<EditText
76-
android:id="@+id/outcomeName"
77-
android:layout_width="match_parent"
78-
android:layout_height="wrap_content"
79-
android:ems="10"
80-
android:hint="Outcome Name"
81-
android:inputType="textPersonName" />
82-
83-
<EditText
84-
android:id="@+id/outcomeUniqueName"
85-
android:layout_width="match_parent"
86-
android:layout_height="wrap_content"
87-
android:ems="10"
88-
android:hint="Unique Outcome Name"
89-
android:inputType="textPersonName" />
90-
91139
<LinearLayout
92140
android:layout_width="0px"
93141
android:layout_height="0px"
@@ -112,7 +160,8 @@
112160
android:layout_height="wrap_content"
113161
android:layout_weight="1"
114162
android:onClick="onUnsubscribeClicked"
115-
android:text="UnSubscribe" />
163+
android:text="Unsubscribe" />
164+
116165
</LinearLayout>
117166

118167
<LinearLayout
@@ -134,53 +183,7 @@
134183
android:layout_weight="1"
135184
android:onClick="onGetTagsClicked"
136185
android:text="Get Tags" />
137-
</LinearLayout>
138186

139-
<LinearLayout
140-
android:layout_width="match_parent"
141-
android:layout_height="match_parent"
142-
android:orientation="horizontal">
143-
144-
<EditText
145-
android:id="@+id/triggerKey"
146-
android:layout_width="wrap_content"
147-
android:layout_height="wrap_content"
148-
android:layout_weight="1"
149-
android:ems="10"
150-
android:hint="Trigger Key"
151-
android:inputType="textPersonName" />
152-
153-
<EditText
154-
android:id="@+id/triggerValue"
155-
android:layout_width="wrap_content"
156-
android:layout_height="wrap_content"
157-
android:layout_weight="1"
158-
android:ems="10"
159-
android:hint="Trigger Value"
160-
android:inputType="textPersonName" />
161-
</LinearLayout>
162-
163-
<LinearLayout
164-
android:layout_width="match_parent"
165-
android:layout_height="wrap_content">
166-
167-
<EditText
168-
android:id="@+id/outcomeNameValue"
169-
android:layout_width="0dp"
170-
android:layout_height="wrap_content"
171-
android:layout_weight="1"
172-
android:ems="10"
173-
android:hint="Outcome Name"
174-
android:inputType="textPersonName" />
175-
176-
<EditText
177-
android:id="@+id/outcomeValue"
178-
android:layout_width="0dp"
179-
android:layout_height="wrap_content"
180-
android:layout_weight="1"
181-
android:ems="10"
182-
android:hint="Outcome Value"
183-
android:inputType="numberDecimal" />
184187
</LinearLayout>
185188

186189
<RelativeLayout

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ static void markRestoredNotificationAsDismissed(NotificationGenerationJob notifi
274274
// Clean up old records after 1 week.
275275
static void deleteOldNotifications(SQLiteDatabase writableDb) {
276276
writableDb.delete(NotificationTable.TABLE_NAME,
277-
NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1_000L) - 604800L),
277+
NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1_000L) - 604_800L),
278278
null);
279279
}
280280

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private void persistDisplayedIams() {
385385
private @NonNull Set<String> getAllDismissedIams() {
386386
Set<String> dismissedIams = new HashSet<>(triggeredMessages);
387387
synchronized (messageDisplayQueue) {
388-
for(OSInAppMessage message : messageDisplayQueue)
388+
for (OSInAppMessage message : messageDisplayQueue)
389389
dismissedIams.remove(message.messageId);
390390
}
391391
return dismissedIams;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,19 @@ public void init() {
387387
private static String userId = null, emailId = null;
388388
private static int subscribableStatus;
389389

390+
// Is the init() of OneSignal SDK finished yet
390391
private static boolean initDone;
391-
392392
static boolean isInitDone() {
393393
return initDone;
394394
}
395395

396+
// Is the app in the foreground or not
396397
private static boolean foreground;
397398
static boolean isForeground() {
398399
return foreground;
399400
}
400401

402+
// Tells the action taken to enter the app
401403
@NonNull private static AppEntryAction appEntryState = AppEntryAction.APP_CLOSE;
402404
static @NonNull AppEntryAction getAppEntryState() {
403405
return appEntryState;
@@ -421,7 +423,8 @@ private static OSSessionManager.SessionListener getNewSessionListener() {
421423
@Override
422424
public void onSessionEnding(@NonNull OSSessionManager.SessionResult lastSessionResult) {
423425
if (outcomeEventsController != null)
424-
outcomeEventsController.clearOutcomes();
426+
outcomeEventsController.cleanOutcomes();
427+
425428
FocusTimeController.getInstance().onSessionEnded(lastSessionResult);
426429
}
427430
};
@@ -799,8 +802,10 @@ private static void doSessionInit() {
799802
// Check session time to determine whether to start a new session or not
800803
if (isPastOnSessionTime()) {
801804
OneSignalStateSynchronizer.setNewSession();
802-
if (foreground)
805+
if (foreground) {
806+
outcomeEventsController.cleanOutcomes();
803807
sessionManager.restartSessionIfNeeded();
808+
}
804809
} else if (foreground) {
805810
OSInAppMessageController.getController().initWithCachedInAppMessages();
806811
sessionManager.attemptSessionUpgrade();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ class OneSignalPrefs {
8787
public static final String PREFS_OS_DIRECT_ENABLED = "PREFS_OS_DIRECT_ENABLED";
8888
public static final String PREFS_OS_INDIRECT_ENABLED = "PREFS_OS_INDIRECT_ENABLED";
8989
public static final String PREFS_OS_UNATTRIBUTED_ENABLED = "PREFS_OS_UNATTRIBUTED_ENABLED";
90-
public static final String PREFS_OS_CACHED_SESSION_OUTCOME_EVENT = "PREFS_OS_CACHED_SESSION_OUTCOME_EVENT";
90+
public static final String PREFS_OS_OUTCOMES_CURRENT_SESSION = "PREFS_OS_OUTCOMES_CURRENT_SESSION";
91+
public static final String PREFS_OS_UNIQUE_OUTCOME_EVENTS_SENT = "PREFS_OS_UNIQUE_OUTCOME_EVENTS_SENT";
9192

9293

9394
// PLAYER PURCHASE KEYS

0 commit comments

Comments
 (0)