Skip to content

Commit

Permalink
feat(multi-format): configure multi-format #393
Browse files Browse the repository at this point in the history
Remove useless constructors in InterstitialAdUnit. Refactored InterstitialAdUnit. Convert AdUnitFormat array to enum set.
  • Loading branch information
ValentinPostindustria committed Mar 28, 2022
1 parent 7860982 commit 1cc7d24
Show file tree
Hide file tree
Showing 16 changed files with 278 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.prebid.mobile.prebidkotlindemo.ads.inappmopub.InAppMoPubInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.inappmopub.InAppMoPubRewardedInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.inappmopub.InAppMoPubVideoInterstitial
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import java.util.*

object AdTypesRepository {

Expand Down Expand Up @@ -298,7 +299,7 @@ object AdTypesRepository {
activity,
"ca-app-pub-1875909575462531/6393291067",
"5a4b8dcf-f984-4b04-9448-6529908d6cb6",
AdUnitFormat.DISPLAY
EnumSet.of(AdUnitFormat.DISPLAY)
)
},
onDestroy = { InAppAdMobInterstitial.destroy() }
Expand All @@ -310,7 +311,7 @@ object AdTypesRepository {
activity,
"ca-app-pub-1875909575462531/6393291067",
"12f58bc2-b664-4672-8d19-638bcc96fd5c",
AdUnitFormat.VIDEO
EnumSet.of(AdUnitFormat.VIDEO)
)
},
onDestroy = { InAppAdMobInterstitial.destroy() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ object InAppInterstitial {
private var adUnit: InterstitialAdUnit? = null

fun create(context: Context, minPercentageWidth: Int, minPercentageHeight: Int, configId: String) {
adUnit = InterstitialAdUnit(context, configId, AdSize(minPercentageWidth, minPercentageHeight))
adUnit = InterstitialAdUnit(context, configId)
adUnit?.setMinSizePercentage(AdSize(minPercentageWidth, minPercentageHeight))
adUnit?.setInterstitialAdUnitListener(object : InterstitialAdUnitListener {
override fun onAdLoaded(interstitialAdUnit: InterstitialAdUnit?) {
adUnit?.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import org.prebid.mobile.rendering.bidding.listeners.InterstitialAdUnitListener
import org.prebid.mobile.rendering.bidding.parallel.InterstitialAdUnit
import org.prebid.mobile.rendering.errors.AdException
import java.util.*

object InAppVideoInterstitial {

private var adUnit: InterstitialAdUnit? = null

fun create(context: Context, configId: String) {
adUnit = InterstitialAdUnit(context, configId, AdUnitFormat.VIDEO)
adUnit = InterstitialAdUnit(context, configId, EnumSet.of(AdUnitFormat.VIDEO))
adUnit?.setInterstitialAdUnitListener(object : InterstitialAdUnitListener {
override fun onAdLoaded(interstitialAdUnit: InterstitialAdUnit?) {
adUnit?.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.prebid.mobile.admob.AdMobInterstitialMediationUtils
import org.prebid.mobile.admob.PrebidInterstitialAdapter
import org.prebid.mobile.rendering.bidding.display.MediationInterstitialAdUnit
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import java.util.*

object InAppAdMobInterstitial {

Expand All @@ -21,7 +22,7 @@ object InAppAdMobInterstitial {
activity: Activity,
adUnitId: String,
configId: String,
adUnitFormat: AdUnitFormat
adUnitFormats: EnumSet<AdUnitFormat>
) {
val extras = Bundle()
val request = AdRequest
Expand All @@ -33,7 +34,7 @@ object InAppAdMobInterstitial {
adUnit = MediationInterstitialAdUnit(
activity,
configId,
listOf(adUnitFormat),
adUnitFormats,
mediationUtils
)
adUnit?.fetchDemand { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ object InAppGamInterstitial {
configId: String
) {
val eventHandler = GamInterstitialEventHandler(activity, adUnitId)
adUnit = InterstitialAdUnit(activity, configId, AdSize(minPercentageWidth, minPercentageHeight), eventHandler)
adUnit = InterstitialAdUnit(activity, configId, eventHandler)
adUnit?.setMinSizePercentage(AdSize(minPercentageWidth, minPercentageHeight))
adUnit?.setInterstitialAdUnitListener(object : InterstitialAdUnitListener {
override fun onAdLoaded(interstitialAdUnit: InterstitialAdUnit?) {
adUnit?.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import org.prebid.mobile.rendering.bidding.listeners.InterstitialAdUnitListener
import org.prebid.mobile.rendering.bidding.parallel.InterstitialAdUnit
import org.prebid.mobile.rendering.errors.AdException
import java.util.*

object InAppGamVideoInterstitial {

private var adUnit: InterstitialAdUnit? = null

fun create(activity: Activity, adUnitId: String, configId: String) {
val eventHandler = GamInterstitialEventHandler(activity, adUnitId)
adUnit = InterstitialAdUnit(activity, configId, AdUnitFormat.VIDEO, eventHandler)
adUnit = InterstitialAdUnit(activity, configId, EnumSet.of(AdUnitFormat.VIDEO), eventHandler)
adUnit?.setInterstitialAdUnitListener(object : InterstitialAdUnitListener {
override fun onAdLoaded(interstitialAdUnit: InterstitialAdUnit?) {
adUnit?.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.mopub.mobileads.MoPubErrorCode
import com.mopub.mobileads.MoPubInterstitial
import org.prebid.mobile.rendering.bidding.display.MediationInterstitialAdUnit
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import java.util.*

object InAppMoPubInterstitial {

Expand Down Expand Up @@ -38,7 +39,7 @@ object InAppMoPubInterstitial {
adUnit = MediationInterstitialAdUnit(
activity,
configId,
listOf(AdUnitFormat.DISPLAY),
EnumSet.of(AdUnitFormat.DISPLAY),
mediationUtils
)
adUnit?.setMinSizePercentage(minPercentageWidth, minPercentageHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.mopub.mobileads.MoPubErrorCode
import com.mopub.mobileads.MoPubInterstitial
import org.prebid.mobile.rendering.bidding.display.MediationInterstitialAdUnit
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import java.util.*

object InAppMoPubVideoInterstitial {

Expand Down Expand Up @@ -38,7 +39,7 @@ object InAppMoPubVideoInterstitial {
adUnit = MediationInterstitialAdUnit(
activity,
configId,
listOf(AdUnitFormat.VIDEO),
EnumSet.of(AdUnitFormat.VIDEO),
mediationUtils
)
adUnit?.setMinSizePercentage(minPercentageWidth, minPercentageHeight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.prebid.mobile.rendering.models.AdPosition;
import org.prebid.mobile.units.configuration.AdFormat;

import java.util.List;
import java.util.EnumSet;

public class MediationInterstitialAdUnit extends MediationBaseAdUnit {

Expand All @@ -50,11 +50,11 @@ public MediationInterstitialAdUnit(
public MediationInterstitialAdUnit(
Context context,
String configId,
@NonNull List<AdUnitFormat> adUnitFormats,
@NonNull EnumSet<AdUnitFormat> adUnitFormats,
PrebidMediationDelegate mediationDelegate
) {
super(context, configId, null, mediationDelegate);
setAdUnitType(adUnitFormats);
mAdUnitConfig.setAdFormats(adUnitFormats);
}

@Override
Expand All @@ -79,14 +79,4 @@ public void setMinSizePercentage(
mAdUnitConfig.setMinSizePercentage(new AdSize(width, height));
}

private void setAdUnitType(List<AdUnitFormat> adUnitFormat) {
if (adUnitFormat.contains(AdUnitFormat.DISPLAY)) {
mAdUnitConfig.addAdFormat(AdFormat.INTERSTITIAL);
}

if (adUnitFormat.contains(AdUnitFormat.VIDEO)) {
mAdUnitConfig.addAdFormat(AdFormat.VAST);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.prebid.mobile.rendering.bidding.listeners.InterstitialEventListener;

public class StandaloneInterstitialEventHandler implements InterstitialEventHandler {

private InterstitialEventListener mInterstitialEventListener;

@Override
Expand All @@ -30,8 +31,8 @@ public void setInterstitialEventListener(InterstitialEventListener interstitialE

@Override
public void requestAdWithBid(
@Nullable
Bid bid) {
@Nullable Bid bid
) {
mInterstitialEventListener.onPrebidSdkWin();
}

Expand All @@ -49,4 +50,5 @@ public void trackImpression() {
public void destroy() {

}

}
Loading

0 comments on commit 1cc7d24

Please sign in to comment.