Skip to content

Commit

Permalink
Fix bugs: Null Exception in BannerExcutor
Browse files Browse the repository at this point in the history
  • Loading branch information
bayonmbayo committed Nov 16, 2024
1 parent 93d19e5 commit ad38a05
Showing 1 changed file with 65 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ private void updateExistingAdView(AdOptions adOptions) {
.runOnUiThread(
() -> {
final AdRequest adRequest = RequestHelper.createRequest(adOptions);
mAdView.loadAd(adRequest);
// TODO
if(mAdView != null){
mAdView.loadAd(adRequest);
}else{
Log.e(logTag, "mAdView is null, the updateExistingAdView can't be completed");
}
}
);
}
Expand All @@ -237,57 +242,68 @@ private void createNewAdView(AdOptions adOptions) {
mAdViewLayout.addView(mAdView);
// Start loading the ad.
mAdView.loadAd(adRequest);
mAdView.setAdListener(
new AdListener() {
@Override
public void onAdLoaded() {
final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(mAdView);

notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
notifyListeners(BannerAdPluginEvents.Loaded.getWebEventName(), emptyObject);
super.onAdLoaded();
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
if (mAdView != null) {
mViewGroup.removeView(mAdViewLayout);
mAdViewLayout.removeView(mAdView);
mAdView.destroy();
mAdView = null;
// TODO
if(mAdView != null){
mAdView.setAdListener(
new AdListener() {
@Override
public void onAdLoaded() {
final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(mAdView);

notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);
notifyListeners(BannerAdPluginEvents.Loaded.getWebEventName(), emptyObject);
super.onAdLoaded();
}

@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
if (mAdView != null) {
mViewGroup.removeView(mAdViewLayout);
mAdViewLayout.removeView(mAdView);
mAdView.destroy();
mAdView = null;
}

final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);

final AdMobPluginError adMobPluginError = new AdMobPluginError(adError);
notifyListeners(BannerAdPluginEvents.FailedToLoad.getWebEventName(), adMobPluginError);

super.onAdFailedToLoad(adError);
}

@Override
public void onAdOpened() {
// TODO
notifyListeners(BannerAdPluginEvents.Opened.getWebEventName(), emptyObject);
super.onAdOpened();
}

@Override
public void onAdClosed() {
notifyListeners(BannerAdPluginEvents.Closed.getWebEventName(), emptyObject);
super.onAdClosed();
}

@Override
public void onAdImpression() {
notifyListeners(BannerAdPluginEvents.AdImpression.getWebEventName(), emptyObject);
super.onAdImpression();
}
}

final BannerAdSizeInfo sizeInfo = new BannerAdSizeInfo(0, 0);
notifyListeners(BannerAdPluginEvents.SizeChanged.getWebEventName(), sizeInfo);

final AdMobPluginError adMobPluginError = new AdMobPluginError(adError);
notifyListeners(BannerAdPluginEvents.FailedToLoad.getWebEventName(), adMobPluginError);

super.onAdFailedToLoad(adError);
}

@Override
public void onAdOpened() {
notifyListeners(BannerAdPluginEvents.Opened.getWebEventName(), emptyObject);
super.onAdOpened();
}

@Override
public void onAdClosed() {
notifyListeners(BannerAdPluginEvents.Closed.getWebEventName(), emptyObject);
super.onAdClosed();
}

@Override
public void onAdImpression() {
notifyListeners(BannerAdPluginEvents.AdImpression.getWebEventName(), emptyObject);
super.onAdImpression();
}
}
);
);
} else{
Log.e(logTag, "mAdView is null, the listener can't work");
}


// Add AdViewLayout top of the WebView
mViewGroup.addView(mAdViewLayout);
if(mViewGroup != null){
mViewGroup.addView(mAdViewLayout);
}else{
Log.e(logTag, "mViewGroup is null, the initialization can't be completed");
}
}
);
}
Expand Down

0 comments on commit ad38a05

Please sign in to comment.