react-native-applovin-max 4.1.7 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -44,8 +44,8 @@ import com.applovin.sdk.AppLovinSdkConfiguration;
44
44
  import com.applovin.sdk.AppLovinSdkSettings;
45
45
  import com.applovin.sdk.AppLovinSdkUtils;
46
46
  import com.facebook.react.bridge.Arguments;
47
- import com.facebook.react.bridge.Callback;
48
47
  import com.facebook.react.bridge.LifecycleEventListener;
48
+ import com.facebook.react.bridge.Promise;
49
49
  import com.facebook.react.bridge.ReactApplicationContext;
50
50
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
51
51
  import com.facebook.react.bridge.ReactMethod;
@@ -79,6 +79,55 @@ public class AppLovinMAXModule
79
79
  private static final String SDK_TAG = "AppLovinSdk";
80
80
  private static final String TAG = "AppLovinMAXModule";
81
81
 
82
+ private static final String ON_BANNER_AD_LOADED_EVENT = "OnBannerAdLoadedEvent";
83
+ private static final String ON_BANNER_AD_LOAD_FAILED_EVENT = "OnBannerAdLoadFailedEvent";
84
+ private static final String ON_BANNER_AD_CLICKED_EVENT = "OnBannerAdClickedEvent";
85
+ private static final String ON_BANNER_AD_COLLAPSED_EVENT = "OnBannerAdCollapsedEvent";
86
+ private static final String ON_BANNER_AD_EXPANDED_EVENT = "OnBannerAdExpandedEvent";
87
+ private static final String ON_BANNER_AD_REVENUE_PAID = "OnBannerAdRevenuePaid";
88
+
89
+ private static final String ON_MREC_AD_LOADED_EVENT = "OnMRecAdLoadedEvent";
90
+ private static final String ON_MREC_AD_LOAD_FAILED_EVENT = "OnMRecAdLoadFailedEvent";
91
+ private static final String ON_MREC_AD_CLICKED_EVENT = "OnMRecAdClickedEvent";
92
+ private static final String ON_MREC_AD_COLLAPSED_EVENT = "OnMRecAdCollapsedEvent";
93
+ private static final String ON_MREC_AD_EXPANDED_EVENT = "OnMRecAdExpandedEvent";
94
+ private static final String ON_MREC_AD_REVENUE_PAID = "OnMRecAdRevenuePaid";
95
+
96
+ private static final String ON_INTERSTITIAL_LOADED_EVENT = "OnInterstitialLoadedEvent";
97
+ private static final String ON_INTERSTITIAL_LOAD_FAILED_EVENT = "OnInterstitialLoadFailedEvent";
98
+ private static final String ON_INTERSTITIAL_CLICKED_EVENT = "OnInterstitialClickedEvent";
99
+ private static final String ON_INTERSTITIAL_DISPLAYED_EVENT = "OnInterstitialDisplayedEvent";
100
+ private static final String ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT = "OnInterstitialAdFailedToDisplayEvent";
101
+ private static final String ON_INTERSTITIAL_HIDDEN_EVENT = "OnInterstitialHiddenEvent";
102
+ private static final String ON_INTERSTITIAL_AD_REVENUE_PAID = "OnInterstitialAdRevenuePaid";
103
+
104
+ private static final String ON_REWARDED_AD_LOADED_EVENT = "OnRewardedAdLoadedEvent";
105
+ private static final String ON_REWARDED_AD_LOAD_FAILED_EVENT = "OnRewardedAdLoadFailedEvent";
106
+ private static final String ON_REWARDED_AD_CLICKED_EVENT = "OnRewardedAdClickedEvent";
107
+ private static final String ON_REWARDED_AD_DISPLAYED_EVENT = "OnRewardedAdDisplayedEvent";
108
+ private static final String ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT = "OnRewardedAdFailedToDisplayEvent";
109
+ private static final String ON_REWARDED_AD_HIDDEN_EVENT = "OnRewardedAdHiddenEvent";
110
+ private static final String ON_REWARDED_AD_RECEIVED_REWARD_EVENT = "OnRewardedAdReceivedRewardEvent";
111
+ private static final String ON_REWARDED_AD_REVENUE_PAID = "OnRewardedAdRevenuePaid";
112
+
113
+ private static final String ON_APPOPEN_AD_LOADED_EVENT = "OnAppOpenAdLoadedEvent";
114
+ private static final String ON_APPOPEN_AD_LOAD_FAILED_EVENT = "OnAppOpenAdLoadFailedEvent";
115
+ private static final String ON_APPOPEN_AD_CLICKED_EVENT = "OnAppOpenAdClickedEvent";
116
+ private static final String ON_APPOPEN_AD_DISPLAYED_EVENT = "OnAppOpenAdDisplayedEvent";
117
+ private static final String ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT = "OnAppOpenAdFailedToDisplayEvent";
118
+ private static final String ON_APPOPEN_AD_HIDDEN_EVENT = "OnAppOpenAdHiddenEvent";
119
+ private static final String ON_APPOPEN_AD_REVENUE_PAID = "OnAppOpenAdRevenuePaid";
120
+
121
+ private static final String TOP_CENTER = "top_center";
122
+ private static final String TOP_LEFT = "top_left";
123
+ private static final String TOP_RIGHT = "top_right";
124
+ private static final String CENTERED = "centered";
125
+ private static final String CENTER_LEFT = "center_left";
126
+ private static final String CENTER_RIGHT = "center_right";
127
+ private static final String BOTTOM_LEFT = "bottom_left";
128
+ private static final String BOTTOM_CENTER = "bottom_center";
129
+ private static final String BOTTOM_RIGHT = "bottom_right";
130
+
82
131
  private static final Point DEFAULT_AD_VIEW_OFFSET = new Point( 0, 0 );
83
132
 
84
133
  public static AppLovinMAXModule instance;
@@ -101,13 +150,13 @@ public class AppLovinMAXModule
101
150
  private Boolean locationCollectionEnabledToSet;
102
151
  private final Map<String, String> extraParametersToSet = new HashMap<>( 8 );
103
152
 
104
- private Integer targetingYearOfBirthToSet;
105
- private String targetingGenderToSet;
106
- private Integer targetingMaximumAdContentRatingToSet;
107
- private String targetingEmailToSet;
108
- private String targetingPhoneNumberToSet;
109
- private ReadableArray targetingKeywordsToSet;
110
- private ReadableArray targetingInterestsToSet;
153
+ private Integer targetingYearOfBirthToSet;
154
+ private String targetingGenderToSet;
155
+ private Integer targetingMaximumAdContentRatingToSet;
156
+ private String targetingEmailToSet;
157
+ private String targetingPhoneNumberToSet;
158
+ private List targetingKeywordsToSet;
159
+ private List targetingInterestsToSet;
111
160
 
112
161
  // Fullscreen Ad Fields
113
162
  private final Map<String, MaxInterstitialAd> mInterstitials = new HashMap<>( 2 );
@@ -166,20 +215,20 @@ public class AppLovinMAXModule
166
215
  return sCurrentActivity;
167
216
  }
168
217
 
169
- @ReactMethod(isBlockingSynchronousMethod = true)
170
- public boolean isInitialized()
218
+ @ReactMethod
219
+ public void isInitialized(final Promise promise)
171
220
  {
172
- return isPluginInitialized && isSdkInitialized;
221
+ promise.resolve( isPluginInitialized && isSdkInitialized );
173
222
  }
174
223
 
175
224
  @ReactMethod
176
- public void initialize(final String pluginVersion, final String sdkKey, final Callback callback)
225
+ public void initialize(final String pluginVersion, final String sdkKey, final Promise promise)
177
226
  {
178
227
  // Check if Activity is available
179
228
  Activity currentActivity = maybeGetCurrentActivity();
180
229
  if ( currentActivity != null )
181
230
  {
182
- performInitialization( pluginVersion, sdkKey, currentActivity, callback );
231
+ performInitialization( pluginVersion, sdkKey, currentActivity, promise );
183
232
  }
184
233
  else
185
234
  {
@@ -197,13 +246,13 @@ public class AppLovinMAXModule
197
246
  contextToUse = getReactApplicationContext();
198
247
  }
199
248
 
200
- performInitialization( pluginVersion, sdkKey, contextToUse, callback );
249
+ performInitialization( pluginVersion, sdkKey, contextToUse, promise );
201
250
  }
202
251
  }, TimeUnit.SECONDS.toMillis( 3 ) );
203
252
  }
204
253
  }
205
254
 
206
- private void performInitialization(final String pluginVersion, final String sdkKey, final Context context, final Callback callback)
255
+ private void performInitialization(final String pluginVersion, final String sdkKey, final Context context, final Promise promise)
207
256
  {
208
257
  // Guard against running init logic multiple times
209
258
  if ( isPluginInitialized ) return;
@@ -232,7 +281,8 @@ public class AppLovinMAXModule
232
281
 
233
282
  if ( TextUtils.isEmpty( sdkKeyToUse ) )
234
283
  {
235
- throw new IllegalStateException( "Unable to initialize AppLovin SDK - no SDK key provided and not found in Android Manifest!" );
284
+ promise.reject( new IllegalStateException( "Unable to initialize AppLovin SDK - no SDK key provided and not found in Android Manifest!" ) );
285
+ return;
236
286
  }
237
287
  }
