Skip to content

Commit 1f9eaf2

Browse files
committed
Remove remove*handler methods
* User can call set*Handler with null for removing the handler
1 parent c7004bb commit 1f9eaf2

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -621,18 +621,18 @@ static void setRemoteNotificationReceivedHandler(OSRemoteNotificationReceivedHan
621621
remoteNotificationReceivedHandler = callback;
622622
}
623623

624-
public static void setNotificationWillShowInForegroundHandler(NotificationWillShowInForegroundHandler callback) {
624+
public static void setNotificationWillShowInForegroundHandler(@Nullable NotificationWillShowInForegroundHandler callback) {
625625
notificationWillShowInForegroundHandler = callback;
626626
}
627627

628-
public static void setNotificationOpenedHandler(OSNotificationOpenedHandler callback) {
628+
public static void setNotificationOpenedHandler(@Nullable OSNotificationOpenedHandler callback) {
629629
notificationOpenedHandler = callback;
630630

631631
if (initDone && notificationOpenedHandler != null)
632632
fireCallbackForOpenedNotifications();
633633
}
634634

635-
public static void setInAppMessageClickHandler(InAppMessageClickHandler callback) {
635+
public static void setInAppMessageClickHandler(@Nullable InAppMessageClickHandler callback) {
636636
inAppMessageClickHandler = callback;
637637
}
638638

@@ -2740,14 +2740,6 @@ public void run() {
27402740
runCancelGroupedNotifications.run();
27412741
}
27422742

2743-
public static void removeNotificationWillShowInForegroundHandler() {
2744-
OneSignal.notificationWillShowInForegroundHandler = null;
2745-
}
2746-
2747-
public static void removeNotificationOpenedHandler() {
2748-
notificationOpenedHandler = null;
2749-
}
2750-
27512743
/**
27522744
* The {@link OSPermissionObserver#onOSPermissionChanged(OSPermissionStateChanges)}
27532745
* method will be fired on the passed-in object when a notification permission setting changes.

OneSignalSDK/unittest/src/test/java/com/test/onesignal/MainOneSignalClassRunner.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ public void shouldCorrectlyRemoveOpenedHandlerAndFireMissedOnesWhenAddedBack() t
10521052
OneSignal.setNotificationOpenedHandler(getNotificationOpenedHandler());
10531053
threadAndTaskWait();
10541054

1055-
OneSignal.removeNotificationOpenedHandler();
1055+
OneSignal.setNotificationOpenedHandler(null);
10561056
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Robo test message\", \"custom\": { \"i\": \"UUID\" } }]"), false, ONESIGNAL_NOTIFICATION_ID);
10571057
assertNull(lastNotificationOpenedBody);
10581058

@@ -2739,8 +2739,8 @@ public void onSuccess(JSONObject response) {}
27392739
@Override
27402740
public void onFailure(JSONObject response) {}
27412741
});
2742-
OneSignal.removeNotificationOpenedHandler();
2743-
OneSignal.removeNotificationWillShowInForegroundHandler();
2742+
OneSignal.setNotificationOpenedHandler(null);
2743+
OneSignal.setNotificationWillShowInForegroundHandler(null);
27442744
threadAndTaskWait();
27452745

27462746
// Permission subscription wont return until OneSignal init is done
@@ -2771,8 +2771,8 @@ public void onSuccess(JSONObject response) {}
27712771
@Override
27722772
public void onFailure(JSONObject response) {}
27732773
});
2774-
OneSignal.removeNotificationOpenedHandler();
2775-
OneSignal.removeNotificationWillShowInForegroundHandler();
2774+
OneSignal.setNotificationOpenedHandler(null);
2775+
OneSignal.setNotificationWillShowInForegroundHandler(null);
27762776
threadAndTaskWait();
27772777

27782778
// TODO change to assertNull(OneSignal.getPermissionSubscriptionState()); when privacy consent public set is removed
@@ -2801,8 +2801,8 @@ public void onSuccess(JSONObject response) {}
28012801
@Override
28022802
public void onFailure(JSONObject response) {}
28032803
});
2804-
OneSignal.removeNotificationOpenedHandler();
2805-
OneSignal.removeNotificationWillShowInForegroundHandler();
2804+
OneSignal.setNotificationOpenedHandler(null);
2805+
OneSignal.setNotificationWillShowInForegroundHandler(null);
28062806
threadAndTaskWait();
28072807

28082808
assertNull(OneSignal.getPermissionSubscriptionState());
@@ -2831,8 +2831,8 @@ public void onSuccess(JSONObject response) {}
28312831
@Override
28322832
public void onFailure(JSONObject response) {}
28332833
});
2834-
OneSignal.removeNotificationOpenedHandler();
2835-
OneSignal.removeNotificationWillShowInForegroundHandler();
2834+
OneSignal.setNotificationOpenedHandler(null);
2835+
OneSignal.setNotificationWillShowInForegroundHandler(null);
28362836
threadAndTaskWait();
28372837

28382838
assertNull(OneSignal.getPermissionSubscriptionState());

0 commit comments

Comments
 (0)