Skip to content

Commit

Permalink
Introduce Applovin MAX adapters (#421)
Browse files Browse the repository at this point in the history
* Create Applovin Max banner adapter and configure environment  (#416)

* feat(max-adapters): create max adapters module #401

* feat(max-adapters): add max page into Internal test app #401

* feat(max-adapters): connect banner example to Kotlin app #401

* feat(max-adapters): create max banner adapter #401

* Create interstitial and rewarded MAX adapters (#418)

* feat(max-adapters): create interstitial and rewarded adapters #404, #405

Add examples to Kotlin app.

* feat(max-adapters): move listeners to different files #404, #405

* Create native MAX adapter and change architecture (#419)

* feat(max-adapters): create native adapter #406

Add example to native app.

* feat(max-adapters): change max adapters architecture

Move files to packages. Create managers for separating different ad types logic.

* feat(max-adapters): use unified parameters matcher

* feat(max-adapters): create tests for ParametersChecker

* feat(max-adapters): use unified name convention for adapters

* feat(max-adapters): fix tests

* Add MAX examples to internal test app (#420)

* feat(max-adapters): add MREC example to Kotlin app #407

* feat(max-adapters): remove applovin ad review gradle plugin

* feat(max-adapters): add banner examples to Internal test app #407

* feat(max-adapters): add interstitial and rewarded examples to Internal test app #404, #405

Add cleaning response id. Fix not correct check for ad type in MaxInterstitialManager. Add rewarded callbacks.

* feat(max-adapters): add native examples to Internal test app #406

* feat(max-adapters): fix kotlin app dependencies
  • Loading branch information
ValentinPostindustria authored Apr 18, 2022
1 parent 7962804 commit fa0872b
Show file tree
Hide file tree
Showing 72 changed files with 3,541 additions and 186 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ captures/

# Keystore files
*.jks

# Applovin Max Ad Review plugin
.safedk/
6 changes: 4 additions & 2 deletions Example/PrebidDemoKotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
Expand Down Expand Up @@ -35,11 +33,13 @@ dependencies {
implementation project(':PrebidMobile')
implementation project(':PrebidMobile-gamEventHandlers')
implementation project(':PrebidMobile-admobAdapters')
implementation project(':PrebidMobile-maxAdapters')

// For testing staging releases
// implementation 'org.prebid:prebid-mobile-sdk:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-gam-event-handlers:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-admob-adapters:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-max-adapters:1.13.0-beta2'

// Standard libraries
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand All @@ -48,6 +48,8 @@ dependencies {

// Advertisement
implementation 'com.google.android.gms:play-services-ads:20.4.0'
implementation "com.applovin:applovin-sdk:11.3.2"
implementation "com.google.android.gms:play-services-ads-identifier:18.0.1" // For Applovin Max


// Multidex
Expand Down
18 changes: 11 additions & 7 deletions Example/PrebidDemoKotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-1875909575462531~6255590079"/>
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-1875909575462531~6255590079" />

<meta-data
android:name="applovin.sdk.key"
android:value="1tLUnP4cVQqpHuHH2yMtfdESvvUhTB05NdbCoDTceDDNVnhd_T8kwIzXDN9iwbdULTboByF-TtNaiTmsoVbxZw" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DemoActivity"/>
<activity android:name=".DemoActivity" />



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import org.prebid.mobile.PrebidMobile
import org.prebid.mobile.prebidkotlindemo.ads.GamBanner
import org.prebid.mobile.prebidkotlindemo.ads.GamInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.GamVideoInterstitial

import org.prebid.mobile.prebidkotlindemo.ads.inapp.*
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobBanner
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobNative
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobRewarded
import org.prebid.mobile.prebidkotlindemo.ads.inappgam.*

import org.prebid.mobile.prebidkotlindemo.ads.inappmax.*
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import java.util.*

Expand Down Expand Up @@ -70,11 +69,10 @@ object AdTypesRepository {
"response-prebid-video-interstitial-320-480"
)
},
onDestroy = { GamInterstitial.destroy() }
onDestroy = { GamVideoInterstitial.destroy() }
)
),


"In-App" to listOf(
AdType(
"Banner 320x50",
Expand Down Expand Up @@ -269,6 +267,70 @@ object AdTypesRepository {
InAppAdMobNative.destroy()
}
)
),

"In-App + Applovin MAX" to listOf(
AdType(
"Banner",
onCreate = { _, wrapper, autoRefreshTime ->
PrebidMobile.setStoredAuctionResponse("response-prebid-banner-320-50")
InAppMaxBanner.create(
wrapper, autoRefreshTime / 1000,
"3d8a0bcbb6d571d5",
"imp-prebid-banner-320-50"
)
},
onDestroy = { InAppMaxBanner.destroy() }
),
AdType(
"MREC",
onCreate = { _, wrapper, autoRefreshTime ->
PrebidMobile.setStoredAuctionResponse("response-prebid-banner-300-250")
InAppMaxMrec.create(
wrapper, autoRefreshTime / 1000,
"550e6c2fe979a641",
"imp-prebid-banner-300-250"
)
},
onDestroy = { InAppMaxMrec.destroy() }
),
AdType(
"Interstitial",
onCreate = { activity, _, _ ->
PrebidMobile.setStoredAuctionResponse("response-prebid-display-interstitial-320-480")
InAppMaxInterstitial.create(
activity,
"393697e649678807",
"imp-prebid-display-interstitial-320-480"
)
},
onDestroy = { InAppMaxInterstitial.destroy() }
),
AdType(
"Rewarded",
onCreate = { activity, _, _ ->
PrebidMobile.setStoredAuctionResponse("response-prebid-video-rewarded-320-480")
InAppMaxRewarded.create(
activity,
"897f2fc59d617715",
"imp-prebid-video-rewarded-320-480"
)
},
onDestroy = { InAppMaxRewarded.destroy() }
),
AdType(
"Native",
onCreate = { activity, wrapper, _ ->
PrebidMobile.setStoredAuctionResponse("response-prebid-banner-native-styles")
InAppMaxNative.create(
activity,
wrapper,
"f3bdfa9dd8da1c4d",
"imp-prebid-banner-native-styles"
)
},
onDestroy = { InAppMaxNative.destroy() }
),
)
)

Expand All @@ -277,5 +339,4 @@ object AdTypesRepository {
PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid-server-test-j.prebid.org/openrtb2/auction"))
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import android.os.Bundle
import android.util.Log
import android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
import android.webkit.WebView
import com.applovin.sdk.AppLovinSdk
import com.applovin.sdk.AppLovinSdkConfiguration
import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.RequestConfiguration

Expand All @@ -35,6 +37,7 @@ class CustomApplication : Application() {
super.onCreate()
initPrebidSDK()
initAdMob()
initApplovinMax()
if (BuildConfig.DEBUG) {
activateKeepScreenOnFlag()
}
Expand All @@ -61,6 +64,12 @@ class CustomApplication : Application() {
MobileAds.setRequestConfiguration(configuration)
}

private fun initApplovinMax() {
AppLovinSdk.getInstance(this).mediationProvider = "max"
AppLovinSdk.getInstance(this).initializeSdk { configuration: AppLovinSdkConfiguration -> }
AppLovinSdk.getInstance(this).settings.setVerboseLogging(false)
}

private fun activateKeepScreenOnFlag() {
sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
this.registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.nativead.NativeAdOptions
import org.prebid.mobile.*
import org.prebid.mobile.admob.PrebidNativeAdapter
import org.prebid.mobile.prebidkotlindemo.databinding.ViewNativeAdBinding
import org.prebid.mobile.prebidkotlindemo.databinding.ViewNativeAdAdMobBinding


object InAppAdMobNative {
Expand Down Expand Up @@ -67,7 +67,7 @@ object InAppAdMobNative {

private fun createCustomView(wrapper: ViewGroup, nativeAd: NativeAd) {
wrapper.removeAllViews()
val binding = ViewNativeAdBinding.inflate(LayoutInflater.from(wrapper.context))
val binding = ViewNativeAdAdMobBinding.inflate(LayoutInflater.from(wrapper.context))

binding.apply {
tvHeadline.text = nativeAd.headline
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.prebid.mobile.prebidkotlindemo.ads.inappmax

import android.util.Log
import android.view.ViewGroup
import android.widget.FrameLayout
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdViewAdListener
import com.applovin.mediation.MaxError
import com.applovin.mediation.adapters.prebid.utils.MaxBannerMediationUtils
import com.applovin.mediation.ads.MaxAdView
import org.prebid.mobile.AdSize
import org.prebid.mobile.prebidkotlindemo.R
import org.prebid.mobile.rendering.bidding.display.MediationBannerAdUnit

object InAppMaxBanner {

private const val TAG = "InAppMaxBanner"

private var adView: MaxAdView? = null
private var adUnit: MediationBannerAdUnit? = null

fun create(
wrapper: ViewGroup,
autoRefreshTime: Int,
adUnitId: String,
configId: String
) {
adView = MaxAdView(adUnitId, wrapper.context)
adView?.setListener(createListener())
adView?.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
wrapper.context.resources.getDimensionPixelSize(R.dimen.banner_height)
)
wrapper.addView(adView)

val mediationUtils = MaxBannerMediationUtils(adView)
adUnit = MediationBannerAdUnit(
wrapper.context,
configId,
AdSize(320, 50),
mediationUtils
)
adUnit?.setRefreshInterval(autoRefreshTime)
adUnit?.fetchDemand {
adView?.loadAd()
}
}

fun destroy() {
adView?.stopAutoRefresh()
adView?.destroy()

adUnit?.stopRefresh()
adUnit?.destroy()
}

private fun createListener(): MaxAdViewAdListener {
return object : MaxAdViewAdListener {
override fun onAdLoaded(ad: MaxAd?) {
Log.d(TAG, "onAdLoaded()")
}

override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {
Log.d(TAG, "onAdLoadFailed(): ${error?.message}")
}

override fun onAdHidden(ad: MaxAd?) {}
override fun onAdClicked(ad: MaxAd?) {}
override fun onAdExpanded(ad: MaxAd?) {}
override fun onAdCollapsed(ad: MaxAd?) {}
override fun onAdDisplayed(ad: MaxAd?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.prebid.mobile.prebidkotlindemo.ads.inappmax

import android.app.Activity
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdListener
import com.applovin.mediation.MaxError
import com.applovin.mediation.adapters.prebid.utils.MaxInterstitialMediationUtils
import com.applovin.mediation.ads.MaxInterstitialAd
import org.prebid.mobile.rendering.bidding.display.MediationInterstitialAdUnit
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat
import java.util.*

object InAppMaxInterstitial {

private var maxInterstitialAd: MaxInterstitialAd? = null
private var adUnit: MediationInterstitialAdUnit? = null

fun create(
activity: Activity,
adUnitId: String,
configId: String
) {
maxInterstitialAd = MaxInterstitialAd(adUnitId, activity)
maxInterstitialAd?.setListener(createListener())

val mediationUtils =
MaxInterstitialMediationUtils(
maxInterstitialAd
)
adUnit = MediationInterstitialAdUnit(
activity,
configId,
EnumSet.of(AdUnitFormat.DISPLAY),
mediationUtils
)
adUnit?.fetchDemand {
maxInterstitialAd?.loadAd()
}
}

fun destroy() {
maxInterstitialAd?.destroy()

adUnit?.destroy()
}

private fun createListener(): MaxAdListener {
return object : MaxAdListener {
override fun onAdLoaded(ad: MaxAd?) {
maxInterstitialAd?.showAd()
}

override fun onAdDisplayed(ad: MaxAd?) {}
override fun onAdHidden(ad: MaxAd?) {}
override fun onAdClicked(ad: MaxAd?) {}
override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
}
}

}
Loading

0 comments on commit fa0872b

Please sign in to comment.