238
288
 
@@ -308,13 +358,13 @@ public class AppLovinMAXModule
308
358
 
309
359
  if ( targetingKeywordsToSet != null )
310
360
  {
311
- sdk.getTargetingData().setKeywords( getStringArrayList( targetingKeywordsToSet ) );
361
+ sdk.getTargetingData().setKeywords( targetingKeywordsToSet );
312
362
  targetingKeywordsToSet = null;
313
363
  }
314
364
 
315
365
  if ( targetingInterestsToSet != null )
316
366
  {
317
- sdk.getTargetingData().setInterests( getStringArrayList( targetingInterestsToSet ) );
367
+ sdk.getTargetingData().setInterests( targetingInterestsToSet );
318
368
  targetingInterestsToSet = null;
319
369
  }
320
370
 
@@ -353,20 +403,19 @@ public class AppLovinMAXModule
353
403
  }.enable();
354
404
 
355
405
  WritableMap sdkConfiguration = Arguments.createMap();
356
- sdkConfiguration.putInt( "consentDialogState", configuration.getConsentDialogState().ordinal() );
357
406
  sdkConfiguration.putString( "countryCode", configuration.getCountryCode() );
358
- callback.invoke( sdkConfiguration );
407
+ promise.resolve( sdkConfiguration );
359
408
  }
360
409
  } );
361
410
  }
362
411
 
363
412
  // General Public API
364
413
 
365
- @ReactMethod(isBlockingSynchronousMethod = true)
366
- public boolean isTablet()
414
+ @ReactMethod
415
+ public void isTablet(final Promise promise)
367
416
  {
368
417
  Context contextToUse = ( maybeGetCurrentActivity() != null ) ? maybeGetCurrentActivity() : getReactApplicationContext();
369
- return AppLovinSdkUtils.isTablet( contextToUse );
418
+ promise.resolve( AppLovinSdkUtils.isTablet( contextToUse ) );
370
419
  }
371
420
 
372
421
  @ReactMethod
@@ -381,51 +430,43 @@ public class AppLovinMAXModule
381
430
  sdk.showMediationDebugger();
382
431
  }
383
432
 
384
- @ReactMethod(isBlockingSynchronousMethod = true)
385
- public int getConsentDialogState()
386
- {
387
- if ( !isInitialized() ) return AppLovinSdkConfiguration.ConsentDialogState.UNKNOWN.ordinal();
388
-
389
- return sdkConfiguration.getConsentDialogState().ordinal();
390
- }
391
-
392
- @ReactMethod()
393
- public void setHasUserConsent(boolean hasUserConsent)
433
+ @ReactMethod
434
+ public void setHasUserConsent(final boolean hasUserConsent)
394
435
  {
395
436
  AppLovinPrivacySettings.setHasUserConsent( hasUserConsent, maybeGetCurrentActivity() );
396
437
  }
397
438
 
398
- @ReactMethod(isBlockingSynchronousMethod = true)
399
- public boolean hasUserConsent()
439
+ @ReactMethod
440
+ public void hasUserConsent(final Promise promise)
400
441
  {
401
- return AppLovinPrivacySettings.hasUserConsent( maybeGetCurrentActivity() );
442
+ promise.resolve( AppLovinPrivacySettings.hasUserConsent( maybeGetCurrentActivity() ) );
402
443
  }
403
444
 
404
- @ReactMethod()
405
- public void setIsAgeRestrictedUser(boolean isAgeRestrictedUser)
445
+ @ReactMethod
446
+ public void setIsAgeRestrictedUser(final boolean isAgeRestrictedUser)
406
447
  {
407
448
  AppLovinPrivacySettings.setIsAgeRestrictedUser( isAgeRestrictedUser, maybeGetCurrentActivity() );
408
449
  }
409
450
 
410
- @ReactMethod(isBlockingSynchronousMethod = true)
411
- public boolean isAgeRestrictedUser()
451
+ @ReactMethod
452
+ public void isAgeRestrictedUser(final Promise promise)
412
453
  {
413
- return AppLovinPrivacySettings.isAgeRestrictedUser( maybeGetCurrentActivity() );
454
+ promise.resolve( AppLovinPrivacySettings.isAgeRestrictedUser( maybeGetCurrentActivity() ) );
414
455
  }
415
456
 
416
- @ReactMethod()
457
+ @ReactMethod
417
458
  public void setDoNotSell(final boolean doNotSell)
418
459
  {
419
460
  AppLovinPrivacySettings.setDoNotSell( doNotSell, maybeGetCurrentActivity() );
420
461
  }
421
462
 
422
- @ReactMethod(isBlockingSynchronousMethod = true)
423
- public boolean isDoNotSell()
463
+ @ReactMethod
464
+ public void isDoNotSell(final Promise promise)
424
465
  {
425
- return AppLovinPrivacySettings.isDoNotSell( maybeGetCurrentActivity() );
466
+ promise.resolve( AppLovinPrivacySettings.isDoNotSell( maybeGetCurrentActivity() ) );
426
467
  }
427
468
 
428
- @ReactMethod()
469
+ @ReactMethod
429
470
  public void setUserId(String userId)
430
471
  {
431
472
  if ( isPluginInitialized )
@@ -439,7 +480,7 @@ public class AppLovinMAXModule
439
480
  }
440
481
  }
441
482
 
442
- @ReactMethod()
483
+ @ReactMethod
443
484
  public void setMuted(final boolean muted)
444
485
  {
445
486
  if ( !isPluginInitialized ) return;
@@ -447,15 +488,13 @@ public class AppLovinMAXModule
447
488
  sdk.getSettings().setMuted( muted );
448
489
  }
449
490
 
450
- @ReactMethod(isBlockingSynchronousMethod = true)
451
- public boolean isMuted()
491
+ @ReactMethod
492
+ public void isMuted(final Promise promise)
452
493
  {
453
- if ( !isPluginInitialized ) return false;
454
-
455
- return sdk.getSettings().isMuted();
494
+ promise.resolve( isPluginInitialized ? sdk.getSettings().isMuted() : false );
456
495
  }
457
496
 
458
- @ReactMethod()
497
+ @ReactMethod
459
498
  public void setVerboseLogging(final boolean enabled)
460
499
  {
461
500
  if ( isPluginInitialized )
@@ -469,7 +508,7 @@ public class AppLovinMAXModule
469
508
  }
470
509
  }
471
510
 
472
- @ReactMethod()
511
+ @ReactMethod
473
512
  public void setCreativeDebuggerEnabled(final boolean enabled)
474
513
  {
475
514
  if ( isPluginInitialized )
@@ -483,7 +522,7 @@ public class AppLovinMAXModule
483
522
  }
484
523
  }
485
524
 
486
- @ReactMethod()
525
+ @ReactMethod
487
526
  public void setTestDeviceAdvertisingIds(final ReadableArray rawAdvertisingIds)
488
527
  {
489
528
  List<String> advertisingIds = new ArrayList<>( rawAdvertisingIds.size() );
@@ -505,7 +544,7 @@ public class AppLovinMAXModule
505
544
  }
506
545
  }
507
546
 
508
- @ReactMethod()
547
+ @ReactMethod
509
548
  public void setExtraParameter(final String key, @Nullable final String value)
510
549
  {
511
550
  if ( TextUtils.isEmpty( key ) )
@@ -526,18 +565,18 @@ public class AppLovinMAXModule
526
565
  }
527
566
  }
528
567
 
529
- @ReactMethod()
568
+ @ReactMethod
530
569
  public void setConsentFlowEnabled(final boolean enabled) { }
531
570
 
532
- @ReactMethod()
571
+ @ReactMethod
533
572
  public void setPrivacyPolicyUrl(final String urlString) { }
534
573
 
535
- @ReactMethod()
574
+ @ReactMethod
536
575
  public void setTermsOfServiceUrl(final String urlString) { }
537
576
 
538
577
  // Data Passing
539
578
 
540
- @ReactMethod()
579
+ @ReactMethod
541
580
  public void setTargetingDataYearOfBirth(final int yearOfBirth)
542
581
  {
543
582
  if ( sdk == null )
@@ -549,7 +588,20 @@ public class AppLovinMAXModule
549
588
  sdk.getTargetingData().setYearOfBirth( yearOfBirth <= 0 ? null : yearOfBirth );
550
589
  }
551
590
 
552
- @ReactMethod()
591
+ @ReactMethod
592
+ public void getTargetingDataYearOfBirth(final Promise promise)
593
+ {
594
+ if ( sdk == null )
595
+ {
596
+ promise.resolve( targetingYearOfBirthToSet == null ? 0 : targetingYearOfBirthToSet );
597
+ return;
598
+ }
599
+
600
+ Integer yearOfBirth = sdk.getTargetingData().getYearOfBirth();
601
+ promise.resolve( yearOfBirth != null ? yearOfBirth : 0 );
602
+ }
603
+
604
+ @ReactMethod
553
605
  public void setTargetingDataGender(@Nullable final String gender)
