Skip to content

Commit

Permalink
1. Bug Fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
AtikulSoftware committed Jun 30, 2024
1 parent 58bc618 commit bc8ce72
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 47 deletions.
102 changes: 59 additions & 43 deletions SmartAdmob/src/main/java/com/bdtopcoder/smartadmob/OpenAdManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public void onActivityDestroyed(@NonNull Activity activity) {
}

public void loadAd(@NonNull Activity activity) {
appOpenAdManager.loadAd(activity);
if (AdmobAdUnit.ADMOB_AD_IS_ON) {
appOpenAdManager.loadAd(activity);
}
}

public void showAdIfAvailable(
Expand All @@ -91,7 +93,6 @@ private class AppOpenAdManager {

GoogleMobileAdsConsentManager googleMobileAdsConsentManager =
GoogleMobileAdsConsentManager.getInstance(getApplicationContext());
// AppOpenAd appOpenAd = null;
boolean isLoadingAd = false;
boolean isShowingAd = false;

Expand Down Expand Up @@ -128,6 +129,7 @@ public void onAdFailedToLoad(LoadAdError loadAdError) {
// Log.d(LOG_TAG, "onAdFailedToLoad: " + loadAdError.getMessage());
}
});

}

private boolean wasLoadTimeLessThanNHoursAgo(long numHours) {
Expand All @@ -154,56 +156,70 @@ public void onShowAdComplete() {
private void showAdIfAvailable(
@NonNull final Activity activity,
@NonNull OnShowAdCompleteListener onShowAdCompleteListener) {
if (isShowingAd) {
// Log.d(LOG_TAG, "The app open ad is already showing.");
return;
}

if (!isAdAvailable()) {
// Log.d(LOG_TAG, "The app open ad is not ready yet.");
onShowAdCompleteListener.onShowAdComplete();
if (googleMobileAdsConsentManager.canRequestAds()) {
loadAd(currentActivity);
if (AdmobAdUnit.ADMOB_AD_IS_ON) {
if (isShowingAd) {
// Log.d(LOG_TAG, "The app open ad is already showing.");
return;
}
return;
}

Log.d(LOG_TAG, "Will show ad.");
if (!isAdAvailable()) {
// Log.d(LOG_TAG, "The app open ad is not ready yet.");
onShowAdCompleteListener.onShowAdComplete();
if (googleMobileAdsConsentManager.canRequestAds()) {
if (AdmobAdUnit.ADMOB_AD_IS_ON) {
loadAd(currentActivity);
}

AdmobAdUnit.openAd.setFullScreenContentCallback(
new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
AdmobAdUnit.openAd = null;
isShowingAd = false;
// Log.d(LOG_TAG, "onAdDismissedFullScreenContent.");

onShowAdCompleteListener.onShowAdComplete();
if (googleMobileAdsConsentManager.canRequestAds()) {
loadAd(activity);
}
return;
}

Log.d(LOG_TAG, "Will show ad.");

AdmobAdUnit.openAd.setFullScreenContentCallback(
new FullScreenContentCallback() {
@Override
public void onAdDismissedFullScreenContent() {
AdmobAdUnit.openAd = null;
isShowingAd = false;
// Log.d(LOG_TAG, "onAdDismissedFullScreenContent.");

onShowAdCompleteListener.onShowAdComplete();
if (googleMobileAdsConsentManager.canRequestAds()) {
if (AdmobAdUnit.ADMOB_AD_IS_ON) {
loadAd(activity);
}

}
}
}

@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
AdmobAdUnit.openAd = null;
isShowingAd = false;
// Log.d(LOG_TAG, "onAdFailedToShowFullScreenContent: " + adError.getMessage());

onShowAdCompleteListener.onShowAdComplete();
if (googleMobileAdsConsentManager.canRequestAds()) {
loadAd(activity);
@Override
public void onAdFailedToShowFullScreenContent(AdError adError) {
AdmobAdUnit.openAd = null;
isShowingAd = false;
// Log.d(LOG_TAG, "onAdFailedToShowFullScreenContent: " + adError.getMessage());

onShowAdCompleteListener.onShowAdComplete();
if (googleMobileAdsConsentManager.canRequestAds()) {
if (AdmobAdUnit.ADMOB_AD_IS_ON) {
loadAd(activity);
}

}
}
}

@Override
public void onAdShowedFullScreenContent() {
// Log.d(LOG_TAG, "onAdShowedFullScreenContent.");
}
});
@Override
public void onAdShowedFullScreenContent() {
// Log.d(LOG_TAG, "onAdShowedFullScreenContent.");
}
});

isShowingAd = true;
AdmobAdUnit.openAd.show(activity);
isShowingAd = true;
AdmobAdUnit.openAd.show(activity);
} else {
onShowAdCompleteListener.onShowAdComplete();
}
}
} // AppOpenAdManager end here =======

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.bdtopcoder.smartadmob;

public interface SplashOpenAdCallBack {
void loadingTimer(long time);
default void loadingTimer(long time){}

void loadingDone(boolean isDone);
default void loadingDone(boolean isDone){}

void startYourActivity();
default void startYourActivity(){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ protected void onCreate(Bundle savedInstanceState) {

tvTime = findViewById(R.id.tvTime);

AdmobAdUnit.ADMOB_AD_IS_ON = true;
AdmobAdUnit.ADMOB_OPEN_AD = "ca-app-pub-3940256099942544/9257395921";
splashManager = new SplashManager(SplashScreen.this, new SplashOpenAdCallBack() {
@Override
Expand All @@ -44,5 +45,4 @@ public void startYourActivity() {
} // OnCreate method end here ========



} // public class end here ===============

0 comments on commit bc8ce72

Please sign in to comment.