-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathindex.android.ts
789 lines (681 loc) · 21.8 KB
/
index.android.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
import { Application, Utils } from '@nativescript/core';
import lazy from '@nativescript/core/utils/lazy';
import { IAdmob, AdEventListener, RequestConfiguration, AdShowOptions, IInterstitialAd, RequestOptions, IRewardedAd, IRewardedInterstitialAd, IRewardedItem, ServerSideVerificationOptions, AdapterStatus } from '.';
import { AdEventType, BannerAdBase, RewardedAdEventType, MaxAdContentRating, unitIdProperty, BannerAdSizeBase, sizeProperty } from './common';
export { MaxAdContentRating, AdEventType };
export * from './adsconsent';
export * from './nativead';
export class AdmobError extends Error {
_native: java.lang.Exception;
static fromNative(native: java.lang.Exception, message?: string) {
const error = new AdmobError(message || native?.getMessage?.());
error._native = native;
return error;
}
get native() {
return this._native;
}
intoNative() {
if (!this._native) {
return new java.lang.Exception(this.message);
}
return this._native;
}
}
let defaultAdmob: Admob;
if (!global.__admob) {
Object.defineProperty(global, '__admob', {
value: () => {
if (!defaultAdmob) {
defaultAdmob = new Admob();
}
return defaultAdmob;
},
writable: false,
});
}
@NativeClass()
class AdListener extends com.google.android.gms.ads.AdListener {
_owner: WeakRef<BannerAd>;
constructor(owner: WeakRef<BannerAd>) {
super();
this._owner = owner;
return global.__native(this);
}
onAdLoaded() {
const owner = this._owner?.get?.();
if (!owner) {
return;
}
owner.notify({
eventName: BannerAd.onAdLoadedEvent,
object: owner,
});
}
onAdClicked() {
const owner = this._owner?.get?.();
if (!owner) {
return;
}
owner.notify({
eventName: BannerAd.onAdClickedEvent,
object: owner,
});
}
onAdFailedToLoad(error: com.google.android.gms.ads.LoadAdError) {
const owner = this._owner?.get?.();
if (!owner) {
return;
}
owner.notify({
eventName: BannerAd.onAdFailedToLoadEvent,
object: owner,
error: AdmobError.fromNative(error as any),
});
}
onAdClosed() {
const owner = this._owner?.get?.();
if (!owner) {
return;
}
owner.notify({
eventName: BannerAd.onAdClosedEvent,
object: owner,
});
}
onAdImpression() {
const owner = this._owner?.get?.();
if (!owner) {
return;
}
owner.notify({
eventName: BannerAd.onAdImpression,
object: owner,
});
}
onAdOpened() {
const owner = this._owner?.get?.();
if (!owner) {
return;
}
owner.notify({
eventName: BannerAd.onAdOpenedEvent,
object: owner,
});
}
}
export class AdRequest {
_native: com.google.android.gms.ads.AdRequest;
static fromNative(request: com.google.android.gms.ads.AdRequest) {
if (request instanceof com.google.android.gms.ads.AdRequest) {
const ret = new AdRequest();
ret._native = request;
return ret;
}
return null;
}
get contentUrl(): string {
return this.native.getContentUrl();
}
get keywords(): string[] {
const kw = this.native.getKeywords().toArray();
const count = kw.length;
const ret = [];
for (let i = 0; i < count; i++) {
ret.push(kw[i]);
}
return ret;
}
get neighboringContentUrls(): string[] {
const urls = this.native.getNeighboringContentUrls();
const count = urls.size();
const ret = [];
for (let i = 0; i < count; i++) {
ret.push(urls.get(i));
}
return ret;
}
isTestDevice(): boolean {
return this.native.isTestDevice(Utils.android.getApplicationContext());
}
get native() {
return this._native;
}
get android() {
return this.native;
}
}
export class InterstitialAd implements IInterstitialAd {
_native: com.google.android.gms.ads.interstitial.InterstitialAd;
_adUnitId: string;
_requestOptions?: RequestOptions;
_loaded = false;
_nativeRequest: com.google.android.gms.ads.AdRequest;
static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions): InterstitialAd {
const ad = new InterstitialAd();
ad._adUnitId = adUnitId;
ad._requestOptions = requestOptions;
return ad;
}
get adUnitId(): string {
return this._adUnitId;
}
_setNative(value) {
this._native = value;
}
_setLoaded(value) {
this._loaded = value;
}
_onAdEvent?: AdEventListener;
get loaded(): boolean {
return this._loaded;
}
load(): void {
const ref = new WeakRef(this);
this._nativeRequest = org.nativescript.firebase.admob.FirebaseAdmob.InterstitialAd.load(
Application.android.foregroundActivity || Application.android.startActivity,
this._adUnitId,
JSON.stringify(this._requestOptions || {}),
new org.nativescript.firebase.admob.FirebaseAdmob.AdCallback({
onEvent(event: string, dataOrError: any) {
const owner = ref.get?.();
switch (event) {
case AdEventType.LOADED:
owner._setNative?.(dataOrError);
owner?._onAdEvent(AdEventType.LOADED, null, owner);
owner?._setLoaded(true);
break;
case AdEventType.CLOSED:
owner?._onAdEvent(AdEventType.CLOSED, null, owner);
owner?._setLoaded(false);
break;
case AdEventType.FAILED_TO_SHOW_FULL_SCREEN_CONTENT:
owner?._onAdEvent(AdEventType.FAILED_TO_SHOW_FULL_SCREEN_CONTENT, AdmobError.fromNative(dataOrError), owner);
break;
case AdEventType.IMPRESSION:
owner?._onAdEvent(AdEventType.IMPRESSION, null, owner);
break;
case AdEventType.OPENED:
owner?._onAdEvent(AdEventType.OPENED, null, owner);
break;
case AdEventType.FAILED_TO_LOAD_EVENT:
owner?._onAdEvent(AdEventType.FAILED_TO_LOAD_EVENT, AdmobError.fromNative(dataOrError), owner);
break;
}
},
})
);
}
onAdEvent(listener: AdEventListener) {
this._onAdEvent = listener;
}
show(showOptions?: AdShowOptions) {
if (typeof showOptions?.immersiveModeEnabled === 'boolean') {
this.native.setImmersiveMode(showOptions?.immersiveModeEnabled);
}
this.native.show(Application.android.foregroundActivity || Application.android.startActivity);
}
get native() {
return this._native;
}
get android() {
return this.native;
}
get request() {
return AdRequest.fromNative(this._nativeRequest);
}
}
export class RewardedInterstitialAd implements IRewardedInterstitialAd {
_native: com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
_adUnitId: string;
_requestOptions?: RequestOptions;
_loaded = false;
_nativeRequest: com.google.android.gms.ads.AdRequest;
static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions): RewardedInterstitialAd {
const ad = new RewardedInterstitialAd();
ad._adUnitId = adUnitId;
ad._requestOptions = requestOptions;
return ad;
}
get adUnitId(): string {
return this._adUnitId;
}
_setNative(value) {
this._native = value;
}
_setLoaded(value) {
this._loaded = value;
}
get loaded(): boolean {
return this._loaded;
}
load(): void {
const ref = new WeakRef(this);
this._nativeRequest = org.nativescript.firebase.admob.FirebaseAdmob.RewardedInterstitialAd.load(
Application.android.foregroundActivity || Application.android.startActivity,
this._adUnitId,
JSON.stringify(this._requestOptions || {}),
new org.nativescript.firebase.admob.FirebaseAdmob.AdCallback({
onEvent(event: string, dataOrError: any) {
const owner = ref.get?.();
switch (event) {
case AdEventType.LOADED:
owner._setNative?.(dataOrError);
owner?._onAdEvent(AdEventType.LOADED, null, owner);
owner?._setLoaded(true);
break;
case AdEventType.CLOSED:
owner?._onAdEvent(AdEventType.CLOSED, null, owner);
owner?._setLoaded(false);
break;
case AdEventType.FAILED_TO_SHOW_FULL_SCREEN_CONTENT:
owner?._onAdEvent(AdEventType.FAILED_TO_SHOW_FULL_SCREEN_CONTENT, AdmobError.fromNative(dataOrError), owner);
break;
case AdEventType.IMPRESSION:
owner?._onAdEvent(AdEventType.IMPRESSION, null, owner);
break;
case AdEventType.OPENED:
owner?._onAdEvent(AdEventType.OPENED, null, owner);
break;
case AdEventType.FAILED_TO_LOAD_EVENT:
owner?._onAdEvent(AdEventType.FAILED_TO_LOAD_EVENT, AdmobError.fromNative(dataOrError), owner);
break;
}
},
})
);
}
_onAdEvent: AdEventListener;
onAdEvent(listener: AdEventListener) {
this._onAdEvent = listener;
}
show(showOptions?: AdShowOptions) {
if (typeof showOptions?.immersiveModeEnabled === 'boolean') {
this.native.setImmersiveMode(showOptions?.immersiveModeEnabled);
}
const ref = new WeakRef(this);
org.nativescript.firebase.admob.FirebaseAdmob.RewardedInterstitialAd.show(
Application.android.foregroundActivity || Application.android.startActivity,
this.native,
new org.nativescript.firebase.admob.FirebaseAdmob.Callback<com.google.android.gms.ads.rewarded.RewardItem>({
onSuccess(reward): void {
ref.get()?._onAdEvent?.(RewardedAdEventType.EARNED_REWARD, null, RewardedItem.fromNative(reward));
},
onError(error): void {},
})
);
}
setServerSideVerificationOptions(options: ServerSideVerificationOptions): void {
if (this.native) {
const ssvo = new com.google.android.gms.ads.rewarded.ServerSideVerificationOptions.Builder();
if (options.customData) {
ssvo.setCustomData(options.customData);
}
if (options.userId) {
ssvo.setUserId(options.userId);
}
this.native.setServerSideVerificationOptions(ssvo.build());
}
}
get native() {
return this._native;
}
get android() {
return this.native;
}
get request() {
return AdRequest.fromNative(this._nativeRequest);
}
}
export class RewardedAd implements IRewardedAd {
_native: com.google.android.gms.ads.rewarded.RewardedAd;
_adUnitId: string;
_requestOptions?: RequestOptions;
_loaded = false;
_nativeRequest: com.google.android.gms.ads.AdRequest;
static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions): RewardedAd {
const reward = new RewardedAd();
reward._adUnitId = adUnitId;
reward._requestOptions = requestOptions;
return reward;
}
get adUnitId(): string {
return this._adUnitId;
}
get loaded(): boolean {
return this._loaded;
}
_setNative(value) {
this._native = value;
}
_setLoaded(value) {
this._loaded = value;
}
load(): void {
const ref = new WeakRef(this);
this._nativeRequest = org.nativescript.firebase.admob.FirebaseAdmob.RewardedAd.load(
Application.android.foregroundActivity || Application.android.startActivity,
this.adUnitId,
JSON.stringify(this._requestOptions || {}),
new org.nativescript.firebase.admob.FirebaseAdmob.AdCallback({
onEvent(event: string, dataOrError: any) {
const owner = ref.get?.();
if (!owner) {
return;
}
switch (event) {
case AdEventType.LOADED:
owner._setNative(dataOrError);
owner._onAdEvent(AdEventType.LOADED, null, owner);
owner._setLoaded(true);
break;
case AdEventType.CLOSED:
owner._onAdEvent(AdEventType.CLOSED, null, owner);
owner._setLoaded(false);
break;
case AdEventType.FAILED_TO_SHOW_FULL_SCREEN_CONTENT:
owner._onAdEvent(AdEventType.FAILED_TO_SHOW_FULL_SCREEN_CONTENT, AdmobError.fromNative(dataOrError), owner);
break;
case AdEventType.IMPRESSION:
owner._onAdEvent(AdEventType.IMPRESSION, null, owner);
break;
case AdEventType.OPENED:
owner._onAdEvent(AdEventType.OPENED, null, owner);
break;
case AdEventType.FAILED_TO_LOAD_EVENT:
owner._onAdEvent(AdEventType.FAILED_TO_LOAD_EVENT, AdmobError.fromNative(dataOrError), owner);
break;
}
},
})
);
}
_onAdEvent: AdEventListener;
onAdEvent(listener: AdEventListener) {
this._onAdEvent = listener;
}
show(showOptions?: AdShowOptions) {
if (typeof showOptions?.immersiveModeEnabled === 'boolean') {
this.native.setImmersiveMode(showOptions?.immersiveModeEnabled);
}
const ref = new WeakRef(this);
org.nativescript.firebase.admob.FirebaseAdmob.RewardedAd.show(
Application.android.foregroundActivity || Application.android.startActivity,
this.native,
new org.nativescript.firebase.admob.FirebaseAdmob.Callback<com.google.android.gms.ads.rewarded.RewardItem>({
onSuccess(reward): void {
ref.get()?._onAdEvent?.(RewardedAdEventType.EARNED_REWARD, null, RewardedItem.fromNative(reward));
},
onError(error): void {},
})
);
}
setServerSideVerificationOptions(options: ServerSideVerificationOptions): void {
if (this.native) {
const ssvo = new com.google.android.gms.ads.rewarded.ServerSideVerificationOptions.Builder();
if (options.customData) {
ssvo.setCustomData(options.customData);
}
if (options.userId) {
ssvo.setUserId(options.userId);
}
this.native.setServerSideVerificationOptions(ssvo.build());
}
}
get native() {
return this._native;
}
get android() {
return this.native;
}
get request() {
return AdRequest.fromNative(this._nativeRequest);
}
}
export class RewardedItem implements IRewardedItem {
_native: com.google.android.gms.ads.rewarded.RewardItem;
static fromNative(reward: com.google.android.gms.ads.rewarded.RewardItem) {
if (reward instanceof com.google.android.gms.ads.rewarded.RewardItem) {
const item = new RewardedItem();
item._native = reward;
return item;
}
return null;
}
get amount(): number {
return this.native?.getAmount?.();
}
get type(): string {
return this.native?.getType();
}
get native() {
return this._native;
}
get android() {
return this.native;
}
}
const BANNER = lazy(() => com.google.android.gms.ads.AdSize.BANNER);
const FULL_BANNER = lazy(() => com.google.android.gms.ads.AdSize.FULL_BANNER);
const LARGE_BANNER = lazy(() => com.google.android.gms.ads.AdSize.LARGE_BANNER);
const LEADERBOARD = lazy(() => com.google.android.gms.ads.AdSize.LEADERBOARD);
const MEDIUM_RECTANGLE = lazy(() => com.google.android.gms.ads.AdSize.MEDIUM_RECTANGLE);
const FLUID = lazy(() => com.google.android.gms.ads.AdSize.FLUID);
const WIDE_SKYSCRAPER = lazy(() => com.google.android.gms.ads.AdSize.WIDE_SKYSCRAPER);
const SEARCH = lazy(() => com.google.android.gms.ads.AdSize.SEARCH);
const INVALID = lazy(() => com.google.android.gms.ads.AdSize.INVALID);
const FULL_WIDTH = lazy(() => com.google.android.gms.ads.AdSize.FULL_WIDTH);
const AUTO_HEIGHT = lazy(() => com.google.android.gms.ads.AdSize.AUTO_HEIGHT);
export class BannerAdSize extends BannerAdSizeBase {
_native: com.google.android.gms.ads.AdSize;
constructor(width?: number, height?: number) {
super();
if (width && height) {
this._native = new com.google.android.gms.ads.AdSize(width, height);
}
}
static fromNative(size: com.google.android.gms.ads.AdSize) {
const banner = new BannerAdSize();
if (size instanceof com.google.android.gms.ads.AdSize) {
banner._native = size;
} else {
banner._native = com.google.android.gms.ads.AdSize.INVALID;
}
return banner;
}
static get BANNER(): BannerAdSize {
return BannerAdSize.fromNative(BANNER());
}
static get FULL_BANNER(): BannerAdSize {
return BannerAdSize.fromNative(FULL_BANNER());
}
static get LARGE_BANNER(): BannerAdSize {
return BannerAdSize.fromNative(LARGE_BANNER());
}
static get LEADERBOARD(): BannerAdSize {
return BannerAdSize.fromNative(LEADERBOARD());
}
static get MEDIUM_RECTANGLE(): BannerAdSize {
return BannerAdSize.fromNative(MEDIUM_RECTANGLE());
}
static createAnchoredAdaptiveBanner(width: number, orientation: 'portrait' | 'landscape' | 'device' = 'device'): BannerAdSize {
switch (orientation) {
case 'portrait':
return BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getPortraitAnchoredAdaptiveBannerAdSize(Application.android.foregroundActivity || Application.android.startActivity, width));
case 'landscape':
return BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getLandscapeAnchoredAdaptiveBannerAdSize(Application.android.foregroundActivity || Application.android.startActivity, width));
default:
return BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(Application.android.foregroundActivity || Application.android.startActivity, width));
}
}
static createInLineAdaptiveBanner(width: number, maxHeight = 0, orientation: 'portrait' | 'landscape' | 'device' = 'device'): BannerAdSize {
if (maxHeight > 0) {
BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getInlineAdaptiveBannerAdSize(width, maxHeight));
}
switch (orientation) {
case 'portrait':
return BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getPortraitInlineAdaptiveBannerAdSize(Application.android.foregroundActivity || Application.android.startActivity, width));
case 'landscape':
return BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getLandscapeInlineAdaptiveBannerAdSize(Application.android.foregroundActivity || Application.android.startActivity, width));
default:
return BannerAdSize.fromNative(com.google.android.gms.ads.AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(Application.android.foregroundActivity || Application.android.startActivity, width));
}
}
static get FLUID(): BannerAdSize {
return BannerAdSize.fromNative(FLUID());
}
static get WIDE_SKYSCRAPER(): BannerAdSize {
return BannerAdSize.fromNative(WIDE_SKYSCRAPER());
}
static get INVALID(): BannerAdSize {
return BannerAdSize.fromNative(INVALID());
}
static get SEARCH(): BannerAdSize {
return BannerAdSize.fromNative(SEARCH());
}
get native() {
return this._native;
}
get android() {
return this.native;
}
}
export class BannerAd extends BannerAdBase {
_native: com.google.android.gms.ads.AdView;
_listener;
_nativeRequest: com.google.android.gms.ads.AdRequest;
[sizeProperty.setNative](value) {
if (this._native) {
this._native.setAdSize(value?.native);
}
}
[unitIdProperty.setNative](value) {
if (this._native) {
this._native.setAdUnitId(value);
}
}
createNativeView() {
this._native = new com.google.android.gms.ads.AdView(this._context);
return this._native;
}
initNativeView() {
super.initNativeView();
this._listener = new AdListener(new WeakRef(this));
this._native.setAdListener(this._listener);
}
load(options?: RequestOptions) {
if (this._native) {
this._nativeRequest = org.nativescript.firebase.admob.FirebaseAdmob.BannerAd.load(JSON.stringify(options || {}), this._native);
}
}
isLoading(): boolean {
return this._native?.isLoading?.();
}
get request() {
return AdRequest.fromNative(this._nativeRequest);
}
}
export class Admob implements IAdmob {
constructor() {
if (defaultAdmob) {
return defaultAdmob;
}
defaultAdmob = this as Admob;
}
static init(): Promise<{ [key: string]: AdapterStatus }> {
return new Promise((resolve, reject) => {
com.google.android.gms.ads.MobileAds.initialize(
Utils.android.getApplicationContext(),
new com.google.android.gms.ads.initialization.OnInitializationCompleteListener({
onInitializationComplete(status: com.google.android.gms.ads.initialization.InitializationStatus) {
let data = {};
try {
data = JSON.parse(org.nativescript.firebase.admob.FirebaseAdmob.toJSONStatusMap(status.getAdapterStatusMap()));
} catch (e) {}
resolve(data);
},
})
);
});
}
static getInstance(): Admob {
return new Admob();
}
set requestConfiguration(requestConfiguration: RequestConfiguration) {
try {
const parsedConfiguration: any = { ...requestConfiguration };
if (typeof parsedConfiguration.tagForChildDirectedTreatment === 'boolean') {
parsedConfiguration.tagForChildDirectedTreatment = String(parsedConfiguration.tagForChildDirectedTreatment);
} else {
parsedConfiguration.tagForChildDirectedTreatment = 'unspecified';
}
if (typeof parsedConfiguration.tagForUnderAgeOfConsent === 'boolean') {
parsedConfiguration.tagForUnderAgeOfConsent = String(parsedConfiguration.tagForUnderAgeOfConsent);
} else {
parsedConfiguration.tagForUnderAgeOfConsent = 'unspecified';
}
org.nativescript.firebase.admob.FirebaseAdmob.setRequestConfiguration(JSON.stringify(requestConfiguration));
} catch (e) {}
}
get requestConfiguration(): RequestConfiguration {
const ret: RequestConfiguration = {};
const config = com.google.android.gms.ads.MobileAds.getRequestConfiguration();
switch (config.getTagForChildDirectedTreatment()) {
case com.google.android.gms.ads.RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE:
ret.tagForChildDirectedTreatment = true;
break;
case com.google.android.gms.ads.RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE:
ret.tagForChildDirectedTreatment = false;
break;
default:
// noop
break;
}
switch (config.getTagForUnderAgeOfConsent()) {
case com.google.android.gms.ads.RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE:
ret.tagForUnderAgeOfConsent = true;
break;
case com.google.android.gms.ads.RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE:
ret.tagForUnderAgeOfConsent = false;
break;
default:
// noop
break;
}
switch (config.getMaxAdContentRating()) {
case com.google.android.gms.ads.RequestConfiguration.MAX_AD_CONTENT_RATING_G:
ret.maxAdContentRating = MaxAdContentRating.G;
break;
case com.google.android.gms.ads.RequestConfiguration.MAX_AD_CONTENT_RATING_MA:
ret.maxAdContentRating = MaxAdContentRating.MA;
break;
case com.google.android.gms.ads.RequestConfiguration.MAX_AD_CONTENT_RATING_PG:
ret.maxAdContentRating = MaxAdContentRating.PG;
break;
case com.google.android.gms.ads.RequestConfiguration.MAX_AD_CONTENT_RATING_T:
ret.maxAdContentRating = MaxAdContentRating.T;
break;
default:
// noop
break;
}
ret.testDevices = [];
const devices = config.getTestDeviceIds();
if (devices) {
const count = devices.size();
for (let i = 0; i < count; i++) {
ret.testDevices.push(devices.get(i));
}
}
return ret;
}
setRequestConfiguration(requestConfiguration: RequestConfiguration) {
this.requestConfiguration = requestConfiguration;
}
getRequestConfiguration(): RequestConfiguration {
return this.requestConfiguration;
}
get app() {
return global?.__defaultFirebaseApp;
}
}