554
606
  {
555
607
  if ( sdk == null )
@@ -561,7 +613,26 @@ public class AppLovinMAXModule
561
613
  sdk.getTargetingData().setGender( getAppLovinGender( gender ) );
562
614
  }
563
615
 
564
- @ReactMethod()
616
+ @ReactMethod
617
+ public void getTargetingDataGender(final Promise promise)
618
+ {
619
+ if ( sdk == null )
620
+ {
621
+ promise.resolve( targetingGenderToSet == null ? "U" : targetingGenderToSet );
622
+ return;
623
+ }
624
+
625
+ if ( sdk.getTargetingData().getGender() == null )
626
+ {
627
+ promise.resolve( "U" );
628
+ }
629
+ else
630
+ {
631
+ promise.resolve( getRawAppLovinGender( sdk.getTargetingData().getGender() ) );
632
+ }
633
+ }
634
+
635
+ @ReactMethod
565
636
  public void setTargetingDataMaximumAdContentRating(final int maximumAdContentRating)
566
637
  {
567
638
  if ( sdk == null )
@@ -573,7 +644,26 @@ public class AppLovinMAXModule
573
644
  sdk.getTargetingData().setMaximumAdContentRating( getAppLovinAdContentRating( maximumAdContentRating ) );
574
645
  }
575
646
 
576
- @ReactMethod()
647
+ @ReactMethod
648
+ public void getTargetingDataMaximumAdContentRating(final Promise promise)
649
+ {
650
+ if ( sdk == null )
651
+ {
652
+ promise.resolve( targetingMaximumAdContentRatingToSet == null ? 0 : targetingMaximumAdContentRatingToSet );
653
+ return;
654
+ }
655
+
656
+ if ( sdk.getTargetingData().getMaximumAdContentRating() == null )
657
+ {
658
+ promise.resolve( 0 );
659
+ }
660
+ else
661
+ {
662
+ promise.resolve( sdk.getTargetingData().getMaximumAdContentRating().ordinal() );
663
+ }
664
+ }
665
+
666
+ @ReactMethod
577
667
  public void setTargetingDataEmail(@Nullable final String email)
578
668
  {
579
669
  if ( sdk == null )
@@ -585,7 +675,19 @@ public class AppLovinMAXModule
585
675
  sdk.getTargetingData().setEmail( email );
586
676
  }
587
677
 
588
- @ReactMethod()
678
+ @ReactMethod
679
+ public void getTargetingDataEmail(final Promise promise)
680
+ {
681
+ if ( sdk == null )
682
+ {
683
+ promise.resolve( targetingEmailToSet );
684
+ return;
685
+ }
686
+
687
+ promise.resolve( sdk.getTargetingData().getEmail() );
688
+ }
689
+
690
+ @ReactMethod
589
691
  public void setTargetingDataPhoneNumber(@Nullable final String phoneNumber)
590
692
  {
591
693
  if ( sdk == null )
@@ -597,31 +699,99 @@ public class AppLovinMAXModule
597
699
  sdk.getTargetingData().setPhoneNumber( phoneNumber );
598
700
  }
599
701
 
600
- @ReactMethod()
702
+ @ReactMethod
703
+ public void getTargetingDataPhoneNumber(final Promise promise)
704
+ {
705
+ if ( sdk == null )
706
+ {
707
+ promise.resolve( targetingPhoneNumberToSet );
708
+ return;
709
+ }
710
+
711
+ promise.resolve( sdk.getTargetingData().getPhoneNumber() );
712
+ }
713
+
714
+ @ReactMethod
601
715
  public void setTargetingDataKeywords(@Nullable final ReadableArray rawKeywords)
602
716
  {
603
717
  if ( sdk == null )
604
718
  {
605
- targetingKeywordsToSet = rawKeywords;
719
+ targetingKeywordsToSet = Arguments.toList( rawKeywords );
606
720
  return;
607
721
  }
608
722
 
609
- sdk.getTargetingData().setKeywords( getStringArrayList( rawKeywords ) );
723
+ sdk.getTargetingData().setKeywords( Arguments.toList( rawKeywords ) );
610
724
  }
611
725
 
612
- @ReactMethod()
726
+ @ReactMethod
727
+ public void getTargetingDataKeywords(final Promise promise)
728
+ {
729
+ if ( sdk == null )
730
+ {
731
+ if ( targetingKeywordsToSet == null || targetingKeywordsToSet.size() == 0 )
732
+ {
733
+ promise.resolve( null );
734
+ }
735
+ else
736
+ {
737
+ promise.resolve( Arguments.fromList( targetingKeywordsToSet ) );
738
+ }
739
+ return;
740
+ }
741
+
742
+ List<String> keywords = sdk.getTargetingData().getKeywords();
743
+
744
+ if ( keywords == null || keywords.size() == 0 )
745
+ {
746
+ promise.resolve( null );
747
+ }
748
+ else
749
+ {
750
+ promise.resolve( Arguments.makeNativeArray( keywords ) );
751
+ }
752
+ }
753
+
754
+ @ReactMethod
613
755
  public void setTargetingDataInterests(@Nullable final ReadableArray rawInterests)
614
756
  {
615
757
  if ( sdk == null )
616
758
  {
617
- targetingInterestsToSet = rawInterests;
759
+ targetingKeywordsToSet = Arguments.toList( rawInterests );
760
+ return;
761
+ }
762
+
763
+ sdk.getTargetingData().setInterests( Arguments.toList( rawInterests ) );
764
+ }
765
+
766
+ @ReactMethod
767
+ public void getTargetingDataInterests(final Promise promise)
768
+ {
769
+ if ( sdk == null )
770
+ {
771
+ if ( targetingInterestsToSet == null || targetingInterestsToSet.size() == 0 )
772
+ {
773
+ promise.resolve( null );
774
+ }
775
+ else
776
+ {
777
+ promise.resolve( Arguments.fromList( targetingInterestsToSet ) );
778
+ }
618
779
  return;
619
780
  }
620
781
 
621
- sdk.getTargetingData().setInterests( getStringArrayList( rawInterests ) );
782
+ List<String> interests = sdk.getTargetingData().getInterests();
783
+
784
+ if ( interests == null || interests.size() == 0 )
785
+ {
786
+ promise.resolve( null );
787
+ }
788
+ else
789
+ {
790
+ promise.resolve( Arguments.makeNativeArray( interests ) );
791
+ }
622
792
  }
623
793
 
624
- @ReactMethod()
794
+ @ReactMethod
625
795
  public void clearAllTargetingData()
626
796
  {
627
797
  if ( sdk == null )
@@ -639,7 +809,7 @@ public class AppLovinMAXModule
639
809
  sdk.getTargetingData().clearAll();
640
810
  }
641
811
 
642
- @ReactMethod()
812
+ @ReactMethod
643
813
  public void setLocationCollectionEnabled(final boolean enabled)
644
814
  {
645
815
  if ( isPluginInitialized )
@@ -655,7 +825,7 @@ public class AppLovinMAXModule
655
825
 
656
826
  // EVENT TRACKING
657
827
 
658
- @ReactMethod()
828
+ @ReactMethod
659
829
  public void trackEvent(final String event, final ReadableMap parameters)
660
830
  {
661
831
  // Convert Map<String, Object> type of `parameters.toHashMap()` to Map<String, String>
@@ -674,254 +844,506 @@ public class AppLovinMAXModule
674
844
 
675
845
  // BANNERS
676
846
 
677
- @ReactMethod()
847
+ @ReactMethod
678
848
  public void createBanner(final String adUnitId, final String bannerPosition)
679
849
  {
850
+ if ( sdk == null )
851
+ {
852
+ logUninitializedAccessError( "createBanner" );
853
+ return;
854
+ }
855
+
680
856
  createAdView( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), bannerPosition, DEFAULT_AD_VIEW_OFFSET );
681
857
  }
682
858
 
683
- @ReactMethod() // NOTE: No function overloading in JS so we need new method signature
859
+ @ReactMethod // NOTE: No function overloading in JS so we need new method signature
684
860
  public void createBannerWithOffsets(final String adUnitId, final String bannerPosition, final float x, final float y)
685
861
  {
862
+ if ( sdk == null )
863
+ {
864
+ logUninitializedAccessError( "createBannerWithOffsets" );
865
+ return;
866
+ }
867
+
686
868
  createAdView( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), bannerPosition, getOffsetPixels( x, y, getCurrentActivity() ) );
687
869
  }
688
870
 
689
- @ReactMethod()
871
+ @ReactMethod
690
872
  public void setBannerBackgroundColor(final String adUnitId, final String hexColorCode)
691
873
  {
874
+ if ( sdk == null )
875
+ {
876
+ logUninitializedAccessError( "setBannerBackgroundColor" );
877
+ return;
878
+ }
879
+
692
880
  setAdViewBackgroundColor( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), hexColorCode );
693
881
  }
694
882
 
695
- @ReactMethod()
883
+ @ReactMethod
696
884
  public void setBannerPlacement(final String adUnitId, final String placement)
697
885
  {
886
+ if ( sdk == null )
887
+ {
888
+ logUninitializedAccessError( "setBannerPlacement" );
889
+ return;
890
+ }
891
+
698
892
  setAdViewPlacement( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), placement );
