Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 731c116

Browse files
author
svzi
committed
moved AdMob init to firebase.init, added AdLister to showBanner()
1 parent 6649521 commit 731c116

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

firebase.android.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ firebase.init = function (arg) {
208208

209209
var firebaseAuth = com.google.firebase.auth.FirebaseAuth.getInstance();
210210

211+
// init admob
212+
com.google.android.gms.ads.MobileAds.initialize(appModule.android.context); // TODO not sure its bound to packagename.. this is from the admob-demo
213+
211214
if (arg.onAuthStateChanged) {
212215
firebase.authStateListener = new com.google.firebase.auth.FirebaseAuth.AuthStateListener({
213216
onAuthStateChanged: function (fbAuth) {
@@ -475,11 +478,6 @@ firebase.admob.showBanner = function (arg) {
475478
try {
476479
var settings = firebase.merge(arg, firebase.admob.defaults);
477480

478-
// this should also be possible in init
479-
com.google.android.gms.ads.MobileAds.initialize(
480-
appModule.android.context,
481-
settings.androidBannerId); // TODO not sure its bound to packagename.. this is from the admob-demo
482-
483481
// always close a previously opened banner
484482
if (firebase.admob.adView !== null && firebase.admob.adView !== undefined) {
485483
var parent = firebase.admob.adView.getParent();
@@ -493,16 +491,26 @@ firebase.admob.showBanner = function (arg) {
493491
var bannerType = firebase.admob._getBannerType(settings.size);
494492
firebase.admob.adView.setAdSize(bannerType);
495493
console.log("----- bannerType: " + bannerType);
496-
// TODO consider implementing events
497-
//firebase.admob.adView.setAdListener(new com.google.android.gms.ads.BannerListener());
494+
var BannerAdListener = com.google.android.gms.ads.AdListener.extend({
495+
onAdLoaded: function () {
496+
//firebase.admob.interstitialView.show();
497+
console.log('ad loaded');
498+
resolve();
499+
},
500+
onAdFailedToLoad: function (errorCode) {
501+
//console.log('ad error: ' + errorCode);
502+
reject(errorCode);
503+
}
504+
});
505+
firebase.admob.adView.setAdListener(new BannerAdListener());
498506

499507
var ad = firebase.admob._buildAdRequest(settings);
500508
firebase.admob.adView.loadAd(ad);
501-
509+
502510
var density = utils.layout.getDisplayDensity(),
503511
top = settings.margins.top * density,
504512
bottom = settings.margins.bottom * density;
505-
513+
506514
var relativeLayoutParams = new android.widget.RelativeLayout.LayoutParams(
507515
android.widget.RelativeLayout.LayoutParams.MATCH_PARENT,
508516
android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
@@ -528,12 +536,10 @@ firebase.admob.showBanner = function (arg) {
528536
// a Page.loaded event 'frame.topmost()' doesn't resolve to 'undefined'
529537
setTimeout(function () {
530538
frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter);
531-
}, 0);
532-
533-
resolve();
539+
}, 0);
534540
} catch (ex) {
535541
console.log("Error in firebase.admob.showBanner: " + ex);
536-
reject(ex);
542+
reject(ex);
537543
}
538544
});
539545
};

firebase.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,16 @@ export module admob {
568568
LEADERBOARD
569569
}
570570

571+
/**
572+
* The possible error codes (see https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_INTERNAL_ERROR).
573+
*/
574+
export enum ERROR_CODES {
575+
ERROR_CODE_INTERNAL_ERROR,
576+
ERROR_CODE_INVALID_REQUEST,
577+
ERROR_CODE_NETWORK_ERROR,
578+
ERROR_CODE_NO_FILL
579+
}
580+
571581
export interface ShowBannerOptions {
572582
/**
573583
* The layout of the banner.

0 commit comments

Comments
 (0)