Skip to content

Commit 8005c7b

Browse files
committed
ReadMe update, added support for showOnCondition: (() -> Boolean)?
1 parent 844ee23 commit 8005c7b

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

Readme.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,18 @@ parentLayout.addView(adContainerView)
5959
// And thats it!
6060
```
6161
**All Methods:**
62-
* `insertAdView(@NonNull adUnitId, adSize, adRequest)`:\
63-
The arguments `adSize` & `adRequest` are optional\
64-
The default value of parameter `adSize` is `ADAPTIVE`.\
65-
Pass your `AdRequest` if you have a customized request.
62+
```kotlin
63+
fun insertAdView(
64+
@NonNull adUnitId: String,
65+
adSize: AdSize,
66+
adRequest: AdRequest),
67+
showOnCondition: (() -> Boolean)? = null
68+
)
69+
```
70+
The arguments `adSize` & `adRequest` are optional\
71+
The default value of parameter `adSize` is `ADAPTIVE`.\
72+
Pass your `AdRequest` if you have a customized request.\
73+
Pass you condition to evaluate whether to show the Ad or not (Default is Null).
6674

6775
* `isLoading(): Boolean`: Returns `true` if the Ad is currently loading, `false` otherwise.
6876

acv/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ android {
1616
defaultConfig {
1717
minSdkVersion 16
1818
targetSdkVersion 31
19-
versionCode 21
20-
versionName "0.2.1"
19+
versionCode 22
20+
versionName "0.2.2"
2121
}
2222

2323
buildTypes {

acv/src/main/java/com/lazygeniouz/acv/AdContainerView.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,24 @@ class AdContainerView @JvmOverloads constructor(
5252
fun insertAdView(
5353
@NonNull adUnitId: String = this.adUnitId,
5454
adSize: AdSize = this.adSize,
55-
adRequest: AdRequest = this.getAdRequest()
55+
adRequest: AdRequest = this.getAdRequest(),
56+
showOnCondition: (() -> Boolean)? = null
5657
) {
5758
if (adUnitId == TEST_AD_ID) Log.i(
58-
tag,
59-
"Current adUnitId is a Test Ad Unit, make sure to use your own in Production"
59+
tag, "Current adUnitId is a Test Ad Unit, make sure to use your own in Production"
6060
)
6161

62+
if (showOnCondition?.invoke() == false) {
63+
Log.d(tag, showOnConditionMessage)
64+
listener?.onAdFailedToLoad(
65+
LoadAdError(
66+
-1, showOnConditionMessage,
67+
tag, null, null
68+
)
69+
)
70+
return
71+
}
72+
6273
removeAllViews()
6374
newAdView = AdView(context)
6475
newAdView!!.visibility = View.GONE

acv/src/main/java/com/lazygeniouz/acv/base/BaseAd.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ open class BaseAd @JvmOverloads constructor(
3030
) : RelativeLayout(context, attrs, defStyleAttr) {
3131

3232
internal val tag = javaClass.simpleName
33+
internal val showOnConditionMessage =
34+
"showOnCondition lambda returned false, AdContainerView will not load an Ad."
3335

3436
protected var autoLoad = false
3537
internal var isAdLoaded = false
@@ -74,7 +76,7 @@ open class BaseAd @JvmOverloads constructor(
7476
/**
7577
* Return whether the Ad is loaded or not
7678
*/
77-
fun isAdLoaded(): Boolean = isAdLoaded
79+
fun isAdLoaded() = isAdLoaded
7880

7981
/**
8082
* Return the Ad's Loading State.

0 commit comments

Comments
 (0)