All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.applovin.mediation.adapters.prebid.utils.MaxMediationBannerUtils Maven / Gradle / Ivy

There is a newer version: 2.2.3
Show newest version
package com.applovin.mediation.adapters.prebid.utils;

import android.util.Log;
import androidx.annotation.Nullable;
import com.applovin.mediation.adapters.PrebidMaxMediationAdapter;
import com.applovin.mediation.ads.MaxAdView;
import org.prebid.mobile.LogUtil;
import org.prebid.mobile.rendering.bidding.data.bid.BidResponse;
import org.prebid.mobile.rendering.bidding.display.PrebidMediationDelegate;
import org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption;
import org.prebid.mobile.rendering.models.ntv.NativeEventTracker;
import org.prebid.mobile.rendering.utils.helpers.VisibilityChecker;

import java.lang.ref.WeakReference;
import java.util.HashMap;

public class MaxMediationBannerUtils implements PrebidMediationDelegate {

    private static final String TAG = MaxMediationBannerUtils.class.getSimpleName();

    private final WeakReference adViewReference;

    public MaxMediationBannerUtils(MaxAdView adView) {
        adViewReference = new WeakReference<>(adView);
    }

    @Override
    public void setResponseToLocalExtras(@Nullable BidResponse response) {
        if (adViewReference.get() != null) {
            String responseId; if (response != null) {
                responseId = response.getId();
            } else {
                responseId = null;
            } adViewReference.get().setLocalExtraParameter(PrebidMaxMediationAdapter.EXTRA_RESPONSE_ID, responseId);
        }
    }

    @Override
    public boolean canPerformRefresh() {
        MaxAdView view = adViewReference.get();
        if (view == null) {
            LogUtil.error(TAG, "AdView is null, it can be destroyed as WeakReference");
            return false;
        }

        final VisibilityTrackerOption visibilityTrackerOption = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
        final VisibilityChecker checker = new VisibilityChecker(visibilityTrackerOption);

        boolean isVisible = checker.isVisibleForRefresh(view);
        if (isVisible) {
            Log.d(TAG, "Visibility checker result: " + true);
        } else {
            Log.e(TAG, "Can't perform refresh. Ad view is not visible.");
        }
        return true;
    }

    @Override
    public void handleKeywordsUpdate(@Nullable HashMap keywords) {}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy