AdContainerView is a simple, lifecycle aware wrapper over Google AdMob's AdView (Banner Ad) for a plug & play use-case.
For the simplest use:
You just need to add AdContainerView in your layout, define adUnitId, adSize & that's it!
AdContainerView hooks to your Activity's lifecycle process & handles AdView's lifecycle (Resume, Pause, Destroy Ad).
This is most helpful when you just want to add a simple Banner Ad without any boilerplate.
AdContainerView is now on mavenCentral(),
Make sure to add that to your repositories block.
Gradle
implementation 'com.lazygeniouz:acv:$latest_version'Maven
<dependency>
    <groupId>com.lazygeniouz</groupId>
    <artifactId>acv</artifactId>
    <version>$latest_version</version>
    <type>aar</type>
</dependency><com.lazygeniouz.acv.AdContainerView 
    android:id="@+id/adContainerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:acv_autoLoad="true"
    app:acv_adSize="ADAPTIVE"
    app:acv_adUnitId="@string/test_ad"/>The attributes are as follows:
- 
acv_autoLoad: Default Value isfalse
Iftrue, the AdView will be loaded as soon as the Activity is created. - 
acv_adSize: Default Value isADAPTIVEwhich equals toAdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize().
Define an AdSize for the the AdView, check AdSize. - 
acv_adUnitId: Define anadUnitIdfor the Banner AdView from your AdMob dashboard. 
val adContainerView = AdContainerView(this@MainActivity)
adContainerView.loadAdView(adUnitId, adSize, adRequest)
parentLayout.addView(adContainerView)Loading the Ad:
fun loadAdView(
    adUnitId: String,
    adSize: AdSize,
    adRequest: AdRequest,
    parentHasListView: Boolean,
    showOnCondition: (() -> Boolean)? = null
)- The arguments 
adSize&adRequestare optional\ - The default value of parameter 
adSizeisADAPTIVE.\ - Pass your 
AdRequestif you have a customized request.\ - Pass 
trueif AdContainerView is added inside a list (RecyclerView, List / GridView).
If you don't do this & the parent view group is a List, it will be destroyed. - Pass you condition to evaluate whether to show the Ad or not (Default is Null).
 
All other methods:
- 
@Nullable getAdView(): Returns the underlyingAdView, can be@nullif called beforeloadAdView(). - 
isLoading(): Boolean: Returnstrueif the Ad is currently loading,falseotherwise. - 
isAdLoaded(): Boolean: Returnstrueif the Ad is loaded,falseotherwise. - 
isVisible(): Boolean: Returnstrueif the Ad is loaded, not null & visible,falseotherwise. - 
getAdSize(): Returns currentadSize. - 
getAdUnitId(): Returns currentadUnitId. - 
setAdListener(listener: AdListener): Use the AdView'sAdListener. - 
@Nullable getAdListener(): Returns the Listener if set, null otherwise. - 
removeAd(): Removes the AdView. Make sure to callloadAdView()to re-addAdView. - 
resumeAd(): Resumes AdView (Handled automatically) - 
pauseAd(): Pauses AdView (Handled automatically) - 
destroyAd(): Destroys AdView (Handled automatically)