699
893
  }
700
894
 
701
- @ReactMethod()
895
+ @ReactMethod
702
896
  public void setBannerCustomData(final String adUnitId, final String customData)
703
897
  {
898
+ if ( sdk == null )
899
+ {
900
+ logUninitializedAccessError( "setBannerCustomData" );
901
+ return;
902
+ }
903
+
704
904
  setAdViewCustomData( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), customData );
705
905
  }
706
906
 
707
- @ReactMethod()
907
+ @ReactMethod
708
908
  public void setBannerWidth(final String adUnitId, final int widthDp)
709
909
  {
910
+ if ( sdk == null )
911
+ {
912
+ logUninitializedAccessError( "setBannerWidth" );
913
+ return;
914
+ }
915
+
710
916
  setAdViewWidth( adUnitId, widthDp, getDeviceSpecificBannerAdViewAdFormat() );
711
917
  }
712
918
 
713
- @ReactMethod()
919
+ @ReactMethod
714
920
  public void updateBannerPosition(final String adUnitId, final String bannerPosition)
715
921
  {
922
+ if ( sdk == null )
923
+ {
924
+ logUninitializedAccessError( "updateBannerPosition" );
925
+ return;
926
+ }
927
+
716
928
  updateAdViewPosition( adUnitId, bannerPosition, DEFAULT_AD_VIEW_OFFSET, getDeviceSpecificBannerAdViewAdFormat() );
717
929
  }
718
930
 
719
- @ReactMethod()
931
+ @ReactMethod
720
932
  public void updateBannerOffsets(final String adUnitId, final float x, final float y)
721
933
  {
934
+ if ( sdk == null )
935
+ {
936
+ logUninitializedAccessError( "updateBannerOffsets" );
937
+ return;
938
+ }
939
+
722
940
  updateAdViewPosition( adUnitId, mAdViewPositions.get( adUnitId ), getOffsetPixels( x, y, getCurrentActivity() ), getDeviceSpecificBannerAdViewAdFormat() );
723
941
  }
724
942
 
725
- @ReactMethod()
943
+ @ReactMethod
726
944
  public void setBannerExtraParameter(final String adUnitId, final String key, final String value)
727
945
  {
946
+ if ( sdk == null )
947
+ {
948
+ logUninitializedAccessError( "setBannerExtraParameter" );
949
+ return;
950
+ }
951
+
728
952
  setAdViewExtraParameters( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), key, value );
729
953
  }
730
954
 
731
- @ReactMethod()
955
+ @ReactMethod
956
+ public void setBannerLocalExtraParameter(final String adUnitId, final String key, final String value)
957
+ {
958
+ setAdViewLocalExtraParameters( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), key, value );
959
+ }
960
+
961
+ @ReactMethod
732
962
  public void startBannerAutoRefresh(final String adUnitId)
733
963
  {
964
+ if ( sdk == null )
965
+ {
966
+ logUninitializedAccessError( "startBannerAutoRefresh" );
967
+ return;
968
+ }
969
+
734
970
  startAutoRefresh( adUnitId, getDeviceSpecificBannerAdViewAdFormat() );
735
971
  }
736
972
 
737
- @ReactMethod()
973
+ @ReactMethod
738
974
  public void stopBannerAutoRefresh(final String adUnitId)
739
975
  {
976
+ if ( sdk == null )
977
+ {
978
+ logUninitializedAccessError( "stopBannerAutoRefresh" );
979
+ return;
980
+ }
981
+
740
982
  stopAutoRefresh( adUnitId, getDeviceSpecificBannerAdViewAdFormat() );
741
983
  }
742
984
 
743
- @ReactMethod()
985
+ @ReactMethod
744
986
  public void showBanner(final String adUnitId)
745
987
  {
988
+ if ( sdk == null )
989
+ {
990
+ logUninitializedAccessError( "showBanner" );
991
+ return;
992
+ }
993
+
746
994
  showAdView( adUnitId, getDeviceSpecificBannerAdViewAdFormat() );
747
995
  }
748
996
 
749
- @ReactMethod()
997
+ @ReactMethod
750
998
  public void hideBanner(final String adUnitId)
751
999
  {
1000
+ if ( sdk == null )
1001
+ {
1002
+ logUninitializedAccessError( "hideBanner" );
1003
+ return;
1004
+ }
1005
+
752
1006
  hideAdView( adUnitId, getDeviceSpecificBannerAdViewAdFormat() );
753
1007
  }
754
1008
 
755
- @ReactMethod()
1009
+ @ReactMethod
756
1010
  public void destroyBanner(final String adUnitId)
757
1011
  {
1012
+ if ( sdk == null )
1013
+ {
1014
+ logUninitializedAccessError( "destroyBanner" );
1015
+ return;
1016
+ }
1017
+
758
1018
  destroyAdView( adUnitId, getDeviceSpecificBannerAdViewAdFormat() );
759
1019
  }
760
1020
 
761
- @ReactMethod(isBlockingSynchronousMethod = true)
762
- public float getAdaptiveBannerHeightForWidth(final float width)
1021
+ @ReactMethod
1022
+ public void getAdaptiveBannerHeightForWidth(final float width, final Promise promise)
763
1023
  {
764
- return getDeviceSpecificBannerAdViewAdFormat().getAdaptiveSize( (int) width, getCurrentActivity() ).getHeight();
1024
+ promise.resolve( getDeviceSpecificBannerAdViewAdFormat().getAdaptiveSize( (int) width, getCurrentActivity() ).getHeight() );
765
1025
  }
766
1026
 
767
1027
  // MRECS
768
1028
 
769
- @ReactMethod()
1029
+ @ReactMethod
770
1030
  public void createMRec(final String adUnitId, final String mrecPosition)
771
1031
  {
1032
+ if ( sdk == null )
1033
+ {
1034
+ logUninitializedAccessError( "createMRec" );
1035
+ return;
1036
+ }
1037
+
772
1038
  createAdView( adUnitId, MaxAdFormat.MREC, mrecPosition, DEFAULT_AD_VIEW_OFFSET );
773
1039
  }
774
1040
 
775
- @ReactMethod()
1041
+ @ReactMethod
776
1042
  public void setMRecPlacement(final String adUnitId, final String placement)
777
1043
  {
1044
+ if ( sdk == null )
1045
+ {
1046
+ logUninitializedAccessError( "setMRecPlacement" );
1047
+ return;
1048
+ }
1049
+
778
1050
  setAdViewPlacement( adUnitId, MaxAdFormat.MREC, placement );
779
1051
  }
780
1052
 
781
- @ReactMethod()
1053
+ @ReactMethod
782
1054
  public void setMRecCustomData(final String adUnitId, final String customData)
783
1055
  {
1056
+ if ( sdk == null )
1057
+ {
1058
+ logUninitializedAccessError( "setMRecCustomData" );
1059
+ return;
1060
+ }
1061
+
784
1062
  setAdViewCustomData( adUnitId, MaxAdFormat.MREC, customData );
785
1063
  }
786
1064
 
787
- @ReactMethod()
1065
+ @ReactMethod
788
1066
  public void updateMRecPosition(final String adUnitId, final String mrecPosition)
789
1067
  {
1068
+ if ( sdk == null )
1069
+ {
1070
+ logUninitializedAccessError( "updateMRecPosition" );
1071
+ return;
1072
+ }
1073
+
790
1074
  updateAdViewPosition( adUnitId, mrecPosition, DEFAULT_AD_VIEW_OFFSET, MaxAdFormat.MREC );
791
1075
  }
792
1076
 
793
- @ReactMethod()
1077
+ @ReactMethod
1078
+ public void setMRecExtraParameter(final String adUnitId, final String key, final String value)
1079
+ {
1080
+ setAdViewExtraParameters( adUnitId, MaxAdFormat.MREC, key, value );
1081
+ }
1082
+
1083
+ @ReactMethod
1084
+ public void setMRecLocalExtraParameter(final String adUnitId, final String key, final String value)
1085
+ {
1086
+ setAdViewLocalExtraParameters( adUnitId, MaxAdFormat.MREC, key, value );
1087
+ }
1088
+
1089
+ @ReactMethod
794
1090
  public void startMRecAutoRefresh(final String adUnitId)
795
1091
  {
1092
+ if ( sdk == null )
1093
+ {
1094
+ logUninitializedAccessError( "startMRecAutoRefresh" );
1095
+ return;
1096
+ }
1097
+
796
1098
  startAutoRefresh( adUnitId, MaxAdFormat.MREC );
797
1099
  }
798
1100
 
799
- @ReactMethod()
1101
+ @ReactMethod
800
1102
  public void stopMRecAutoRefresh(final String adUnitId)
801
1103
  {
1104
+ if ( sdk == null )
1105
+ {
1106
+ logUninitializedAccessError( "stopMRecAutoRefresh" );
1107
+ return;
1108
+ }
1109
+
802
1110
  stopAutoRefresh( adUnitId, MaxAdFormat.MREC );
803
1111
  }
804
1112
 
805
- @ReactMethod()
1113
+ @ReactMethod
806
1114
  public void showMRec(final String adUnitId)
