diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java index 32a319f57..d037bf046 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java @@ -21,6 +21,7 @@ import org.prebid.mobile.api.data.AdFormat; import org.prebid.mobile.api.data.AdUnitFormat; +import org.prebid.mobile.rendering.models.AdPosition; import java.util.EnumSet; import java.util.HashSet; @@ -77,4 +78,8 @@ public void setOrtbConfig(@Nullable String ortbConfig) { configuration.setOrtbConfig(ortbConfig); } + public void setAdPosition(AdPosition adPosition) { + configuration.setAdPosition(adPosition); + } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/data/BannerAdPosition.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/data/BannerAdPosition.java deleted file mode 100644 index 00ee3e634..000000000 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/data/BannerAdPosition.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2018-2021 Prebid.org, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.prebid.mobile.api.data; - -import org.prebid.mobile.rendering.models.AdPosition; - -/** - * Banner ad position for additional targeting. - */ -public enum BannerAdPosition { - UNDEFINED(-1), - UNKNOWN(0), - HEADER(4), - FOOTER(5), - SIDEBAR(6); - - private final int value; - - BannerAdPosition(int value) { - this.value = value; - } - - public int getValue() { - return value; - } - - public static BannerAdPosition mapToDisplayAdPosition(int adPosition) { - final BannerAdPosition[] values = BannerAdPosition.values(); - for (BannerAdPosition bannerAdPosition : values) { - if (bannerAdPosition.getValue() == adPosition) { - return bannerAdPosition; - } - } - return BannerAdPosition.UNDEFINED; - } - - public static AdPosition mapToAdPosition(BannerAdPosition bannerAdPosition) { - if (bannerAdPosition == null) { - return AdPosition.UNDEFINED; - } - - for (AdPosition adPosition : AdPosition.values()) { - if (adPosition.getValue() == bannerAdPosition.getValue()) { - return adPosition; - } - } - return AdPosition.UNDEFINED; - } -} diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBannerAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBannerAdUnit.java index f6b436c3f..003cd5322 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBannerAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBannerAdUnit.java @@ -23,7 +23,6 @@ import org.prebid.mobile.AdSize; import org.prebid.mobile.LogUtil; import org.prebid.mobile.api.data.AdFormat; -import org.prebid.mobile.api.data.BannerAdPosition; import org.prebid.mobile.api.mediation.listeners.OnFetchCompleteListener; import org.prebid.mobile.rendering.bidding.display.PrebidMediationDelegate; import org.prebid.mobile.rendering.models.AdPosition; @@ -115,13 +114,12 @@ public final void setRefreshInterval(int seconds) { adUnitConfig.setAutoRefreshDelay(seconds); } - public void setAdPosition(BannerAdPosition bannerAdPosition) { - final AdPosition adPosition = BannerAdPosition.mapToAdPosition(bannerAdPosition); + public void setAdPosition(AdPosition adPosition) { adUnitConfig.setAdPosition(adPosition); } - public BannerAdPosition getAdPosition() { - return BannerAdPosition.mapToDisplayAdPosition(adUnitConfig.getAdPositionValue()); + public AdPosition getAdPosition() { + return adUnitConfig.getAdPosition(); } public void stopRefresh() { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java index b020e92a4..da775098e 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java @@ -35,7 +35,6 @@ import org.prebid.mobile.LogUtil; import org.prebid.mobile.PrebidMobile; import org.prebid.mobile.api.data.AdFormat; -import org.prebid.mobile.api.data.BannerAdPosition; import org.prebid.mobile.api.data.VideoPlacementType; import org.prebid.mobile.api.exceptions.AdException; import org.prebid.mobile.api.rendering.listeners.BannerVideoListener; @@ -529,13 +528,12 @@ public void clearExtKeywords() { } - public void setAdPosition(BannerAdPosition bannerAdPosition) { - final AdPosition adPosition = BannerAdPosition.mapToAdPosition(bannerAdPosition); + public void setAdPosition(AdPosition adPosition) { adUnitConfig.setAdPosition(adPosition); } - public BannerAdPosition getAdPosition() { - return BannerAdPosition.mapToDisplayAdPosition(adUnitConfig.getAdPositionValue()); + public AdPosition getAdPosition() { + return adUnitConfig.getAdPosition(); } public void setPbAdSlot(String adSlot) { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java index 3ca8c41b7..55c59ac27 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java @@ -64,7 +64,8 @@ public class AdUnitConfiguration { private Position skipButtonPosition = Position.TOP_RIGHT; private AdSize minSizePercentage; private PlacementType placementType; - private AdPosition adPosition; + @NonNull + private AdPosition adPosition = AdPosition.UNDEFINED; @Nullable private ContentObject appContent; private BannerParameters bannerParameters; @@ -483,12 +484,19 @@ public boolean isPlacementTypeValid() { return getPlacementTypeValue() != PlacementType.UNDEFINED.getValue(); } - public void setAdPosition(@Nullable AdPosition adPosition) { + public void setAdPosition(AdPosition adPosition) { + if (adPosition == null) return; + this.adPosition = adPosition; } + @NonNull + public AdPosition getAdPosition() { + return adPosition; + } + public int getAdPositionValue() { - return adPosition != null ? adPosition.getValue() : AdPosition.UNDEFINED.getValue(); + return adPosition.getValue(); } public boolean isAdPositionValid() { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/AdPosition.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/AdPosition.java index cbce697a3..c899bbf92 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/AdPosition.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/AdPosition.java @@ -16,9 +16,16 @@ package org.prebid.mobile.rendering.models; +/** + * The ad position for additional targeting. + */ public enum AdPosition { + UNDEFINED(-1), UNKNOWN(0), + ABOVE_THE_FOLD(1), + LOCKED(2), + BELOW_THE_FOLD(3), HEADER(4), FOOTER(5), SIDEBAR(6), @@ -33,4 +40,5 @@ public enum AdPosition { public int getValue() { return value; } + } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java index 84ce89725..a387f3b71 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java @@ -220,6 +220,11 @@ private void appendUserTargetingParameters(AdRequestInput adRequestInput) { private void setVideoImpValues(Imp imp) { Video video = new Video(); + + if (adConfiguration.isAdPositionValid()) { + video.pos = adConfiguration.getAdPositionValue(); + } + if (adConfiguration.isOriginalAdUnit()) { VideoParameters videoParameters = adConfiguration.getVideoParameters(); if (videoParameters != null) { @@ -293,10 +298,6 @@ private void setVideoImpValues(Imp imp) { //Interstitial video specific values video.playbackend = VIDEO_INTERSTITIAL_PLAYBACK_END;//On Leaving Viewport or when Terminated by User - if (adConfiguration.isAdPositionValid()) { - video.pos = adConfiguration.getAdPositionValue(); - } - if (!adConfiguration.isPlacementTypeValid()) { video.placement = PlacementType.INTERSTITIAL.getValue(); } else { diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/AdUnitSuccessorTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/AdUnitSuccessorTest.java index be9c8f42c..1cad3302c 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/AdUnitSuccessorTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/AdUnitSuccessorTest.java @@ -31,6 +31,7 @@ import org.prebid.mobile.configuration.AdUnitConfiguration; import org.prebid.mobile.reflection.AdUnitReflection; import org.prebid.mobile.rendering.bidding.loader.BidLoader; +import org.prebid.mobile.rendering.models.AdPosition; import org.prebid.mobile.testutils.BaseSetup; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -100,6 +101,27 @@ public void testGpidParameter() { assertEquals(expectedGpid, configuration.getGpid()); } + @Test + public void adPosition_empty() { + BannerAdUnit adUnit = new BannerAdUnit(testConfigId, width, height); + + AdUnitConfiguration configuration = adUnit.getConfiguration(); + assertEquals(AdPosition.UNDEFINED, configuration.getAdPosition()); + assertEquals(AdPosition.UNDEFINED.getValue(), configuration.getAdPositionValue()); + } + + @Test + public void adPosition() { + BannerAdUnit adUnit = new BannerAdUnit(testConfigId, width, height); + adUnit.setAdPosition(AdPosition.SIDEBAR); + + AdUnitConfiguration configuration = adUnit.getConfiguration(); + assertEquals(AdPosition.SIDEBAR, configuration.getAdPosition()); + assertEquals(AdPosition.SIDEBAR.getValue(), configuration.getAdPositionValue()); + } + + + @Test public void testBannerParametersCreation() { //given diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBannerAdUnitTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBannerAdUnitTest.java index 51d54b279..8bfc65c0f 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBannerAdUnitTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBannerAdUnitTest.java @@ -27,10 +27,10 @@ import org.prebid.mobile.AdSize; import org.prebid.mobile.PrebidMobile; import org.prebid.mobile.api.data.AdFormat; -import org.prebid.mobile.api.data.BannerAdPosition; import org.prebid.mobile.configuration.AdUnitConfiguration; import org.prebid.mobile.rendering.bidding.config.MockMediationUtils; import org.prebid.mobile.rendering.bidding.loader.BidLoader; +import org.prebid.mobile.rendering.models.AdPosition; import org.prebid.mobile.rendering.utils.broadcast.ScreenStateReceiver; import org.prebid.mobile.test.utils.WhiteBox; import org.robolectric.Robolectric; @@ -64,7 +64,7 @@ public void setUp() throws Exception { WhiteBox.setInternalState(mediationBannerAdUnit, "bidLoader", mockBidLoader); WhiteBox.setInternalState(mediationBannerAdUnit, "screenStateReceiver", mockScreenStateReceiver); - assertEquals(BannerAdPosition.UNDEFINED.getValue(), mediationBannerAdUnit.getAdPosition().getValue()); + assertEquals(AdPosition.UNDEFINED.getValue(), mediationBannerAdUnit.getAdPosition().getValue()); } @After @@ -106,19 +106,19 @@ public void whenStopRefresh_BidLoaderCancelRefresh() { @Test public void setAdPosition_EqualsGetAdPosition() { mediationBannerAdUnit.setAdPosition(null); - assertEquals(BannerAdPosition.UNDEFINED, mediationBannerAdUnit.getAdPosition()); + assertEquals(AdPosition.UNDEFINED, mediationBannerAdUnit.getAdPosition()); - mediationBannerAdUnit.setAdPosition(BannerAdPosition.FOOTER); - assertEquals(BannerAdPosition.FOOTER, mediationBannerAdUnit.getAdPosition()); + mediationBannerAdUnit.setAdPosition(AdPosition.FOOTER); + assertEquals(AdPosition.FOOTER, mediationBannerAdUnit.getAdPosition()); - mediationBannerAdUnit.setAdPosition(BannerAdPosition.HEADER); - assertEquals(BannerAdPosition.HEADER, mediationBannerAdUnit.getAdPosition()); + mediationBannerAdUnit.setAdPosition(AdPosition.HEADER); + assertEquals(AdPosition.HEADER, mediationBannerAdUnit.getAdPosition()); - mediationBannerAdUnit.setAdPosition(BannerAdPosition.SIDEBAR); - assertEquals(BannerAdPosition.SIDEBAR, mediationBannerAdUnit.getAdPosition()); + mediationBannerAdUnit.setAdPosition(AdPosition.SIDEBAR); + assertEquals(AdPosition.SIDEBAR, mediationBannerAdUnit.getAdPosition()); - mediationBannerAdUnit.setAdPosition(BannerAdPosition.UNKNOWN); - assertEquals(BannerAdPosition.UNKNOWN, mediationBannerAdUnit.getAdPosition()); + mediationBannerAdUnit.setAdPosition(AdPosition.UNKNOWN); + assertEquals(AdPosition.UNKNOWN, mediationBannerAdUnit.getAdPosition()); } } \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBaseAdUnitTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBaseAdUnitTest.java index 612c23573..b4fe7da01 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBaseAdUnitTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/mediation/MediationBaseAdUnitTest.java @@ -27,12 +27,12 @@ import org.prebid.mobile.AdSize; import org.prebid.mobile.Host; import org.prebid.mobile.PrebidMobile; -import org.prebid.mobile.api.data.BannerAdPosition; import org.prebid.mobile.api.data.FetchDemandResult; import org.prebid.mobile.api.exceptions.AdException; import org.prebid.mobile.api.mediation.listeners.OnFetchCompleteListener; import org.prebid.mobile.rendering.bidding.config.MockMediationUtils; import org.prebid.mobile.rendering.bidding.loader.BidLoader; +import org.prebid.mobile.rendering.models.AdPosition; import org.prebid.mobile.test.utils.WhiteBox; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; @@ -68,7 +68,7 @@ public void setUp() throws Exception { baseAdUnit = createAdUnit("config"); PrebidMobile.setPrebidServerHost(Host.APPNEXUS); - assertEquals(BannerAdPosition.UNDEFINED.getValue(), baseAdUnit.adUnitConfig.getAdPositionValue()); + assertEquals(AdPosition.UNDEFINED.getValue(), baseAdUnit.adUnitConfig.getAdPositionValue()); } @After diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/rendering/BannerViewTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/rendering/BannerViewTest.java index 50277fd1c..6f13f4788 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/rendering/BannerViewTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/api/rendering/BannerViewTest.java @@ -28,7 +28,6 @@ import org.mockito.MockitoAnnotations; import org.prebid.mobile.AdSize; import org.prebid.mobile.api.data.AdFormat; -import org.prebid.mobile.api.data.BannerAdPosition; import org.prebid.mobile.api.data.VideoPlacementType; import org.prebid.mobile.api.exceptions.AdException; import org.prebid.mobile.api.rendering.listeners.BannerVideoListener; @@ -43,6 +42,7 @@ import org.prebid.mobile.rendering.bidding.listeners.DisplayVideoListener; import org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener; import org.prebid.mobile.rendering.bidding.loader.BidLoader; +import org.prebid.mobile.rendering.models.AdPosition; import org.prebid.mobile.rendering.utils.broadcast.ScreenStateReceiver; import org.prebid.mobile.test.utils.WhiteBox; import org.robolectric.Robolectric; @@ -94,7 +94,7 @@ public void setup() throws Exception { bannerView.setBannerListener(mockBannerListener); bannerView.setBannerVideoListener(mockBannerVideoListener); - assertEquals(BannerAdPosition.UNDEFINED.getValue(), bannerView.getAdPosition().getValue()); + assertEquals(AdPosition.UNDEFINED.getValue(), bannerView.getAdPosition().getValue()); } @Test @@ -496,19 +496,19 @@ public void addRemoveContextKeywords_EqualsGetContextKeyWordsSet() { @Test public void setAdPosition_EqualsGetAdPosition() { bannerView.setAdPosition(null); - assertEquals(BannerAdPosition.UNDEFINED, bannerView.getAdPosition()); + assertEquals(AdPosition.UNDEFINED, bannerView.getAdPosition()); - bannerView.setAdPosition(BannerAdPosition.FOOTER); - assertEquals(BannerAdPosition.FOOTER, bannerView.getAdPosition()); + bannerView.setAdPosition(AdPosition.FOOTER); + assertEquals(AdPosition.FOOTER, bannerView.getAdPosition()); - bannerView.setAdPosition(BannerAdPosition.HEADER); - assertEquals(BannerAdPosition.HEADER, bannerView.getAdPosition()); + bannerView.setAdPosition(AdPosition.HEADER); + assertEquals(AdPosition.HEADER, bannerView.getAdPosition()); - bannerView.setAdPosition(BannerAdPosition.SIDEBAR); - assertEquals(BannerAdPosition.SIDEBAR, bannerView.getAdPosition()); + bannerView.setAdPosition(AdPosition.SIDEBAR); + assertEquals(AdPosition.SIDEBAR, bannerView.getAdPosition()); - bannerView.setAdPosition(BannerAdPosition.UNKNOWN); - assertEquals(BannerAdPosition.UNKNOWN, bannerView.getAdPosition()); + bannerView.setAdPosition(AdPosition.UNKNOWN); + assertEquals(AdPosition.UNKNOWN, bannerView.getAdPosition()); } @Test