@@ -143,6 +143,24 @@ public interface GetTagsHandler {
143
143
void tagsAvailable (JSONObject tags );
144
144
}
145
145
146
+ public interface ChangeTagsUpdateHandler {
147
+ void onSuccess (JSONObject tags );
148
+ void onFailure (SendTagsError error );
149
+ }
150
+
151
+ public static class SendTagsError {
152
+ private String message ;
153
+ private int code ;
154
+
155
+ SendTagsError (int errorCode , String errorMessage ) {
156
+ this .message = errorMessage ;
157
+ this .code = errorCode ;
158
+ }
159
+
160
+ public int getCode () { return code ; }
161
+ public String getMessage () { return message ; }
162
+ }
163
+
146
164
147
165
public enum EmailErrorType {
148
166
VALIDATION , REQUIRES_EMAIL_AUTH , INVALID_OPERATION , NETWORK
@@ -869,6 +887,13 @@ private static void fireCallbackForOpenedNotifications() {
869
887
870
888
unprocessedOpenedNotifis .clear ();
871
889
}
890
+ /**
891
+ * Please do not use this method for logging, it is meant solely to be
892
+ * used by our wrapper SDK's.
893
+ */
894
+ public static void onesignalLog (LOG_LEVEL level , String message ) {
895
+ OneSignal .Log (level , message );
896
+ }
872
897
873
898
public static boolean userProvidedPrivacyConsent () {
874
899
return getSavedUserConsentStatus ();
@@ -1422,6 +1447,24 @@ public static void sendTags(String jsonString) {
1422
1447
*
1423
1448
*/
1424
1449
public static void sendTags (final JSONObject keyValues ) {
1450
+ sendTags (keyValues , null );
1451
+ }
1452
+
1453
+ /**
1454
+ * Tag a user based on an app event of your choosing so later you can create
1455
+ * <a href="https://documentation.onesignal.com/docs/segmentation">OneSignal Segments</a>
1456
+ * to target these users.
1457
+ *
1458
+ * NOTE: The ChangeTagsUpdateHandler will not be called under all circumstances. It can also take
1459
+ * more than 5 seconds in some cases to be called, so please do not block any user action
1460
+ * based on this callback.
1461
+ * @param keyValues Key value pairs of your choosing to create or update. <b>Note:</b>
1462
+ * Passing in a blank String as a value deletes a key.
1463
+ * You can also call {@link #deleteTag(String)} or {@link #deleteTags(String)}.
1464
+ *
1465
+ */
1466
+ public static void sendTags (final JSONObject keyValues , ChangeTagsUpdateHandler handler ) {
1467
+ final ChangeTagsUpdateHandler tagsHandler = handler ;
1425
1468
1426
1469
//if applicable, check if the user provided privacy consent
1427
1470
if (shouldLogUserPrivacyConsentErrorMessageForMethodName ("sendTags()" ))
@@ -1430,10 +1473,13 @@ public static void sendTags(final JSONObject keyValues) {
1430
1473
Runnable sendTagsRunnable = new Runnable () {
1431
1474
@ Override
1432
1475
public void run () {
1433
- if (keyValues == null ) return ;
1476
+ if (keyValues == null ) {
1477
+ if (tagsHandler != null )
1478
+ tagsHandler .onFailure (new SendTagsError (-1 , "Attempted to send null tags" ));
1479
+ return ;
1480
+ }
1434
1481
1435
1482
JSONObject existingKeys = OneSignalStateSynchronizer .getTags (false ).result ;
1436
-
1437
1483
JSONObject toSend = new JSONObject ();
1438
1484
1439
1485
Iterator <String > keys = keyValues .keys ();
@@ -1456,15 +1502,21 @@ else if (keyValues.isNull(key) || "".equals(value)) {
1456
1502
catch (Throwable t ) {}
1457
1503
}
1458
1504
1459
- if (!toSend .toString ().equals ("{}" ))
1460
- OneSignalStateSynchronizer .sendTags (toSend );
1505
+ if (!toSend .toString ().equals ("{}" )) {
1506
+ OneSignalStateSynchronizer .sendTags (toSend , tagsHandler );
1507
+ } else {
1508
+ tagsHandler .onSuccess (existingKeys );
1509
+ }
1461
1510
}
1462
1511
};
1463
1512
1464
1513
1465
1514
if (appContext == null || shouldRunTaskThroughQueue ()) {
1466
1515
Log (LOG_LEVEL .ERROR , "You must initialize OneSignal before modifying tags!" +
1467
1516
"Moving this operation to a pending task queue." );
1517
+ if (tagsHandler != null )
1518
+ tagsHandler .onFailure (new SendTagsError (-1 , "You must initialize OneSignal before modifying tags!" +
1519
+ "Moving this operation to a pending task queue." ));
1468
1520
addTaskToQueue (new PendingTaskRunnable (sendTagsRunnable ));
1469
1521
return ;
1470
1522
}
@@ -1612,14 +1664,17 @@ public void run() {
1612
1664
* @param key Key to remove.
1613
1665
*/
1614
1666
public static void deleteTag (String key ) {
1667
+ deleteTag (key , null );
1668
+ }
1615
1669
1670
+ public static void deleteTag (String key , ChangeTagsUpdateHandler handler ) {
1616
1671
//if applicable, check if the user provided privacy consent
1617
1672
if (shouldLogUserPrivacyConsentErrorMessageForMethodName ("deleteTag()" ))
1618
1673
return ;
1619
1674
1620
1675
Collection <String > tempList = new ArrayList <>(1 );
1621
1676
tempList .add (key );
1622
- deleteTags (tempList );
1677
+ deleteTags (tempList , handler );
1623
1678
}
1624
1679
1625
1680
/**
@@ -1628,7 +1683,10 @@ public static void deleteTag(String key) {
1628
1683
* @param keys Keys to remove.
1629
1684
*/
1630
1685
public static void deleteTags (Collection <String > keys ) {
1686
+ deleteTags (keys , null );
1687
+ }
1631
1688
1689
+ public static void deleteTags (Collection <String > keys , ChangeTagsUpdateHandler handler ) {
1632
1690
//if applicable, check if the user provided privacy consent
1633
1691
if (shouldLogUserPrivacyConsentErrorMessageForMethodName ("deleteTags()" ))
1634
1692
return ;
@@ -1638,14 +1696,17 @@ public static void deleteTags(Collection<String> keys) {
1638
1696
for (String key : keys )
1639
1697
jsonTags .put (key , "" );
1640
1698
1641
- sendTags (jsonTags );
1699
+ sendTags (jsonTags , handler );
1642
1700
} catch (Throwable t ) {
1643
1701
Log (LOG_LEVEL .ERROR , "Failed to generate JSON for deleteTags." , t );
1644
1702
}
1645
1703
}
1646
1704
1647
1705
public static void deleteTags (String jsonArrayString ) {
1706
+ deleteTags (jsonArrayString , null );
1707
+ }
1648
1708
1709
+ public static void deleteTags (String jsonArrayString , ChangeTagsUpdateHandler handler ) {
1649
1710
//if applicable, check if the user provided privacy consent
1650
1711
if (shouldLogUserPrivacyConsentErrorMessageForMethodName ("deleteTags()" ))
1651
1712
return ;
@@ -1657,7 +1718,7 @@ public static void deleteTags(String jsonArrayString) {
1657
1718
for (int i = 0 ; i < jsonArray .length (); i ++)
1658
1719
jsonTags .put (jsonArray .getString (i ), "" );
1659
1720
1660
- sendTags (jsonTags );
1721
+ sendTags (jsonTags , handler );
1661
1722
} catch (Throwable t ) {
1662
1723
Log (LOG_LEVEL .ERROR , "Failed to generate JSON for deleteTags." , t );
1663
1724
}
@@ -2138,6 +2199,10 @@ public static void setInFocusDisplaying(int displayOption) {
2138
2199
setInFocusDisplaying (getInFocusDisplaying (displayOption ));
2139
2200
}
2140
2201
2202
+ public static OSInFocusDisplayOption currentInFocusDisplayOption () {
2203
+ return getCurrentOrNewInitBuilder ().mDisplayOption ;
2204
+ }
2205
+
2141
2206
private static OSInFocusDisplayOption getInFocusDisplaying (int displayOption ) {
2142
2207
switch (displayOption ) {
2143
2208
case 0 :
0 commit comments