807
1115
  {
1116
+ if ( sdk == null )
1117
+ {
1118
+ logUninitializedAccessError( "showMRec" );
1119
+ return;
1120
+ }
1121
+
808
1122
  showAdView( adUnitId, MaxAdFormat.MREC );
809
1123
  }
810
1124
 
811
- @ReactMethod()
1125
+ @ReactMethod
812
1126
  public void hideMRec(final String adUnitId)
813
1127
  {
1128
+ if ( sdk == null )
1129
+ {
1130
+ logUninitializedAccessError( "hideMRec" );
1131
+ return;
1132
+ }
1133
+
814
1134
  hideAdView( adUnitId, MaxAdFormat.MREC );
815
1135
  }
816
1136
 
817
- @ReactMethod()
1137
+ @ReactMethod
818
1138
  public void destroyMRec(final String adUnitId)
819
1139
  {
1140
+ if ( sdk == null )
1141
+ {
1142
+ logUninitializedAccessError( "destroyMRec" );
1143
+ return;
1144
+ }
1145
+
820
1146
  destroyAdView( adUnitId, MaxAdFormat.MREC );
821
1147
  }
822
1148
 
823
1149
  // INTERSTITIALS
824
1150
 
825
- @ReactMethod()
1151
+ @ReactMethod
826
1152
  public void loadInterstitial(final String adUnitId)
827
1153
  {
1154
+ if ( sdk == null )
1155
+ {
1156
+ logUninitializedAccessError( "loadInterstitial" );
1157
+ return;
1158
+ }
1159
+
828
1160
  MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
829
1161
  if ( interstitial == null )
830
1162
  {
831
- sendReactNativeEventForAdLoadFailed( "OnInterstitialLoadFailedEvent", adUnitId, null );
1163
+ sendReactNativeEventForAdLoadFailed( ON_INTERSTITIAL_LOAD_FAILED_EVENT, adUnitId, null );
832
1164
  return;
833
1165
  }
834
1166
 
835
1167
  interstitial.loadAd();
836
1168
  }
837
1169
 
838
- @ReactMethod(isBlockingSynchronousMethod = true)
839
- public boolean isInterstitialReady(final String adUnitId)
1170
+ @ReactMethod
1171
+ public void isInterstitialReady(final String adUnitId, final Promise promise)
840
1172
  {
1173
+ if ( sdk == null )
1174
+ {
1175
+ logUninitializedAccessError( "isInterstitialReady" );
1176
+ promise.resolve( false );
1177
+ return;
1178
+ }
1179
+
841
1180
  MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
842
- return interstitial.isReady();
1181
+ promise.resolve( interstitial.isReady() );
843
1182
  }
844
1183
 
845
- @ReactMethod()
1184
+ @ReactMethod
846
1185
  public void showInterstitial(final String adUnitId, final String placement, final String customData)
847
1186
  {
1187
+ if ( sdk == null )
1188
+ {
1189
+ logUninitializedAccessError( "showInterstitial" );
1190
+ return;
1191
+ }
1192
+
848
1193
  MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
849
1194
  interstitial.showAd( placement, customData );
850
1195
  }
851
1196
 
852
- @ReactMethod()
1197
+ @ReactMethod
853
1198
  public void setInterstitialExtraParameter(final String adUnitId, final String key, final String value)
854
1199
  {
1200
+ if ( sdk == null )
1201
+ {
1202
+ logUninitializedAccessError( "setInterstitialExtraParameter" );
1203
+ return;
1204
+ }
1205
+
855
1206
  MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
856
1207
  interstitial.setExtraParameter( key, value );
857
1208
  }
858
1209
 
1210
+ @ReactMethod
1211
+ public void setInterstitialLocalExtraParameter(final String adUnitId, final String key, final String value)
1212
+ {
1213
+ MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
1214
+ interstitial.setLocalExtraParameter( key, value );
1215
+ }
1216
+
859
1217
  // REWARDED
860
1218
 
861
- @ReactMethod()
1219
+ @ReactMethod
862
1220
  public void loadRewardedAd(final String adUnitId)
863
1221
  {
1222
+ if ( sdk == null )
1223
+ {
1224
+ logUninitializedAccessError( "loadRewardedAd" );
1225
+ return;
1226
+ }
1227
+
864
1228
  MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
865
1229
  if ( rewardedAd == null )
866
1230
  {
867
- sendReactNativeEventForAdLoadFailed( "OnRewardedAdLoadFailedEvent", adUnitId, null );
1231
+ sendReactNativeEventForAdLoadFailed( ON_REWARDED_AD_LOAD_FAILED_EVENT, adUnitId, null );
868
1232
  return;
869
1233
  }
870
1234
 
871
1235
  rewardedAd.loadAd();
872
1236
  }
873
1237
 
874
- @ReactMethod(isBlockingSynchronousMethod = true)
875
- public boolean isRewardedAdReady(final String adUnitId)
1238
+ @ReactMethod
1239
+ public void isRewardedAdReady(final String adUnitId, final Promise promise)
876
1240
  {
1241
+ if ( sdk == null )
1242
+ {
1243
+ logUninitializedAccessError( "isRewardedAdReady" );
1244
+ promise.resolve( false );
1245
+ return;
1246
+ }
1247
+
877
1248
  MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
878
- return rewardedAd.isReady();
1249
+ promise.resolve( rewardedAd.isReady() );
879
1250
  }
880
1251
 
881
- @ReactMethod()
1252
+ @ReactMethod
882
1253
  public void showRewardedAd(final String adUnitId, final String placement, final String customData)
883
1254
  {
1255
+ if ( sdk == null )
1256
+ {
1257
+ logUninitializedAccessError( "showRewardedAd" );
1258
+ return;
1259
+ }
1260
+
884
1261
  MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
885
1262
  rewardedAd.showAd( placement, customData );
886
1263
  }
887
1264
 
888
- @ReactMethod()
1265
+ @ReactMethod
889
1266
  public void setRewardedAdExtraParameter(final String adUnitId, final String key, final String value)
890
1267
  {
1268
+ if ( sdk == null )
1269
+ {
1270
+ logUninitializedAccessError( "setRewardedAdExtraParameter" );
1271
+ return;
1272
+ }
1273
+
891
1274
  MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
892
1275
  rewardedAd.setExtraParameter( key, value );
893
1276
  }
894
1277
 
1278
+ @ReactMethod
1279
+ public void setRewardedAdLocalExtraParameter(final String adUnitId, final String key, final String value)
1280
+ {
1281
+ MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
1282
+ rewardedAd.setLocalExtraParameter( key, value );
1283
+ }
1284
+
895
1285
  // APP OPEN AD
896
1286
 
897
- @ReactMethod()
1287
+ @ReactMethod
898
1288
  public void loadAppOpenAd(final String adUnitId)
899
1289
  {
1290
+ if ( sdk == null )
1291
+ {
1292
+ logUninitializedAccessError( "loadAppOpenAd" );
1293
+ return;
1294
+ }
1295
+
900
1296
  MaxAppOpenAd appOpenAd = retrieveAppOpenAd( adUnitId );
901
1297
  appOpenAd.loadAd();
902
1298
  }
903
1299
 
904
- @ReactMethod(isBlockingSynchronousMethod = true)
905
- public boolean isAppOpenAdReady(final String adUnitId)
1300
+ @ReactMethod
1301
+ public void isAppOpenAdReady(final String adUnitId, final Promise promise)
906
1302
  {
1303
+ if ( sdk == null )
1304
+ {
1305
+ logUninitializedAccessError( "isAppOpenAdReady" );
1306
+ promise.resolve( false );
1307
+ return;
1308
+ }
1309
+
907
1310
  MaxAppOpenAd appOpenAd = retrieveAppOpenAd( adUnitId );
908
- return appOpenAd.isReady();
1311
+ promise.resolve( appOpenAd.isReady() );
909
1312
  }
910
1313
 
911
- @ReactMethod()
1314
+ @ReactMethod
912
1315
  public void showAppOpenAd(final String adUnitId, @Nullable final String placement, @Nullable final String customData)
913
1316
  {
1317
+ if ( sdk == null )
1318
+ {
1319
+ logUninitializedAccessError( "showAppOpenAd" );
1320
+ return;
1321
+ }
1322
+
914
1323
  MaxAppOpenAd appOpenAd = retrieveAppOpenAd( adUnitId );
915
1324
  appOpenAd.showAd( placement, customData );
916
1325
  }
917
1326
 
918
- @ReactMethod()
1327
+ @ReactMethod
919
1328
  public void setAppOpenAdExtraParameter(final String adUnitId, final String key, final String value)
920
1329
  {
1330
+ if ( sdk == null )
1331
+ {
1332
+ logUninitializedAccessError( "setAppOpenAdExtraParameter" );
1333
+ return;
1334
+ }
1335
+
921
1336
  MaxAppOpenAd appOpenAd = retrieveAppOpenAd( adUnitId );
922
1337
  appOpenAd.setExtraParameter( key, value );
923
1338
  }
924
1339
 
