File tree Expand file tree Collapse file tree 4 files changed +31
-10
lines changed
src/main/java/com/lazygeniouz/acv Expand file tree Collapse file tree 4 files changed +31
-10
lines changed Original file line number Diff line number Diff line change @@ -59,10 +59,18 @@ parentLayout.addView(adContainerView)
59
59
// And thats it!
60
60
```
61
61
** 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).
66
74
67
75
* ` isLoading(): Boolean ` : Returns ` true ` if the Ad is currently loading, ` false ` otherwise.
68
76
Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ android {
16
16
defaultConfig {
17
17
minSdkVersion 16
18
18
targetSdkVersion 31
19
- versionCode 21
20
- versionName " 0.2.1 "
19
+ versionCode 22
20
+ versionName " 0.2.2 "
21
21
}
22
22
23
23
buildTypes {
Original file line number Diff line number Diff line change @@ -52,13 +52,24 @@ class AdContainerView @JvmOverloads constructor(
52
52
fun insertAdView (
53
53
@NonNull adUnitId : String = this.adUnitId,
54
54
adSize : AdSize = this.adSize,
55
- adRequest : AdRequest = this.getAdRequest()
55
+ adRequest : AdRequest = this.getAdRequest(),
56
+ showOnCondition : (() -> Boolean )? = null
56
57
) {
57
58
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"
60
60
)
61
61
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
+
62
73
removeAllViews()
63
74
newAdView = AdView (context)
64
75
newAdView!! .visibility = View .GONE
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ open class BaseAd @JvmOverloads constructor(
30
30
) : RelativeLayout(context, attrs, defStyleAttr) {
31
31
32
32
internal val tag = javaClass.simpleName
33
+ internal val showOnConditionMessage =
34
+ " showOnCondition lambda returned false, AdContainerView will not load an Ad."
33
35
34
36
protected var autoLoad = false
35
37
internal var isAdLoaded = false
@@ -74,7 +76,7 @@ open class BaseAd @JvmOverloads constructor(
74
76
/* *
75
77
* Return whether the Ad is loaded or not
76
78
*/
77
- fun isAdLoaded (): Boolean = isAdLoaded
79
+ fun isAdLoaded () = isAdLoaded
78
80
79
81
/* *
80
82
* Return the Ad's Loading State.
You can’t perform that action at this time.
0 commit comments