@@ -396,23 +396,19 @@ public void notificationWillShowInForeground(OSNotificationReceivedEvent notific
396
396
}
397
397
}
398
398
399
- static class OSFlutterEmailHandle extends FlutterRegistrarResponder
399
+ static class OSFlutterEmailHandle extends OSFlutterHandler
400
400
implements OneSignal .EmailUpdateHandler {
401
- private final Result result ;
402
- private final String methodName ;
403
- private final AtomicBoolean replySubmitted = new AtomicBoolean (false );
404
401
405
402
OSFlutterEmailHandle (PluginRegistry .Registrar flutterRegistrar , MethodChannel channel , Result res , String methodName ) {
406
- this .flutterRegistrar = flutterRegistrar ;
407
- this .channel = channel ;
408
- this .result = res ;
409
- this .methodName = methodName ;
403
+ super (flutterRegistrar , channel , res , methodName );
410
404
}
411
405
412
406
@ Override
413
407
public void onSuccess () {
414
- if (this .replySubmitted .getAndSet (true ))
415
- return ;
408
+ if (this .replySubmitted .getAndSet (true )) {
409
+ OneSignal .onesignalLog (OneSignal .LOG_LEVEL .DEBUG , "OneSignal " + methodName + " handler called twice, ignoring!" );
410
+ return ;
411
+ }
416
412
417
413
replySuccess (result , null );
418
414
}
@@ -428,23 +424,19 @@ public void onFailure(EmailUpdateError error) {
428
424
}
429
425
}
430
426
431
- static class OSFlutterSMSHandler extends FlutterRegistrarResponder
427
+ static class OSFlutterSMSHandler extends OSFlutterHandler
432
428
implements OneSignal .OSSMSUpdateHandler {
433
- private final Result result ;
434
- private final String methodName ;
435
- private final AtomicBoolean replySubmitted = new AtomicBoolean (false );
436
429
437
430
OSFlutterSMSHandler (PluginRegistry .Registrar flutterRegistrar , MethodChannel channel , Result res , String methodName ) {
438
- this .flutterRegistrar = flutterRegistrar ;
439
- this .channel = channel ;
440
- this .result = res ;
441
- this .methodName = methodName ;
431
+ super (flutterRegistrar , channel , res , methodName );
442
432
}
443
433
444
434
@ Override
445
435
public void onSuccess (JSONObject results ) {
446
- if (this .replySubmitted .getAndSet (true ))
436
+ if (this .replySubmitted .getAndSet (true )) {
437
+ OneSignal .onesignalLog (OneSignal .LOG_LEVEL .DEBUG , "OneSignal " + methodName + " handler called twice, ignoring! response: " + results );
447
438
return ;
439
+ }
448
440
449
441
try {
450
442
replySuccess (result , OneSignalSerializer .convertJSONObjectToHashMap (results ));
@@ -462,23 +454,19 @@ public void onFailure(OneSignal.OSSMSUpdateError error) {
462
454
}
463
455
}
464
456
465
- static class OSFlutterExternalUserIdHandler extends FlutterRegistrarResponder
457
+ static class OSFlutterExternalUserIdHandler extends OSFlutterHandler
466
458
implements OneSignal .OSExternalUserIdUpdateCompletionHandler {
467
- private final Result result ;
468
- private final String methodName ;
469
- private final AtomicBoolean replySubmitted = new AtomicBoolean (false );
470
459
471
460
OSFlutterExternalUserIdHandler (PluginRegistry .Registrar flutterRegistrar , MethodChannel channel , Result res , String methodName ) {
472
- this .flutterRegistrar = flutterRegistrar ;
473
- this .channel = channel ;
474
- this .result = res ;
475
- this .methodName = methodName ;
461
+ super (flutterRegistrar , channel , res , methodName );
476
462
}
477
463
478
464
@ Override
479
465
public void onSuccess (JSONObject results ) {
480
- if (this .replySubmitted .getAndSet (true ))
466
+ if (this .replySubmitted .getAndSet (true )) {
467
+ OneSignal .onesignalLog (OneSignal .LOG_LEVEL .DEBUG , "OneSignal " + methodName + " handler called twice, ignoring! response: " + results );
481
468
return ;
469
+ }
482
470
483
471
try {
484
472
replySuccess (result , OneSignalSerializer .convertJSONObjectToHashMap (results ));
@@ -496,23 +484,19 @@ public void onFailure(OneSignal.ExternalIdError error) {
496
484
}
497
485
}
498
486
499
- static class OSFlutterPostNotificationHandler extends FlutterRegistrarResponder
487
+ static class OSFlutterPostNotificationHandler extends OSFlutterHandler
500
488
implements OneSignal .PostNotificationResponseHandler {
501
- private final Result result ;
502
- private final String methodName ;
503
- private final AtomicBoolean replySubmitted = new AtomicBoolean (false );
504
489
505
490
OSFlutterPostNotificationHandler (PluginRegistry .Registrar flutterRegistrar , MethodChannel channel , Result res , String methodName ) {
506
- this .flutterRegistrar = flutterRegistrar ;
507
- this .channel = channel ;
508
- this .result = res ;
509
- this .methodName = methodName ;
491
+ super (flutterRegistrar , channel , res , methodName );
510
492
}
511
493
512
494
@ Override
513
495
public void onSuccess (JSONObject results ) {
514
- if (this .replySubmitted .getAndSet (true ))
515
- return ;
496
+ if (this .replySubmitted .getAndSet (true )) {
497
+ OneSignal .onesignalLog (OneSignal .LOG_LEVEL .DEBUG , "OneSignal " + methodName + " handler called twice, ignoring! response: " + results );
498
+ return ;
499
+ }
516
500
517
501
try {
518
502
replySuccess (result , OneSignalSerializer .convertJSONObjectToHashMap (results ));
@@ -523,8 +507,10 @@ public void onSuccess(JSONObject results) {
523
507
524
508
@ Override
525
509
public void onFailure (JSONObject response ) {
526
- if (this .replySubmitted .getAndSet (true ))
527
- return ;
510
+ if (this .replySubmitted .getAndSet (true )) {
511
+ OneSignal .onesignalLog (OneSignal .LOG_LEVEL .DEBUG , "OneSignal " + methodName + " handler called twice, ignoring! response: " + response );
512
+ return ;
513
+ }
528
514
529
515
try {
530
516
replyError (result , "OneSignal" , "Encountered an error attempting to " + methodName + " " + response .toString (), OneSignalSerializer .convertJSONObjectToHashMap (response ));
@@ -534,4 +520,16 @@ public void onFailure(JSONObject response) {
534
520
}
535
521
}
536
522
523
+ static class OSFlutterHandler extends FlutterRegistrarResponder {
524
+ protected final Result result ;
525
+ protected final String methodName ;
526
+ protected final AtomicBoolean replySubmitted = new AtomicBoolean (false );
527
+
528
+ OSFlutterHandler (PluginRegistry .Registrar flutterRegistrar , MethodChannel channel , Result res , String methodName ) {
529
+ this .flutterRegistrar = flutterRegistrar ;
530
+ this .channel = channel ;
531
+ this .result = res ;
532
+ this .methodName = methodName ;
533
+ }
534
+ }
537
535
}
0 commit comments