1340
+ @ReactMethod
1341
+ public void setAppOpenAdLocalExtraParameter(final String adUnitId, final String key, final String value)
1342
+ {
1343
+ MaxAppOpenAd appOpenAd = retrieveAppOpenAd( adUnitId );
1344
+ appOpenAd.setLocalExtraParameter( key, value );
1345
+ }
1346
+
925
1347
  // AD CALLBACKS
926
1348
 
927
1349
  @Override
@@ -931,7 +1353,7 @@ public class AppLovinMAXModule
931
1353
  MaxAdFormat adFormat = ad.getFormat();
932
1354
  if ( MaxAdFormat.BANNER == adFormat || MaxAdFormat.LEADER == adFormat || MaxAdFormat.MREC == adFormat )
933
1355
  {
934
- name = ( MaxAdFormat.MREC == adFormat ) ? "OnMRecAdLoadedEvent" : "OnBannerAdLoadedEvent";
1356
+ name = ( MaxAdFormat.MREC == adFormat ) ? ON_MREC_AD_LOADED_EVENT : ON_BANNER_AD_LOADED_EVENT;
935
1357
 
936
1358
  String adViewPosition = mAdViewPositions.get( ad.getAdUnitId() );
937
1359
  if ( !TextUtils.isEmpty( adViewPosition ) )
@@ -950,19 +1372,15 @@ public class AppLovinMAXModule
950
1372
  }
951
1373
  else if ( MaxAdFormat.INTERSTITIAL == adFormat )
952
1374
  {
953
- name = "OnInterstitialLoadedEvent";
1375
+ name = ON_INTERSTITIAL_LOADED_EVENT;
954
1376
  }
955
1377
  else if ( MaxAdFormat.REWARDED == adFormat )
956
1378
  {
957
- name = "OnRewardedAdLoadedEvent";
958
- }
959
- else if ( MaxAdFormat.NATIVE == adFormat )
960
- {
961
- name = "OnNativeAdLoadedEvent";
1379
+ name = ON_REWARDED_AD_LOADED_EVENT;
962
1380
  }
963
1381
  else if ( MaxAdFormat.APP_OPEN == adFormat )
964
1382
  {
965
- name = "OnAppOpenAdLoadedEvent";
1383
+ name = ON_APPOPEN_AD_LOADED_EVENT;
966
1384
  }
967
1385
  else
968
1386
  {
@@ -985,19 +1403,19 @@ public class AppLovinMAXModule
985
1403
  String name;
986
1404
  if ( mAdViews.containsKey( adUnitId ) )
987
1405
  {
988
- name = ( MaxAdFormat.MREC == mAdViewAdFormats.get( adUnitId ) ) ? "OnMRecAdLoadFailedEvent" : "OnBannerAdLoadFailedEvent";
1406
+ name = ( MaxAdFormat.MREC == mAdViewAdFormats.get( adUnitId ) ) ? ON_MREC_AD_LOAD_FAILED_EVENT : ON_BANNER_AD_LOAD_FAILED_EVENT;
989
1407
  }
990
1408
  else if ( mInterstitials.containsKey( adUnitId ) )
991
1409
  {
992
- name = "OnInterstitialLoadFailedEvent";
1410
+ name = ON_INTERSTITIAL_LOAD_FAILED_EVENT;
993
1411
  }
994
1412
  else if ( mRewardedAds.containsKey( adUnitId ) )
995
1413
  {
996
- name = "OnRewardedAdLoadFailedEvent";
1414
+ name = ON_REWARDED_AD_LOAD_FAILED_EVENT;
997
1415
  }
998
1416
  else if ( mAppOpenAds.containsKey( adUnitId ) )
999
1417
  {
1000
- name = "OnAppOpenAdLoadFailedEvent";
1418
+ name = ON_APPOPEN_AD_LOAD_FAILED_EVENT;
1001
1419
  }
1002
1420
  else
1003
1421
  {
@@ -1008,24 +1426,9 @@ public class AppLovinMAXModule
1008
1426
  sendReactNativeEventForAdLoadFailed( name, adUnitId, error );
1009
1427
  }
1010
1428
 
1011
- public void sendReactNativeEventForAdLoadFailed(final String name, final String adUnitId, final @Nullable MaxError error)
1429
+ void sendReactNativeEventForAdLoadFailed(final String name, final String adUnitId, @Nullable final MaxError error)
1012
1430
  {
1013
- WritableMap params = Arguments.createMap();
1014
- params.putString( "adUnitId", adUnitId );
1015
-
1016
- if ( error != null )
1017
- {
1018
- params.putInt( "code", error.getCode() );
1019
- params.putString( "message", error.getMessage() );
1020
- params.putString( "adLoadFailureInfo", error.getAdLoadFailureInfo() );
1021
- params.putMap( "waterfall", createAdWaterfallInfo( error.getWaterfall() ) );
1022
- }
1023
- else
1024
- {
1025
- params.putInt( "code", MaxErrorCode.UNSPECIFIED );
1026
- }
1027
-
1028
- sendReactNativeEvent( name, params );
1431
+ sendReactNativeEvent( name, getAdLoadFailedInfo( adUnitId, error ) );
1029
1432
  }
1030
1433
 
1031
1434
  @Override
@@ -1035,27 +1438,23 @@ public class AppLovinMAXModule
1035
1438
  final String name;
1036
1439
  if ( MaxAdFormat.BANNER == adFormat || MaxAdFormat.LEADER == adFormat )
1037
1440
  {
1038
- name = "OnBannerAdClickedEvent";
1441
+ name = ON_BANNER_AD_CLICKED_EVENT;
1039
1442
  }
1040
1443
  else if ( MaxAdFormat.MREC == adFormat )
1041
1444
  {
1042
- name = "OnMRecAdClickedEvent";
1445
+ name = ON_MREC_AD_CLICKED_EVENT;
1043
1446
  }
1044
1447
  else if ( MaxAdFormat.INTERSTITIAL == adFormat )
1045
1448
  {
1046
- name = "OnInterstitialClickedEvent";
1449
+ name = ON_INTERSTITIAL_CLICKED_EVENT;
1047
1450
  }
1048
1451
  else if ( MaxAdFormat.REWARDED == adFormat )
1049
1452
  {
1050
- name = "OnRewardedAdClickedEvent";
1051
- }
1052
- else if ( MaxAdFormat.NATIVE == adFormat )
1053
- {
1054
- name = "OnNativeAdClickedEvent";
1453
+ name = ON_REWARDED_AD_CLICKED_EVENT;
1055
1454
  }
1056
1455
  else if ( MaxAdFormat.APP_OPEN == adFormat )
1057
1456
  {
1058
- name = "OnAppOpenAdClickedEvent";
1457
+ name = ON_APPOPEN_AD_CLICKED_EVENT;
1059
1458
  }
1060
1459
  else
1061
1460
  {
@@ -1076,15 +1475,15 @@ public class AppLovinMAXModule
1076
1475
  final String name;
1077
1476
  if ( MaxAdFormat.INTERSTITIAL == adFormat )
1078
1477
  {
1079
- name = "OnInterstitialDisplayedEvent";
1478
+ name = ON_INTERSTITIAL_DISPLAYED_EVENT;
1080
1479
  }
1081
1480
  else if ( MaxAdFormat.REWARDED == adFormat )
1082
1481
  {
1083
- name = "OnRewardedAdDisplayedEvent";
1482
+ name = ON_REWARDED_AD_DISPLAYED_EVENT;
1084
1483
  }
1085
1484
  else // APP OPEN
1086
1485
  {
1087
- name = "OnAppOpenAdDisplayedEvent";
1486
+ name = ON_APPOPEN_AD_DISPLAYED_EVENT;
1088
1487
  }
1089
1488
 
1090
1489
  sendReactNativeEvent( name, getAdInfo( ad ) );
@@ -1100,22 +1499,18 @@ public class AppLovinMAXModule
1100
1499
  final String name;
1101
1500
  if ( MaxAdFormat.INTERSTITIAL == adFormat )
1102
1501
  {
1103
- name = "OnInterstitialAdFailedToDisplayEvent";
1502
+ name = ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT;
1104
1503
  }
1105
1504
  else if ( MaxAdFormat.REWARDED == adFormat )
1106
1505
  {
1107
- name = "OnRewardedAdFailedToDisplayEvent";
1506
+ name = ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT;
1108
1507
  }
1109
1508
  else // APP OPEN
1110
1509
  {
1111
- name = "OnAppOpenAdFailedToDisplayEvent";
1510
+ name = ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT;
1112
1511
  }
1113
1512
 
1114
- WritableMap params = getAdInfo( ad );
1115
- params.putInt( "code", error.getCode() );
1116
- params.putString( "message", error.getMessage() );
1117
-
1118
- sendReactNativeEvent( name, params );
1513
+ sendReactNativeEvent( name, getAdDisplayFailedInfo( ad, error ) );
1119
1514
  }
1120
1515
 
1121
1516
  @Override
@@ -1128,15 +1523,15 @@ public class AppLovinMAXModule
1128
1523
  String name;
1129
1524
  if ( MaxAdFormat.INTERSTITIAL == adFormat )
1130
1525
  {
1131
- name = "OnInterstitialHiddenEvent";
1526
+ name = ON_INTERSTITIAL_HIDDEN_EVENT;
1132
1527
  }
1133
1528
  else if ( MaxAdFormat.REWARDED == adFormat )
1134
1529
  {
1135
- name = "OnRewardedAdHiddenEvent";
1530
+ name = ON_REWARDED_AD_HIDDEN_EVENT;
1136
1531
  }
1137
1532
  else // APP OPEN
1138
1533
  {
1139
- name = "OnAppOpenAdHiddenEvent";
1534
+ name = ON_APPOPEN_AD_HIDDEN_EVENT;
1140
1535
  }
1141
1536
 
1142
1537
  sendReactNativeEvent( name, getAdInfo( ad ) );
@@ -1152,7 +1547,7 @@ public class AppLovinMAXModule
1152
1547
  return;
1153
1548
  }
