Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update yandex adapter for 6.2.0 support #588

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Yandex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 6.2.0.0
* Certified with Yandex SDK 6.2.0.

## 6.1.0.0
* Certified with Yandex SDK 6.1.0.

Expand Down
2 changes: 1 addition & 1 deletion Yandex/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

private val versionMajor = 6
private val versionMinor = 1
private val versionMinor = 2
private val versionPatch = 0
private val versionAdapterPatch = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import com.yandex.mobile.ads.common.AdRequest;
import com.yandex.mobile.ads.common.AdRequestConfiguration;
import com.yandex.mobile.ads.common.AdRequestError;
import com.yandex.mobile.ads.common.AdType;
import com.yandex.mobile.ads.common.BidderTokenLoadListener;
import com.yandex.mobile.ads.common.BidderTokenLoader;
import com.yandex.mobile.ads.common.BidderTokenRequestConfiguration;
import com.yandex.mobile.ads.common.ImpressionData;
import com.yandex.mobile.ads.common.InitializationListener;
import com.yandex.mobile.ads.common.MobileAds;
Expand Down Expand Up @@ -156,7 +158,7 @@ public void initialize(final MaxAdapterInitializationParameters parameters, fina

status = InitializationStatus.INITIALIZING;

updateUserConsent( parameters );
updatePrivacySettings( parameters );

if ( parameters.isTesting() )
{
Expand Down Expand Up @@ -196,9 +198,11 @@ public void collectSignal(final MaxAdapterSignalCollectionParameters parameters,
{
log( "Collecting signal..." );

updateUserConsent( parameters );
updatePrivacySettings( parameters );

BidderTokenLoader.loadBidderToken( activity, new BidderTokenLoadListener()
BidderTokenRequestConfiguration bidderTokenRequest = createBidderTokenRequestConfiguration( activity, parameters.getAdFormat() );

BidderTokenLoader.loadBidderToken( activity, bidderTokenRequest, new BidderTokenLoadListener()
{
@Override
public void onBidderTokenLoaded(@NonNull final String bidderToken)
Expand Down Expand Up @@ -239,7 +243,7 @@ public void loadInterstitialAd(final MaxAdapterResponseParameters parameters, fi
return;
}

updateUserConsent( parameters );
updatePrivacySettings( parameters );

Runnable loadInterstitialAdRunnable = new Runnable()
{
Expand Down Expand Up @@ -293,7 +297,7 @@ public void loadRewardedAd(final MaxAdapterResponseParameters parameters, final
return;
}

updateUserConsent( parameters );
updatePrivacySettings( parameters );

Runnable loadRewardedAdRunnable = new Runnable()
{
Expand Down Expand Up @@ -342,7 +346,7 @@ public void loadAdViewAd(final MaxAdapterResponseParameters parameters, final Ma

final Context applicationContext = getContext( activity );

updateUserConsent( parameters );
updatePrivacySettings( parameters );

Runnable loadAdViewAdRunnable = new Runnable()
{
Expand Down Expand Up @@ -373,7 +377,7 @@ public void loadNativeAd(final MaxAdapterResponseParameters parameters, final Ac

final Context applicationContext = getContext( activity );

updateUserConsent( parameters );
updatePrivacySettings( parameters );

Runnable loadNativeAdRunnable = new Runnable()
{
Expand Down Expand Up @@ -417,13 +421,19 @@ private void loadAdOnUiThread(final Runnable loadOrShowRunnable)
}
}

private void updateUserConsent(final MaxAdapterParameters parameters)
private void updatePrivacySettings(final MaxAdapterParameters parameters)
{
Boolean hasUserConsent = parameters.hasUserConsent();
if ( hasUserConsent != null )
{
MobileAds.setUserConsent( hasUserConsent );
}

Boolean isAgeRestrictedUser = parameters.isAgeRestrictedUser();
if ( isAgeRestrictedUser != null )
{
MobileAds.setAgeRestrictedUser( isAgeRestrictedUser );
}
}

private AdRequest createAdRequest(MaxAdapterResponseParameters parameters)
Expand All @@ -442,6 +452,33 @@ private AdRequestConfiguration createAdRequestConfiguration(final String placeme
.build();
}

private BidderTokenRequestConfiguration createBidderTokenRequestConfiguration(final Context context, final MaxAdFormat adFormat) {
AdType adType = toAdType( adFormat );
BidderTokenRequestConfiguration.Builder requestBuilder = new BidderTokenRequestConfiguration.Builder( adType );

if (adType == AdType.BANNER) {
requestBuilder.setBannerAdSize( toBannerAdSize( adFormat, context ) );
}

return requestBuilder.setParameters(adRequestParameters).build();
}

private static AdType toAdType(final MaxAdFormat adFormat) {
if (adFormat.isAdViewAd()) {
return AdType.BANNER;
} else if (adFormat == MaxAdFormat.INTERSTITIAL) {
return AdType.INTERSTITIAL;
} else if (adFormat == MaxAdFormat.REWARDED || adFormat == MaxAdFormat.REWARDED_INTERSTITIAL) {
return AdType.REWARDED;
} else if (adFormat == MaxAdFormat.APP_OPEN) {
return AdType.APP_OPEN_AD;
} else if (adFormat == MaxAdFormat.NATIVE) {
return AdType.NATIVE;
} else {
return AdType.UNKNOWN;
}
}

private static BannerAdSize toBannerAdSize(final MaxAdFormat adFormat, final Context context)
{
if ( adFormat == MaxAdFormat.BANNER )
Expand Down