From 75cf8fa8804ef988f2c175ae9295d16ceacd4255 Mon Sep 17 00:00:00 2001 From: svzi Date: Tue, 3 Oct 2017 17:18:40 +0200 Subject: [PATCH 1/8] let showInterstitial() fullfil promise, when ad is closed instead of when ad is loaded --- firebase.android.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.android.js b/firebase.android.js index 921f597a..bbf629e2 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -600,7 +600,6 @@ firebase.admob.showInterstitial = function (arg) { var InterstitialAdListener = com.google.android.gms.ads.AdListener.extend({ onAdLoaded: function () { firebase.admob.interstitialView.show(); - resolve(); }, onAdFailedToLoad: function (errorCode) { reject(errorCode); @@ -608,6 +607,7 @@ firebase.admob.showInterstitial = function (arg) { onAdClosed: function () { firebase.admob.interstitialView.setAdListener(null); firebase.admob.interstitialView = null; + resolve(); } }); firebase.admob.interstitialView.setAdListener(new InterstitialAdListener()); From 22e91a6a2cf5a77ff29e1ad5244ca832395be0bf Mon Sep 17 00:00:00 2001 From: svzi Date: Wed, 4 Oct 2017 16:23:23 +0200 Subject: [PATCH 2/8] BUGFIX: preventing NullPointerException --- firebase.android.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/firebase.android.js b/firebase.android.js index bbf629e2..f9449124 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -580,7 +580,9 @@ firebase.admob.showBanner = function (arg) { // 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' setTimeout(function () { - frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter); + if (frame.topmost() && frame.topmost().currentPage && frame.topmost().currentPage.android) { + frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter); + } }, 0); } catch (ex) { console.log("Error in firebase.admob.showBanner: " + ex); From ad3832a58e95c98fe6a8b56793cb3495a7c08714 Mon Sep 17 00:00:00 2001 From: svzi Date: Wed, 4 Oct 2017 16:41:32 +0200 Subject: [PATCH 3/8] improved banner showing --- firebase.android.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/firebase.android.js b/firebase.android.js index f9449124..5467cfc1 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -577,13 +577,24 @@ firebase.admob.showBanner = function (arg) { android.widget.RelativeLayout.LayoutParams.MATCH_PARENT, android.widget.RelativeLayout.LayoutParams.MATCH_PARENT); - // 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' - setTimeout(function () { - if (frame.topmost() && frame.topmost().currentPage && frame.topmost().currentPage.android) { - frame.topmost().currentPage.android.getParent().addView(adViewLayout, relativeLayoutParamsOuter); - } - }, 0); + // 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' + var showBanner = function() { + if (frame.topmost() && frame.topmost().currentPage && frame.topmost().currentPage.android) { + frame + .topmost() + .currentPage.android.getParent() + .addView(adViewLayout, relativeLayoutParamsOuter); + } else { + console.log('trying again in 300ms...'); + setTimeout(function() { + showBanner(); + }, 300); + } + }; + setTimeout(function() { + showBanner(); + }, 0); } catch (ex) { console.log("Error in firebase.admob.showBanner: " + ex); reject(ex); From 24f7bc1e38c46b61a5b2e9602cf7d9abb61458d5 Mon Sep 17 00:00:00 2001 From: svzi Date: Wed, 4 Oct 2017 17:22:09 +0200 Subject: [PATCH 4/8] removed annoying debug-output --- firebase.android.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firebase.android.js b/firebase.android.js index 5467cfc1..23a686ff 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -535,11 +535,11 @@ firebase.admob.showBanner = function (arg) { firebase.admob.adView.setAdUnitId(settings.androidBannerId); var bannerType = firebase.admob._getBannerType(settings.size); firebase.admob.adView.setAdSize(bannerType); - console.log("----- bannerType: " + bannerType); + //console.log("----- bannerType: " + bannerType); var BannerAdListener = com.google.android.gms.ads.AdListener.extend({ onAdLoaded: function () { //firebase.admob.interstitialView.show(); - console.log('ad loaded'); + //console.log('ad loaded'); resolve(); }, onAdFailedToLoad: function (errorCode) { From f7c4d391c827e3e6b3bf98011df557310d731812 Mon Sep 17 00:00:00 2001 From: svzi Date: Wed, 4 Oct 2017 23:58:09 +0200 Subject: [PATCH 5/8] testing with interstitials --- firebase.android.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/firebase.android.js b/firebase.android.js index 23a686ff..73953aa4 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -612,13 +612,16 @@ firebase.admob.showInterstitial = function (arg) { // Interstitial ads must be loaded before they can be shown, so adding a listener var InterstitialAdListener = com.google.android.gms.ads.AdListener.extend({ onAdLoaded: function () { - firebase.admob.interstitialView.show(); + console.log('showInterstitial -> onAdLoaded'); + firebase.admob.interstitialView.show(); }, onAdFailedToLoad: function (errorCode) { - reject(errorCode); + console.log('showInterstitial -> onAdFailedToLoad'); + reject(errorCode); }, onAdClosed: function () { - firebase.admob.interstitialView.setAdListener(null); + console.log('showInterstitial -> onAdClosed'); + // firebase.admob.interstitialView.setAdListener(null); firebase.admob.interstitialView = null; resolve(); } From 1f2dbcef51f747d9d13e925a2896a486af9323de Mon Sep 17 00:00:00 2001 From: svzi Date: Thu, 5 Oct 2017 00:08:35 +0200 Subject: [PATCH 6/8] testing with interstitials #2 --- firebase.android.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firebase.android.js b/firebase.android.js index 73953aa4..6d081688 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -620,9 +620,10 @@ firebase.admob.showInterstitial = function (arg) { reject(errorCode); }, onAdClosed: function () { - console.log('showInterstitial -> onAdClosed'); - // firebase.admob.interstitialView.setAdListener(null); + console.log('showInterstitial -> onAdClosed #1'); + firebase.admob.interstitialView.setAdListener(null); firebase.admob.interstitialView = null; + console.log('showInterstitial -> onAdClosed #2'); resolve(); } }); From 41741a0538539ffd245b12fa7ded4a603f255ab1 Mon Sep 17 00:00:00 2001 From: svzi Date: Fri, 6 Oct 2017 16:35:32 +0200 Subject: [PATCH 7/8] fixed one more possible NPE --- firebase.android.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.android.js b/firebase.android.js index 6d081688..1c349cd0 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -580,7 +580,7 @@ firebase.admob.showBanner = function (arg) { // 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' var showBanner = function() { - if (frame.topmost() && frame.topmost().currentPage && frame.topmost().currentPage.android) { + if (frame.topmost() && frame.topmost().currentPage && frame.topmost().currentPage.android && frame.topmost().currentPage.android.getParent()) { frame .topmost() .currentPage.android.getParent() From 05451f88af5f7cc7f4062c6f0bc5c39090ff0c61 Mon Sep 17 00:00:00 2001 From: svzi Date: Sat, 7 Oct 2017 11:27:06 +0200 Subject: [PATCH 8/8] more banner handling improvements --- firebase.android.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/firebase.android.js b/firebase.android.js index 1c349cd0..880221ed 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -579,17 +579,22 @@ firebase.admob.showBanner = function (arg) { // 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' - var showBanner = function() { + var showBanner = function(counter) { if (frame.topmost() && frame.topmost().currentPage && frame.topmost().currentPage.android && frame.topmost().currentPage.android.getParent()) { frame .topmost() .currentPage.android.getParent() .addView(adViewLayout, relativeLayoutParamsOuter); } else { - console.log('trying again in 300ms...'); - setTimeout(function() { - showBanner(); - }, 300); + if (counter === undefined) { + counter = 1; + } else if (counter < 5) { + var delay = Number(counter * 300); + console.log('trying again in ' + delay + ' ms...'); + setTimeout(function() { + showBanner(counter++); + }, delay); + } } }; setTimeout(function() {