1154
1549
 
1155
- sendReactNativeEvent( ( MaxAdFormat.MREC == adFormat ) ? "OnMRecAdExpandedEvent" : "OnBannerAdExpandedEvent", getAdInfo( ad ) );
1550
+ sendReactNativeEvent( ( MaxAdFormat.MREC == adFormat ) ? ON_MREC_AD_EXPANDED_EVENT : ON_BANNER_AD_EXPANDED_EVENT, getAdInfo( ad ) );
1156
1551
  }
1157
1552
 
1158
1553
  @Override
@@ -1165,7 +1560,7 @@ public class AppLovinMAXModule
1165
1560
  return;
1166
1561
  }
1167
1562
 
1168
- sendReactNativeEvent( ( MaxAdFormat.MREC == adFormat ) ? "OnMRecAdCollapsedEvent" : "OnBannerAdCollapsedEvent", getAdInfo( ad ) );
1563
+ sendReactNativeEvent( ( MaxAdFormat.MREC == adFormat ) ? ON_MREC_AD_COLLAPSED_EVENT : ON_BANNER_AD_COLLAPSED_EVENT, getAdInfo( ad ) );
1169
1564
  }
1170
1565
 
1171
1566
  @Override
@@ -1175,27 +1570,23 @@ public class AppLovinMAXModule
1175
1570
  final String name;
1176
1571
  if ( MaxAdFormat.BANNER == adFormat || MaxAdFormat.LEADER == adFormat )
1177
1572
  {
1178
- name = "OnBannerAdRevenuePaid";
1573
+ name = ON_BANNER_AD_REVENUE_PAID;
1179
1574
  }
1180
1575
  else if ( MaxAdFormat.MREC == adFormat )
1181
1576
  {
1182
- name = "OnMRecAdRevenuePaid";
1577
+ name = ON_MREC_AD_REVENUE_PAID;
1183
1578
  }
1184
1579
  else if ( MaxAdFormat.INTERSTITIAL == adFormat )
1185
1580
  {
1186
- name = "OnInterstitialAdRevenuePaid";
1581
+ name = ON_INTERSTITIAL_AD_REVENUE_PAID;
1187
1582
  }
1188
1583
  else if ( MaxAdFormat.REWARDED == adFormat )
1189
1584
  {
1190
- name = "OnRewardedAdRevenuePaid";
1191
- }
1192
- else if ( MaxAdFormat.NATIVE == adFormat )
1193
- {
1194
- name = "OnNativeAdRevenuePaid";
1585
+ name = ON_REWARDED_AD_REVENUE_PAID;
1195
1586
  }
1196
1587
  else if ( MaxAdFormat.APP_OPEN == adFormat )
1197
1588
  {
1198
- name = "OnAppOpenAdRevenuePaid";
1589
+ name = ON_APPOPEN_AD_REVENUE_PAID;
1199
1590
  }
1200
1591
  else
1201
1592
  {
@@ -1203,12 +1594,7 @@ public class AppLovinMAXModule
1203
1594
  return;
1204
1595
  }
1205
1596
 
1206
- WritableMap adInfo = getAdInfo( ad );
1207
- adInfo.putString( "networkPlacement", ad.getNetworkPlacement() );
1208
- adInfo.putString( "revenuePrecision", ad.getRevenuePrecision() );
1209
- adInfo.putString( "countryCode", sdkConfiguration.getCountryCode() );
1210
-
1211
- sendReactNativeEvent( name, adInfo );
1597
+ sendReactNativeEvent( name, getAdRevenueInfo( ad ) );
1212
1598
  }
1213
1599
 
1214
1600
  @Override
@@ -1535,6 +1921,28 @@ public class AppLovinMAXModule
1535
1921
  } );
1536
1922
  }
1537
1923
 
1924
+ private void setAdViewLocalExtraParameters(final String adUnitId, final MaxAdFormat adFormat, final String key, final String value)
1925
+ {
1926
+ getReactApplicationContext().runOnUiQueueThread( new Runnable()
1927
+ {
1928
+ @Override
1929
+ public void run()
1930
+ {
1931
+ d( "Setting " + adFormat.getLabel() + " local extra with key: \"" + key + "\" value: " + value );
1932
+
1933
+ // Retrieve ad view from the map
1934
+ final MaxAdView adView = retrieveAdView( adUnitId, adFormat );
1935
+ if ( adView == null )
1936
+ {
1937
+ e( adFormat.getLabel() + " does not exist" );
1938
+ return;
1939
+ }
1940
+
1941
+ adView.setLocalExtraParameter( key, value );
1942
+ }
1943
+ } );
1944
+ }
1945
+
1538
1946
  private void startAutoRefresh(final String adUnitId, final MaxAdFormat adFormat)
