7
7
import com .onesignal .OSEmailSubscriptionObserver ;
8
8
import com .onesignal .OSEmailSubscriptionStateChanges ;
9
9
import com .onesignal .OSInAppMessageAction ;
10
+ import com .onesignal .OSInAppMessage ;
11
+ import com .onesignal .OSInAppMessageLifecycleHandler ;
10
12
import com .onesignal .OSNotification ;
11
13
import com .onesignal .OSNotificationOpenedResult ;
12
14
import com .onesignal .OSNotificationReceivedEvent ;
@@ -57,6 +59,12 @@ public class OneSignalPlugin
57
59
private boolean hasSetRequiresPrivacyConsent = false ;
58
60
private boolean waitingForUserPrivacyConsent = false ;
59
61
62
+ private OSInAppMessage inAppMessage ;
63
+ private boolean hasSetOnWillDisplayInAppMessageHandler = false ;
64
+ private boolean hasSetOnDidDisplayInAppMessageHandler = false ;
65
+ private boolean hasSetOnWillDismissInAppMessageHandler = false ;
66
+ private boolean hasSetOnDidDismissInAppMessageHandler = false ;
67
+
60
68
private final HashMap <String , OSNotificationReceivedEvent > notificationReceivedEventCache = new HashMap <>();
61
69
62
70
public OneSignalPlugin () {
@@ -160,6 +168,14 @@ else if (call.method.contentEquals("OneSignal#initNotificationOpenedHandlerParam
160
168
this .initNotificationOpenedHandlerParams ();
161
169
else if (call .method .contentEquals ("OneSignal#initInAppMessageClickedHandlerParams" ))
162
170
this .initInAppMessageClickedHandlerParams ();
171
+ else if (call .method .contentEquals ("OneSignal#onWillDisplayInAppMessageHandlerParams" ))
172
+ this .OnWillDisplayInAppMessageHandlerParams ();
173
+ else if (call .method .contentEquals ("OneSignal#onDidDisplayInAppMessageHandlerParams" ))
174
+ this .OnWillDisplayInAppMessageHandlerParams ();
175
+ else if (call .method .contentEquals ("OneSignal#onWillDismissInAppMessageHandlerParams" ))
176
+ this .OnWillDisplayInAppMessageHandlerParams ();
177
+ else if (call .method .contentEquals ("OneSignal#onDidDismissInAppMessageHandlerParams" ))
178
+ this .OnWillDisplayInAppMessageHandlerParams ();
163
179
else if (call .method .contentEquals ("OneSignal#initNotificationWillShowInForegroundHandlerParams" ))
164
180
this .initNotificationWillShowInForegroundHandlerParams ();
165
181
else if (call .method .contentEquals ("OneSignal#completeNotification" ))
@@ -183,6 +199,7 @@ private void setAppId(MethodCall call, Result reply) {
183
199
OneSignal .setInAppMessageClickHandler (this );
184
200
OneSignal .initWithContext (context );
185
201
OneSignal .setAppId (appId );
202
+ setInAppMessageLifecycleHandler ();
186
203
187
204
if (hasSetRequiresPrivacyConsent && !OneSignal .userProvidedPrivacyConsent ())
188
205
this .waitingForUserPrivacyConsent = true ;
@@ -409,6 +426,99 @@ public void inAppMessageClicked(OSInAppMessageAction action) {
409
426
invokeMethodOnUiThread ("OneSignal#handleClickedInAppMessage" , OneSignalSerializer .convertInAppMessageClickedActionToMap (action ));
410
427
}
411
428
429
+ /* in app message lifecycle */
430
+ private void OnWillDisplayInAppMessageHandlerParams () {
431
+ this .hasSetOnWillDisplayInAppMessageHandler = true ;
432
+ if (this .inAppMessage != null ) {
433
+ this .onWillDisplayInAppMessageFlutter (this .inAppMessage );
434
+ this .inAppMessage = null ;
435
+ }
436
+ }
437
+
438
+ private void OnDidDisplayInAppMessageHandlerParams () {
439
+ this .hasSetOnDidDisplayInAppMessageHandler = true ;
440
+ if (this .inAppMessage != null ) {
441
+ this .onDidDisplayInAppMessageFlutter (this .inAppMessage );
442
+ this .inAppMessage = null ;
443
+ }
444
+ }
445
+
446
+ private void OnWillDismissInAppMessageHandlerParams () {
447
+ this .hasSetOnWillDismissInAppMessageHandler = true ;
448
+ if (this .inAppMessage != null ) {
449
+ this .onWillDismissInAppMessageFlutter (this .inAppMessage );
450
+ this .inAppMessage = null ;
451
+ }
452
+ }
453
+
454
+ private void OnDidDismissInAppMessageHandlerParams () {
455
+ this .hasSetOnDidDismissInAppMessageHandler = true ;
456
+ if (this .inAppMessage != null ) {
457
+ this .onDidDismissInAppMessageFlutter (this .inAppMessage );
458
+ this .inAppMessage = null ;
459
+ }
460
+ }
461
+
462
+ public void setInAppMessageLifecycleHandler () {
463
+ OneSignal .setInAppMessageLifecycleHandler (new OSInAppMessageLifecycleHandler () {
464
+ @ Override
465
+ public void onWillDisplayInAppMessage (OSInAppMessage message ) {
466
+ onWillDisplayInAppMessageFlutter (message );
467
+ }
468
+
469
+ @ Override
470
+ public void onDidDisplayInAppMessage (OSInAppMessage message ) {
471
+ onDidDisplayInAppMessageFlutter (message );
472
+ }
473
+
474
+ @ Override
475
+ public void onWillDismissInAppMessage (OSInAppMessage message ) {
476
+ onWillDismissInAppMessageFlutter (message );
477
+ }
478
+
479
+ @ Override
480
+ public void onDidDismissInAppMessage (OSInAppMessage message ) {
481
+ onDidDismissInAppMessageFlutter (message );
482
+ }
483
+ });
484
+ }
485
+
486
+ public void onWillDisplayInAppMessageFlutter (OSInAppMessage message ) {
487
+ if (!this .hasSetOnWillDisplayInAppMessageHandler ) {
488
+ this .inAppMessage = message ;
489
+ return ;
490
+ }
491
+
492
+ invokeMethodOnUiThread ("OneSignal#onWillDisplayInAppMessage" , OneSignalSerializer .convertInAppMessageToMap (message ));
493
+ }
494
+
495
+ public void onDidDisplayInAppMessageFlutter (OSInAppMessage message ) {
496
+ if (!this .hasSetOnDidDisplayInAppMessageHandler ) {
497
+ this .inAppMessage = message ;
498
+ return ;
499
+ }
500
+
501
+ invokeMethodOnUiThread ("OneSignal#onDidDisplayInAppMessage" , OneSignalSerializer .convertInAppMessageToMap (message ));
502
+ }
503
+
504
+ public void onWillDismissInAppMessageFlutter (OSInAppMessage message ) {
505
+ if (!this .hasSetOnWillDismissInAppMessageHandler ) {
506
+ this .inAppMessage = message ;
507
+ return ;
508
+ }
509
+
510
+ invokeMethodOnUiThread ("OneSignal#onWillDismissInAppMessage" , OneSignalSerializer .convertInAppMessageToMap (message ));
511
+ }
512
+
513
+ public void onDidDismissInAppMessageFlutter (OSInAppMessage message ) {
514
+ if (!this .hasSetOnDidDismissInAppMessageHandler ) {
515
+ this .inAppMessage = message ;
516
+ return ;
517
+ }
518
+
519
+ invokeMethodOnUiThread ("OneSignal#onDidDismissInAppMessage" , OneSignalSerializer .convertInAppMessageToMap (message ));
520
+ }
521
+
412
522
@ Override
413
523
public void notificationWillShowInForeground (OSNotificationReceivedEvent notificationReceivedEvent ) {
414
524
if (!this .hasSetNotificationWillShowInForegroundHandler ) {
0 commit comments