11import { firebase } from "../firebase-common" ;
22import { BannerOptions , InterstitialOptions , PreloadRewardedVideoAdOptions , ShowRewardedVideoAdOptions } from "./admob" ;
33import { AD_SIZE , BANNER_DEFAULTS , rewardedVideoCallbacks } from "./admob-common" ;
4- import * as appModule from "tns-core-modules/application" ;
5- import { topmost } from "tns-core-modules/ui/frame" ;
6- import { layout } from "tns-core-modules/utils/utils" ;
4+ import { Application , Frame , Utils } from "@nativescript/core" ;
75
86declare const com : any ;
97
@@ -22,7 +20,7 @@ export function showBanner(arg: BannerOptions): Promise<any> {
2220 }
2321 }
2422
25- firebase . admob . adView = new com . google . android . gms . ads . AdView ( appModule . android . foregroundActivity ) ;
23+ firebase . admob . adView = new com . google . android . gms . ads . AdView ( Application . android . foregroundActivity ) ;
2624 firebase . admob . adView . setAdUnitId ( settings . androidBannerId ) ;
2725 const bannerType = _getBannerType ( settings . size ) ;
2826 firebase . admob . adView . setAdSize ( bannerType ) ;
@@ -53,7 +51,7 @@ export function showBanner(arg: BannerOptions): Promise<any> {
5351 const ad = _buildAdRequest ( settings ) ;
5452 firebase . admob . adView . loadAd ( ad ) ;
5553
56- const density = layout . getDisplayDensity ( ) ,
54+ const density = Utils . layout . getDisplayDensity ( ) ,
5755 top = settings . margins . top * density ,
5856 bottom = settings . margins . bottom * density ;
5957
@@ -71,21 +69,21 @@ export function showBanner(arg: BannerOptions): Promise<any> {
7169 relativeLayoutParams . addRule ( android . widget . RelativeLayout . ALIGN_PARENT_TOP ) ;
7270 }
7371
74- const adViewLayout = new android . widget . RelativeLayout ( appModule . android . foregroundActivity ) ;
72+ const adViewLayout = new android . widget . RelativeLayout ( Application . android . foregroundActivity ) ;
7573 adViewLayout . addView ( firebase . admob . adView , relativeLayoutParams ) ;
7674
7775 const relativeLayoutParamsOuter = new android . widget . RelativeLayout . LayoutParams (
7876 android . widget . RelativeLayout . LayoutParams . MATCH_PARENT ,
7977 android . widget . RelativeLayout . LayoutParams . MATCH_PARENT ) ;
8078
81- // Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.topmost()' doesn't resolve to 'undefined'.
79+ // Wrapping it in a timeout makes sure that when this function is loaded from a Page.loaded event 'frame.Frame. topmost()' doesn't resolve to 'undefined'.
8280 // Also, in NativeScript 4+ it may be undefined anyway.. so using the appModule in that case.
8381 setTimeout ( ( ) => {
84- const top = topmost ( ) ;
82+ const top = Frame . topmost ( ) ;
8583 if ( top !== undefined && top . currentPage && top . currentPage . android && top . currentPage . android . getParent ( ) ) {
8684 top . currentPage . android . getParent ( ) . addView ( adViewLayout , relativeLayoutParamsOuter ) ;
87- } else if ( appModule . android && appModule . android . foregroundActivity ) {
88- appModule . android . foregroundActivity . getWindow ( ) . getDecorView ( ) . addView ( adViewLayout , relativeLayoutParamsOuter ) ;
85+ } else if ( Application . android && Application . android . foregroundActivity ) {
86+ Application . android . foregroundActivity . getWindow ( ) . getDecorView ( ) . addView ( adViewLayout , relativeLayoutParamsOuter ) ;
8987 } else {
9088 console . log ( "Could not find a view to add the banner to" ) ;
9189 }
@@ -101,7 +99,7 @@ export function preloadInterstitial(arg: InterstitialOptions): Promise<any> {
10199 return new Promise ( ( resolve , reject ) => {
102100 try {
103101 const settings = firebase . merge ( arg , BANNER_DEFAULTS ) ;
104- const activity = appModule . android . foregroundActivity || appModule . android . startActivity ;
102+ const activity = Application . android . foregroundActivity || Application . android . startActivity ;
105103 firebase . admob . interstitialView = new com . google . android . gms . ads . InterstitialAd ( activity ) ;
106104 firebase . admob . interstitialView . setAdUnitId ( settings . androidInterstitialId ) ;
107105
@@ -152,7 +150,7 @@ export function showInterstitial(arg?: InterstitialOptions): Promise<any> {
152150 }
153151
154152 const settings = firebase . merge ( arg , BANNER_DEFAULTS ) ;
155- const activity = appModule . android . foregroundActivity || appModule . android . startActivity ;
153+ const activity = Application . android . foregroundActivity || Application . android . startActivity ;
156154 firebase . admob . interstitialView = new com . google . android . gms . ads . InterstitialAd ( activity ) ;
157155 firebase . admob . interstitialView . setAdUnitId ( settings . androidInterstitialId ) ;
158156
@@ -192,7 +190,7 @@ export function preloadRewardedVideoAd(arg: PreloadRewardedVideoAdOptions): Prom
192190 return new Promise ( ( resolve , reject ) => {
193191 try {
194192 const settings = firebase . merge ( arg , BANNER_DEFAULTS ) ;
195- const activity = appModule . android . foregroundActivity || appModule . android . startActivity ;
193+ const activity = Application . android . foregroundActivity || Application . android . startActivity ;
196194 firebase . admob . rewardedAdVideoView = com . google . android . gms . ads . MobileAds . getRewardedVideoAdInstance ( activity ) ;
197195
198196 rewardedVideoCallbacks . onLoaded = resolve ;
@@ -326,7 +324,7 @@ function _buildAdRequest(settings): any {
326324 if ( settings . testing ) {
327325 builder . addTestDevice ( com . google . android . gms . ads . AdRequest . DEVICE_ID_EMULATOR ) ;
328326 // This will request test ads on the emulator and device by passing this hashed device ID.
329- const activity = appModule . android . foregroundActivity || appModule . android . startActivity ;
327+ const activity = Application . android . foregroundActivity || Application . android . startActivity ;
330328 const ANDROID_ID = android . provider . Settings . Secure . getString ( activity . getContentResolver ( ) , android . provider . Settings . Secure . ANDROID_ID ) ;
331329 let deviceId = _md5 ( ANDROID_ID ) ;
332330 if ( deviceId !== null ) {
0 commit comments