1539
1947
  {
1540
1948
  getReactApplicationContext().runOnUiQueueThread( new Runnable()
@@ -1692,7 +2100,7 @@ public class AppLovinMAXModule
1692
2100
  adViewWidthDp = mAdViewWidths.get( adUnitId );
1693
2101
  }
1694
2102
  // Top center / bottom center stretches full screen
1695
- else if ( "top_center".equalsIgnoreCase( adViewPosition ) || "bottom_center".equalsIgnoreCase( adViewPosition ) )
2103
+ else if ( TOP_CENTER.equalsIgnoreCase( adViewPosition ) || BOTTOM_CENTER.equalsIgnoreCase( adViewPosition ) )
1696
2104
  {
1697
2105
  int adViewWidthPx = windowRect.width();
1698
2106
  adViewWidthDp = AppLovinSdkUtils.pxToDp( getCurrentActivity(), adViewWidthPx );
@@ -1732,7 +2140,7 @@ public class AppLovinMAXModule
1732
2140
  adView.setTranslationX( 0 );
1733
2141
  params.setMargins( 0, 0, 0, 0 );
1734
2142
 
1735
- if ( "centered".equalsIgnoreCase( adViewPosition ) )
2143
+ if ( CENTERED.equalsIgnoreCase( adViewPosition ) )
1736
2144
  {
1737
2145
  gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
1738
2146
 
@@ -1814,7 +2222,7 @@ public class AppLovinMAXModule
1814
2222
  e( Log.getStackTraceString( e ) );
1815
2223
  }
1816
2224
 
1817
- private static void logUninitializedAccessError(final String callingMethod)
2225
+ public static void logUninitializedAccessError(final String callingMethod)
1818
2226
  {
1819
2227
  e( "ERROR: Failed to execute " + callingMethod + "() - please ensure the AppLovin MAX React Native module has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
1820
2228
  }
@@ -1884,7 +2292,7 @@ public class AppLovinMAXModule
1884
2292
  return new Point( AppLovinSdkUtils.dpToPx( context, (int) xDp ), AppLovinSdkUtils.dpToPx( context, (int) yDp ) );
1885
2293
  }
1886
2294
 
1887
- private static AppLovinGender getAppLovinGender(@Nullable String gender)
2295
+ private static AppLovinGender getAppLovinGender(@Nullable final String gender)
1888
2296
  {
1889
2297
  if ( gender != null )
1890
2298
  {
@@ -1905,7 +2313,25 @@ public class AppLovinMAXModule
1905
2313
  return AppLovinGender.UNKNOWN;
1906
2314
  }
1907
2315
 
1908
- private static AppLovinAdContentRating getAppLovinAdContentRating(int maximumAdContentRating)
2316
+ private static String getRawAppLovinGender(final AppLovinGender gender)
2317
+ {
2318
+ if ( gender == AppLovinGender.FEMALE )
2319
+ {
2320
+ return "F";
2321
+ }
2322
+ else if ( gender == AppLovinGender.MALE )
2323
+ {
2324
+ return "M";
2325
+ }
2326
+ else if ( gender == AppLovinGender.OTHER )
2327
+ {
2328
+ return "O";
2329
+ }
2330
+
2331
+ return "U";
2332
+ }
2333
+
2334
+ private static AppLovinAdContentRating getAppLovinAdContentRating(final int maximumAdContentRating)
1909
2335
  {
1910
2336
  if ( maximumAdContentRating == 1 )
1911
2337
  {
@@ -1923,23 +2349,9 @@ public class AppLovinMAXModule
1923
2349
  return AppLovinAdContentRating.NONE;
1924
2350
  }
1925
2351
 
1926
- private List<String> getStringArrayList(@Nullable ReadableArray readableArray)
1927
- {
1928
- if ( readableArray == null ) return null;
1929
-
1930
- List<String> list = new ArrayList<>( readableArray.size() );
1931
-
1932
- for ( Object item : readableArray.toArrayList() )
1933
- {
1934
- list.add( (String) item );
1935
- }
1936
-
1937
- return list;
1938
- }
1939
-
1940
2352
  // AD INFO
1941
2353
 
1942
- private WritableMap getAdInfo(final MaxAd ad)
2354
+ public WritableMap getAdInfo(final MaxAd ad)
1943
2355
  {
1944
2356
  WritableMap adInfo = Arguments.createMap();
1945
2357
  adInfo.putString( "adUnitId", ad.getAdUnitId() );
@@ -1953,6 +2365,43 @@ public class AppLovinMAXModule
1953
2365
  return adInfo;
1954
2366
  }
1955
2367
 
2368
+ public WritableMap getAdLoadFailedInfo(final String adUnitId, @Nullable final MaxError error)
2369
+ {
2370
+ WritableMap errInfo = Arguments.createMap();
2371
+ errInfo.putString( "adUnitId", adUnitId );
2372
+
2373
+ if ( error != null )
2374
+ {
2375
+ errInfo.putInt( "code", error.getCode() );
2376
+ errInfo.putString( "message", error.getMessage() );
2377
+ errInfo.putString( "adLoadFailureInfo", error.getAdLoadFailureInfo() );
2378
+ errInfo.putMap( "waterfall", createAdWaterfallInfo( error.getWaterfall() ) );
2379
+ }
2380
+ else
2381
+ {
2382
+ errInfo.putInt( "code", MaxErrorCode.UNSPECIFIED );
2383
+ }
2384
+
2385
+ return errInfo;
2386
+ }
2387
+
2388
+ public WritableMap getAdDisplayFailedInfo(final MaxAd ad, final MaxError error)
2389
+ {
2390
+ WritableMap params = getAdInfo( ad );
2391
+ params.putInt( "code", error.getCode() );
2392
+ params.putString( "message", error.getMessage() );
2393
+ return params;
2394
+ }
2395
+
2396
+ public WritableMap getAdRevenueInfo(final MaxAd ad)
2397
+ {
2398
+ WritableMap adInfo = getAdInfo( ad );
2399
+ adInfo.putString( "networkPlacement", ad.getNetworkPlacement() );
2400
+ adInfo.putString( "revenuePrecision", ad.getRevenuePrecision() );
2401
+ adInfo.putString( "countryCode", sdkConfiguration.getCountryCode() );
2402
+ return adInfo;
2403
+ }
2404
+
1956
2405
  // AD WATERFALL INFO
1957
2406
 
1958
2407
  private WritableMap createAdWaterfallInfo(final MaxAdWaterfallInfo waterfallInfo)
@@ -2076,6 +2525,60 @@ public class AppLovinMAXModule
2076
2525
  @Nullable
2077
2526
  public Map<String, Object> getConstants()
2078
2527
  {
2079
- return super.getConstants();
2528
+ final Map<String, Object> constants = new HashMap<>();
2529
+
2530
+ constants.put( "ON_MREC_AD_LOADED_EVENT", ON_MREC_AD_LOADED_EVENT );
2531
+ constants.put( "ON_MREC_AD_LOAD_FAILED_EVENT", ON_MREC_AD_LOAD_FAILED_EVENT );
2532
+ constants.put( "ON_MREC_AD_CLICKED_EVENT", ON_MREC_AD_CLICKED_EVENT );
2533
+ constants.put( "ON_MREC_AD_COLLAPSED_EVENT", ON_MREC_AD_COLLAPSED_EVENT );
2534
+ constants.put( "ON_MREC_AD_EXPANDED_EVENT", ON_MREC_AD_EXPANDED_EVENT );
2535
+ constants.put( "ON_MREC_AD_REVENUE_PAID", ON_MREC_AD_REVENUE_PAID );
2536
+
2537
+ constants.put( "ON_BANNER_AD_LOADED_EVENT", ON_BANNER_AD_LOADED_EVENT );
2538
+ constants.put( "ON_BANNER_AD_LOAD_FAILED_EVENT", ON_BANNER_AD_LOAD_FAILED_EVENT );
2539
+ constants.put( "ON_BANNER_AD_CLICKED_EVENT", ON_BANNER_AD_CLICKED_EVENT );
2540
+ constants.put( "ON_BANNER_AD_COLLAPSED_EVENT", ON_BANNER_AD_COLLAPSED_EVENT );
2541
+ constants.put( "ON_BANNER_AD_EXPANDED_EVENT", ON_BANNER_AD_EXPANDED_EVENT );
2542
+ constants.put( "ON_BANNER_AD_REVENUE_PAID", ON_BANNER_AD_REVENUE_PAID );
2543
+
2544
+ constants.put( "ON_INTERSTITIAL_LOADED_EVENT", ON_INTERSTITIAL_LOADED_EVENT );
2545
+ constants.put( "ON_INTERSTITIAL_LOAD_FAILED_EVENT", ON_INTERSTITIAL_LOAD_FAILED_EVENT );
2546
+ constants.put( "ON_INTERSTITIAL_CLICKED_EVENT", ON_INTERSTITIAL_CLICKED_EVENT );
2547
+ constants.put( "ON_INTERSTITIAL_DISPLAYED_EVENT", ON_INTERSTITIAL_DISPLAYED_EVENT );
2548
+ constants.put( "ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT", ON_INTERSTITIAL_AD_FAILED_TO_DISPLAY_EVENT );
2549
+ constants.put( "ON_INTERSTITIAL_HIDDEN_EVENT", ON_INTERSTITIAL_HIDDEN_EVENT );
2550
+ constants.put( "ON_INTERSTITIAL_AD_REVENUE_PAID", ON_INTERSTITIAL_AD_REVENUE_PAID );
2551
+
2552
+ constants.put( "ON_REWARDED_AD_LOADED_EVENT", ON_REWARDED_AD_LOADED_EVENT );
2553
+ constants.put( "ON_REWARDED_AD_LOAD_FAILED_EVENT", ON_REWARDED_AD_LOAD_FAILED_EVENT );
2554
+ constants.put( "ON_REWARDED_AD_CLICKED_EVENT", ON_REWARDED_AD_CLICKED_EVENT );
2555
+ constants.put( "ON_REWARDED_AD_DISPLAYED_EVENT", ON_REWARDED_AD_DISPLAYED_EVENT );
2556
+ constants.put( "ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT", ON_REWARDED_AD_FAILED_TO_DISPLAY_EVENT );
2557
+ constants.put( "ON_REWARDED_AD_HIDDEN_EVENT", ON_REWARDED_AD_HIDDEN_EVENT );
2558
+ constants.put( "ON_REWARDED_AD_RECEIVED_REWARD_EVENT", ON_REWARDED_AD_RECEIVED_REWARD_EVENT );
2559
+ constants.put( "ON_REWARDED_AD_REVENUE_PAID", ON_REWARDED_AD_REVENUE_PAID );
2560
+
2561
+ constants.put( "ON_APPOPEN_AD_LOADED_EVENT", ON_APPOPEN_AD_LOADED_EVENT );
2562
+ constants.put( "ON_APPOPEN_AD_LOAD_FAILED_EVENT", ON_APPOPEN_AD_LOAD_FAILED_EVENT );
2563
+ constants.put( "ON_APPOPEN_AD_CLICKED_EVENT", ON_APPOPEN_AD_CLICKED_EVENT );
2564
+ constants.put( "ON_APPOPEN_AD_DISPLAYED_EVENT", ON_APPOPEN_AD_DISPLAYED_EVENT );
2565
+ constants.put( "ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT", ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT );
2566
+ constants.put( "ON_APPOPEN_AD_HIDDEN_EVENT", ON_APPOPEN_AD_HIDDEN_EVENT );
2567
+ constants.put( "ON_APPOPEN_AD_REVENUE_PAID", ON_APPOPEN_AD_REVENUE_PAID );
2568
+
2569
+ constants.put( "TOP_CENTER_POSITION", TOP_CENTER );
2570
+ constants.put( "TOP_LEFT_POSITION", TOP_LEFT );
2571
+ constants.put( "TOP_RIGHT_POSITION", TOP_RIGHT );
2572
+ constants.put( "CENTERED_POSITION", CENTERED );
2573
+ constants.put( "CENTER_LEFT_POSITION", CENTER_LEFT );
2574
+ constants.put( "CENTER_RIGHT_POSITION", CENTER_RIGHT );
2575
+ constants.put( "BOTTOM_LEFT_POSITION", BOTTOM_LEFT );
2576
+ constants.put( "BOTTOM_CENTER_POSITION", BOTTOM_CENTER );
2577
+ constants.put( "BOTTOM_RIGHT_POSITION", BOTTOM_RIGHT );
2578
+
2579
+ constants.put( "BANNER_AD_FORMAT_LABEL", MaxAdFormat.BANNER.getLabel() );
2580
+ constants.put( "MREC_AD_FORMAT_LABEL", MaxAdFormat.MREC.getLabel() );
2581
+
2582
+ return constants;
2080
2583
  }
2081
2584
  }