Commit 813e956b authored by wanglei's avatar wanglei

[同步]同步广告问题

parent 285684f1
...@@ -170,21 +170,28 @@ dependencies { ...@@ -170,21 +170,28 @@ dependencies {
implementation("com.google.firebase:firebase-crashlytics") implementation("com.google.firebase:firebase-crashlytics")
implementation("com.google.firebase:firebase-config") implementation("com.google.firebase:firebase-config")
//广告 // //广告
//admob渠道 // //admob渠道
implementation(libs.vungle) // implementation(libs.vungle)
implementation(libs.facebook) // implementation(libs.facebook)
implementation(libs.mintegral) // implementation(libs.mintegral)
implementation(libs.pangle) // implementation(libs.pangle)
//applovin sdk // //applovin sdk
implementation(libs.applovin) // implementation(libs.applovin)
//applovin渠道 // //applovin渠道
implementation(libs.applovin.google) // implementation(libs.applovin.google)
implementation(libs.applovin.admob) // implementation(libs.applovin.admob)
implementation(libs.applovin.facebook) //meta // implementation(libs.applovin.facebook) //meta
implementation(libs.applovin.mintegral)//mintegral // implementation(libs.applovin.mintegral)//mintegral
implementation(libs.applovin.pangle) //pangle // implementation(libs.applovin.pangle) //pangle
implementation(libs.applovin.vungle) //vungle // implementation(libs.applovin.vungle) //vungle
implementation("com.google.android.gms:play-services-ads:23.5.0")
implementation("com.google.ads.mediation:applovin:13.0.1.0")
implementation("com.google.ads.mediation:facebook:6.18.0.0")
implementation("com.google.ads.mediation:mintegral:16.8.61.0")
implementation("com.google.ads.mediation:pangle:6.3.0.4.0")
implementation("com.google.ads.mediation:vungle:7.4.2.0")
val work_version = "2.8.1" val work_version = "2.8.1"
implementation("androidx.work:work-runtime-ktx:$work_version") implementation("androidx.work:work-runtime-ktx:$work_version")
......
...@@ -4,20 +4,22 @@ package com.rgt.superr.bean.config ...@@ -4,20 +4,22 @@ package com.rgt.superr.bean.config
class AdConfigBean( class AdConfigBean(
var isAdShow: Boolean = true,//广告开关 var isAdShow: Boolean = true,//广告开关
var adSwitch: Boolean = true,//true 走admob,false走max // var adSwitch: Boolean = true,//true 走admob,false走max
var taichiAdValue: Int = 1,//价值上报阀值 var taichiAdValue: Int = 1,//价值上报阀值
var adRatio: Int = 100,//价值上报随机控制 var adRatio: Int = 100,//价值上报随机控制
var numDisplayLimit: Int = -1,//展示次数限制 var numDisplayLimit: Int = -1,//展示次数限制
var numRequestLimit: Int = -1,//请求次数限制 var numRequestLimit: Int = -1,//请求次数限制
var numClickLimit: Int = -1,//点击次数限制 var numClickLimit: Int = -1,//点击次数限制
var timeInterval: Int = 10,//广告间隔秒 var timeInterval: Int = 10,//插页广告间隔秒
var timeIntervalOpen: Int = 0,//开屏广告间隔
var openAdLoading: Int = 15,//开屏广告拉取时间 var openAdLoading: Int = 15,//开屏广告拉取时间
var numNativeDisplayLimit: Int = -1,//原生广告展示限制
var fullNativeShow: Boolean = true,//显示全屏原生 var fullNativeShow: Boolean = true,//显示全屏原生
var functionBackShowAd: Boolean = true,//功能退出显示广告 var functionBackShowAd: Boolean = true,//功能退出显示广告
var functionInShowAd: Boolean = true,//功能进入显示广告 var functionInShowAd: Boolean = true,//功能进入显示广告
var rvEmptyShowNative: Boolean = true,//列表空的显示原生不 // var rvEmptyShowNative: Boolean = true,//列表空的显示原生不
var requestUmp: Boolean = false,//是否需要请求ump var requestUmp: Boolean = false,//是否需要请求ump
var showCountdown: Boolean = false,//是否显示倒计时 var showCountdown: Boolean = false,//是否显示倒计时
......
...@@ -6,7 +6,7 @@ package com.rgt.superr.bean.config ...@@ -6,7 +6,7 @@ package com.rgt.superr.bean.config
*/ */
data class ConfigBean( data class ConfigBean(
var isInBlackList: Boolean = false, // var isInBlackList: Boolean = false,
val ut: Int = 0, val ut: Int = 0,
var vpnCanUse: Boolean = true, var vpnCanUse: Boolean = true,
val adConfigBean: AdConfigBean = AdConfigBean(), val adConfigBean: AdConfigBean = AdConfigBean(),
......
package com.rgt.superr.business.ads package com.rgt.superr.business.ads
import android.app.Dialog import android.app.Dialog
import com.rgt.superr.business.ads.LimitUtils.openInterLastShowTime import com.rgt.superr.business.ads.AdsType.Companion.INSERT
import com.rgt.superr.business.ads.AdsType.Companion.OPEN
import com.rgt.superr.business.ads.LimitUtils.interLastShowTime
import com.rgt.superr.business.ads.LimitUtils.openLastShowTime
class AdState<T>() { class AdState<T>() {
var adDialog: Dialog? = null var adDialog: Dialog? = null
...@@ -24,41 +28,41 @@ class AdState<T>() { ...@@ -24,41 +28,41 @@ class AdState<T>() {
*/ */
var loadingAd: Boolean = false var loadingAd: Boolean = false
/**
* 用于保存引用现有页面,在此页面显示广告(因为要等待广告加载完毕)
*/
// var activityRef: WeakReference<Activity>? = null
/** /**
* 上一次的缓存成功时间 * 上一次的缓存成功时间
*/ */
var lastLoadTime: Long = 0 var lastLoadTime: Long = 0
/**
* 上次展示时间
*/
// var lastShowTime: Long = 0
/** /**
* 广告已经展示 * 广告已经展示
*/ */
fun onAdDisplayed() { fun onAdDisplayed(adsType: AdsType) {
currentAd = null currentAd = null
currentAdEvent = null currentAdEvent = null
// activityRef = null
adDialog?.dismiss() adDialog?.dismiss()
adDialog = null adDialog = null
openInterLastShowTime = System.currentTimeMillis() if (adsType == OPEN) {
openLastShowTime = System.currentTimeMillis()
}
if (adsType == INSERT) {
interLastShowTime = System.currentTimeMillis()
}
} }
fun onAdHidden() { fun onAdHidden(adsType: AdsType) {
//重置下上次展示的时间,避免看广告的时间算入间隔 //重置下上次展示的时间,避免看广告的时间算入间隔
openInterLastShowTime = System.currentTimeMillis() if (adsType == OPEN) {
openLastShowTime = System.currentTimeMillis()
}
if (adsType == INSERT) {
interLastShowTime = System.currentTimeMillis()
}
} }
...@@ -68,17 +72,16 @@ class AdState<T>() { ...@@ -68,17 +72,16 @@ class AdState<T>() {
currentAd = null currentAd = null
currentAdEvent = null currentAdEvent = null
// activityRef = null
} }
fun onAdLoaded(ad: T?, adEvent: AdEvent?) { fun loadStart(adEvent: AdEvent) {
//这里可能提前设置,所有可以不设置,max回调的类型可能不同 loadingAd = true
if (ad != null) { currentAdEvent = adEvent
currentAd = ad }
}
if (adEvent != null) { fun onAdLoaded(ad: T?) {
currentAdEvent = adEvent currentAd = ad
}
loadingAd = false loadingAd = false
lastLoadTime = System.currentTimeMillis() lastLoadTime = System.currentTimeMillis()
} }
...@@ -90,7 +93,6 @@ class AdState<T>() { ...@@ -90,7 +93,6 @@ class AdState<T>() {
} }
fun adAvailable() = fun needLoad() = currentAd == null || ((System.currentTimeMillis() - lastLoadTime) / 1000 / 60).toInt() > 30
currentAd != null || ((System.currentTimeMillis() - lastLoadTime) / 1000 / 60).toInt() < 30
} }
...@@ -17,10 +17,10 @@ import com.rgt.superr.business.ads.admob.AdInterMgr ...@@ -17,10 +17,10 @@ import com.rgt.superr.business.ads.admob.AdInterMgr
import com.rgt.superr.business.ads.admob.AdNativeMgr import com.rgt.superr.business.ads.admob.AdNativeMgr
import com.rgt.superr.business.ads.admob.AdOpenMgr import com.rgt.superr.business.ads.admob.AdOpenMgr
import com.rgt.superr.business.ads.admob.AdmobEvent import com.rgt.superr.business.ads.admob.AdmobEvent
import com.rgt.superr.business.ads.applovin.AdMaxEvent //import com.rgt.superr.business.ads.applovin.AdMaxEvent
import com.rgt.superr.business.ads.applovin.MaxInsertMgr //import com.rgt.superr.business.ads.applovin.MaxInsertMgr
import com.rgt.superr.business.ads.applovin.MaxNativeMgr //import com.rgt.superr.business.ads.applovin.MaxNativeMgr
import com.rgt.superr.business.ads.applovin.MaxOpenMgr //import com.rgt.superr.business.ads.applovin.MaxOpenMgr
import com.rgt.superr.business.helper.EventUtils import com.rgt.superr.business.helper.EventUtils
import com.rgt.superr.utils.AppPreferences import com.rgt.superr.utils.AppPreferences
import com.rgt.superr.utils.LogEx import com.rgt.superr.utils.LogEx
...@@ -49,15 +49,15 @@ object AdsMgr { ...@@ -49,15 +49,15 @@ object AdsMgr {
AdBannerMgr() AdBannerMgr()
} }
private val maxOpenMgr by lazy { // private val maxOpenMgr by lazy {
MaxOpenMgr() // MaxOpenMgr()
} // }
private val maxInsertMgr by lazy { // private val maxInsertMgr by lazy {
MaxInsertMgr() // MaxInsertMgr()
} // }
private val maxNativeMgr by lazy { // private val maxNativeMgr by lazy {
MaxNativeMgr() // MaxNativeMgr()
} // }
/** /**
* 是否初始化 * 是否初始化
...@@ -87,12 +87,12 @@ object AdsMgr { ...@@ -87,12 +87,12 @@ object AdsMgr {
*/ */
fun init(context: Context) { fun init(context: Context) {
if (configBean.isInBlackList) { // if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", value = "isInBlackList=${configBean.isInBlackList}") // EventUtils.event("isInBlackList", value = "isInBlackList=${configBean.isInBlackList}")
return // return
} // }
initAdmob(context) initAdmob(context)
initMax(context) // initMax(context)
} }
...@@ -106,7 +106,7 @@ object AdsMgr { ...@@ -106,7 +106,7 @@ object AdsMgr {
EventUtils.event("AdmobInit", "AdmobInit=$isAdmobInit") EventUtils.event("AdmobInit", "AdmobInit=$isAdmobInit")
// context.toast("admob init") // context.toast("admob init")
if (adsConfigBean.adSwitch) { if (true) {
admobInitCallBack?.invoke() admobInitCallBack?.invoke()
admobInitCallBack = null admobInitCallBack = null
adNativeMgr.loadAd(context, AdmobEvent("nativeAd", context::class.java.simpleName)) adNativeMgr.loadAd(context, AdmobEvent("nativeAd", context::class.java.simpleName))
...@@ -117,38 +117,38 @@ object AdsMgr { ...@@ -117,38 +117,38 @@ object AdsMgr {
} }
private fun initMax(context: Context) = kotlin.runCatching { // private fun initMax(context: Context) = kotlin.runCatching {
if (isMaxInit) return@runCatching // if (isMaxInit) return@runCatching
val executor = Executors.newSingleThreadExecutor() // val executor = Executors.newSingleThreadExecutor()
//
executor.execute { // executor.execute {
val currentGaid = AdvertisingIdClient.getAdvertisingIdInfo(context).id // val currentGaid = AdvertisingIdClient.getAdvertisingIdInfo(context).id
AppPreferences.getInstance().getString("gid", currentGaid) // AppPreferences.getInstance().getString("gid", currentGaid)
//
val build = AppLovinSdkInitializationConfiguration // val build = AppLovinSdkInitializationConfiguration
.builder(GlobalConfig.KEY_MAX, context) // .builder(GlobalConfig.KEY_MAX, context)
//
build.mediationProvider = AppLovinMediationProvider.MAX // build.mediationProvider = AppLovinMediationProvider.MAX
if (BuildConfig.DEBUG) { // if (BuildConfig.DEBUG) {
build.testDeviceAdvertisingIds = Collections.singletonList(currentGaid) // build.testDeviceAdvertisingIds = Collections.singletonList(currentGaid)
} // }
val initConfig = build.build() // val initConfig = build.build()
runCatching { // runCatching {
AppLovinSdk.getInstance(context).initialize(initConfig) { // AppLovinSdk.getInstance(context).initialize(initConfig) {
isMaxInit = true // isMaxInit = true
// maxOpenMgr.loadAd(context) //// maxOpenMgr.loadAd(context)
if (!adsConfigBean.adSwitch) { // if (!adsConfigBean.adSwitch) {
maxInsertMgr.loadAd(context, AdMaxEvent("interAd", context::class.java.simpleName)) // maxInsertMgr.loadAd(context, AdMaxEvent("interAd", context::class.java.simpleName))
context.toast("max init") // context.toast("max init")
maxInitCallBack?.invoke() // maxInitCallBack?.invoke()
maxInitCallBack = null // maxInitCallBack = null
} // }
} // }
} // }
//
} // }
//
} // }
var admobInitCallBack: (() -> Unit)? = null var admobInitCallBack: (() -> Unit)? = null
var maxInitCallBack: (() -> Unit)? = null var maxInitCallBack: (() -> Unit)? = null
...@@ -172,14 +172,14 @@ object AdsMgr { ...@@ -172,14 +172,14 @@ object AdsMgr {
return return
} }
if (configBean.isInBlackList) { // if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", "isInBlackList=${configBean.isInBlackList}") // EventUtils.event("isInBlackList", "isInBlackList=${configBean.isInBlackList}")
showCallBack?.failed() // showCallBack?.failed()
return // return
} // }
val from = activity::class.java.simpleName val from = activity::class.java.simpleName
if (adsConfigBean.adSwitch) { if (true) {
val admobEvent = AdmobEvent("openAd", from).apply { this.isUnLimit = isUnLimit } val admobEvent = AdmobEvent("openAd", from).apply { this.isUnLimit = isUnLimit }
if (isAdmobInit) { if (isAdmobInit) {
adOpenMgr.show(activity, admobEvent, showCallBack) adOpenMgr.show(activity, admobEvent, showCallBack)
...@@ -189,13 +189,13 @@ object AdsMgr { ...@@ -189,13 +189,13 @@ object AdsMgr {
adOpenMgr.show(activity, admobEvent, showCallBack) adOpenMgr.show(activity, admobEvent, showCallBack)
} }
} else { } else {
if (isMaxInit) { // if (isMaxInit) {
maxOpenMgr.show(activity, isUnLimit, AdMaxEvent("openAd", from), showCallBack) // maxOpenMgr.show(activity, isUnLimit, AdMaxEvent("openAd", from), showCallBack)
} else { // } else {
maxInitCallBack = { // maxInitCallBack = {
maxOpenMgr.show(activity, isUnLimit, AdMaxEvent("openAd", from), showCallBack) // maxOpenMgr.show(activity, isUnLimit, AdMaxEvent("openAd", from), showCallBack)
} // }
} // }
} }
} }
...@@ -219,17 +219,16 @@ object AdsMgr { ...@@ -219,17 +219,16 @@ object AdsMgr {
return return
} }
if (configBean.isInBlackList) { // if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", configBean.isInBlackList.toString()) // EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
showCallBack?.failed() // showCallBack?.failed()
return // return
} // }
LogEx.logDebug("showAd", "adSwitch=${adsConfigBean.adSwitch}")
val from = activity::class.java.simpleName val from = activity::class.java.simpleName
if (adsConfigBean.adSwitch) { if (true) {
adInterMgr.show(activity, AdmobEvent("interAd", from).apply { this.isUnLimit = isUnLimit }, showCallBack) adInterMgr.show(activity, AdmobEvent("interAd", from).apply { this.isUnLimit = isUnLimit }, showCallBack)
} else { } else {
maxInsertMgr.show(activity, isUnLimit, AdMaxEvent("interAd", from), showCallBack) // maxInsertMgr.show(activity, isUnLimit, AdMaxEvent("interAd", from), showCallBack)
} }
} }
...@@ -250,16 +249,16 @@ object AdsMgr { ...@@ -250,16 +249,16 @@ object AdsMgr {
return return
} }
nativeView.visibility = View.VISIBLE nativeView.visibility = View.VISIBLE
if (configBean.isInBlackList) { // if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", configBean.isInBlackList.toString()) // EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
return // return
} // }
val showNative = { val showNative = {
if (adsConfigBean.adSwitch) { if (true) {
adNativeMgr.show(AdmobEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack) adNativeMgr.show(AdmobEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack)
} else { } else {
maxNativeMgr.show(AdMaxEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack) // maxNativeMgr.show(AdMaxEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack)
} }
} }
...@@ -282,11 +281,11 @@ object AdsMgr { ...@@ -282,11 +281,11 @@ object AdsMgr {
return return
} }
parent.visibility = View.VISIBLE parent.visibility = View.VISIBLE
if (configBean.isInBlackList) { // if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", configBean.isInBlackList.toString()) // EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
return // return
} // }
if (adsConfigBean.adSwitch) { if (true) {
adBannerMgr.show(parent, collapsible, adClose) adBannerMgr.show(parent, collapsible, adClose)
} }
} }
......
...@@ -4,6 +4,7 @@ import com.rgt.superr.BuildConfig ...@@ -4,6 +4,7 @@ import com.rgt.superr.BuildConfig
import com.rgt.superr.bean.config.AdConfigBean import com.rgt.superr.bean.config.AdConfigBean
import com.rgt.superr.utils.AppPreferences import com.rgt.superr.utils.AppPreferences
import com.rgt.superr.utils.KotlinExt.toFormatTime4 import com.rgt.superr.utils.KotlinExt.toFormatTime4
import com.rgt.superr.utils.LogEx
/** /**
...@@ -11,6 +12,8 @@ import com.rgt.superr.utils.KotlinExt.toFormatTime4 ...@@ -11,6 +12,8 @@ import com.rgt.superr.utils.KotlinExt.toFormatTime4
* *
*/ */
object LimitUtils { object LimitUtils {
const val NUM_NATIVE_DISPLAY = "local_numNativeDisplayLimit"
const val NUM_DISPLAY = "local_numDisplayLimit" const val NUM_DISPLAY = "local_numDisplayLimit"
const val NUM_REQUEST = "local_numRequestLimit" const val NUM_REQUEST = "local_numRequestLimit"
...@@ -143,24 +146,94 @@ object LimitUtils { ...@@ -143,24 +146,94 @@ object LimitUtils {
addNum(NUM_CLICK) addNum(NUM_CLICK)
} }
fun addNativeDisplayNum() {
addNum(NUM_NATIVE_DISPLAY)
}
/**
* 开屏限制
*/
fun isIntervalOpenLimit(adEvent: AdEvent): Boolean {
val passTime = ((System.currentTimeMillis() - openLastShowTime) / 1000).toInt()
val interval = AdConfigBean.adsConfigBean.timeIntervalOpen
val flag = passTime < interval
LogEx.logDebug(adEvent.TAG, "open isIntervalOpenLimit=$flag passTime=$passTime interval=$interval")
if (flag) {
adEvent.adShowError("ad in timeInterval")
}
return flag
}
/** /**
* 开屏和插页广告的显示间隔限制 * 插屏限制
*/ */
fun isIntervalLimited(adEvent: AdEvent?): Boolean { fun isIntervalInterLimit(adEvent: AdEvent): Boolean {
val flag = ((System.currentTimeMillis() - openInterLastShowTime) / 1000).toInt() < (AdConfigBean.adsConfigBean.timeInterval) val passTime = ((System.currentTimeMillis() - interLastShowTime) / 1000).toInt()
val interval = AdConfigBean.adsConfigBean.timeInterval
val flag = passTime < interval
LogEx.logDebug(
adEvent.TAG,
"inter isIntervalInterLimit=$flag interLastShowTime=$interLastShowTime passTime=$passTime interval=$interval"
)
if (flag) { if (flag) {
adEvent?.adLimited("ad in timeInterval") adEvent.adShowError("ad in timeInterval")
} }
return flag return flag
} }
//开屏和插页上一次展示时间共用,避免开屏插页连弹 //开屏上次展示时间
var openInterLastShowTime = 0L var openLastShowTime = 0L
get() {
return AppPreferences.getInstance().getLong("openLastShowTime", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("openLastShowTime", value, true)
}
//插屏上次展示时间
var interLastShowTime = 0L
get() { get() {
return AppPreferences.getInstance().getLong("openInterLastShowTime", field) return AppPreferences.getInstance().getLong("interLastShowTime", field)
} }
set(value) { set(value) {
field = value field = value
AppPreferences.getInstance().put("openInterLastShowTime", value, true) AppPreferences.getInstance().put("interLastShowTime", value, true)
} }
}
\ No newline at end of file
/**
* 原生广告是否到达限制
*/
private inline val isNativeLimited: Boolean
get() {
val maxCount = AdConfigBean.adsConfigBean.numNativeDisplayLimit
return maxCount > -1 && AppPreferences.getInstance()
.getInt(NUM_NATIVE_DISPLAY, 0) >= maxCount
}
fun isShowNative(adsType: AdsType, adEvent: AdEvent?): Boolean {
val currentDate = System.currentTimeMillis().toFormatTime4()
if (saveDate != currentDate) {
//如果已经不是今天了,就重置个数
saveDate = currentDate
AppPreferences.getInstance().put(NUM_NATIVE_DISPLAY, 0)
}
val flag = isNativeLimited
val todayNumber = AppPreferences.getInstance().getInt(NUM_NATIVE_DISPLAY, 0)
val max = AdConfigBean.adsConfigBean.numNativeDisplayLimit
LogEx.logDebug(adEvent?.TAG ?: "", "native todayNumber=$todayNumber max=$max ")
if (flag) {
val value = "current${getAdEventMsg(adsType)} " +
"show=${todayNumber} " +
"${getAdEventMsg(adsType).lowercase()}_" + "max_show=${max}"
adEvent?.adLimited(value)
}
return !flag
}
}
...@@ -25,9 +25,9 @@ class AdBannerMgr { ...@@ -25,9 +25,9 @@ class AdBannerMgr {
fun show(parent: ViewGroup, collapsible: Boolean, adClose: (() -> Unit)? = null) { fun show(parent: ViewGroup, collapsible: Boolean, adClose: (() -> Unit)? = null) {
if (!AdConfigBean.adsConfigBean.adSwitch) { // if (!AdConfigBean.adsConfigBean.adSwitch) {
return // return
} // }
val admobEvent = AdmobEvent("banner", "banner") val admobEvent = AdmobEvent("banner", "banner")
if (!LimitUtils.isAdShow(AdsType.BANNER, admobEvent)) { if (!LimitUtils.isAdShow(AdsType.BANNER, admobEvent)) {
......
...@@ -19,6 +19,7 @@ import com.google.android.gms.ads.FullScreenContentCallback ...@@ -19,6 +19,7 @@ import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.LoadAdError import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.interstitial.InterstitialAd import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
import com.rgt.superr.business.ads.AdsType.Companion.INSERT
/** /**
...@@ -26,12 +27,12 @@ import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback ...@@ -26,12 +27,12 @@ import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
*/ */
class AdInterMgr { class AdInterMgr {
private val TAG = "AdInterMgr"
private var adState = AdState<InterstitialAd>() private var adState = AdState<InterstitialAd>()
private var showCallBack: AdsShowCallBack? = null private var showCallBack: AdsShowCallBack? = null
//正在加载回调 //正在加载回调
private var loadingCallBack: (() -> Unit)? = null private var loadingCallBack: ((flag: Boolean) -> Unit)? = null
fun show( fun show(
activity: Activity, activity: Activity,
...@@ -43,24 +44,22 @@ class AdInterMgr { ...@@ -43,24 +44,22 @@ class AdInterMgr {
return return
} }
val nowAdEvent = adEvent
//currentAdEvent!=null 表示有缓存广告,关联reqId //currentAdEvent!=null 表示有缓存广告,关联reqId
adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId } adState.currentAdEvent?.let { adEvent.reqId = it.reqId }
if (!nowAdEvent.isUnLimit) { if (!adEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, nowAdEvent)) { if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
showCallBack?.failed(2) showCallBack?.failed(2)
return return
} }
if (LimitUtils.isIntervalLimited(nowAdEvent)) { if (LimitUtils.isIntervalInterLimit(adEvent)) {
showCallBack?.failed(3) showCallBack?.failed(3)
return return
} }
} }
val needLoad = !adState.adAvailable() val needLoad = adState.needLoad()
// adState.activityRef = WeakReference(activity)
this.showCallBack = showCallBack this.showCallBack = showCallBack
if (adState.adDialog == null) { if (adState.adDialog == null) {
...@@ -69,24 +68,29 @@ class AdInterMgr { ...@@ -69,24 +68,29 @@ class AdInterMgr {
adState.adDialog?.dismiss() adState.adDialog?.dismiss()
} }
nowAdEvent.adPrepareShow() adEvent.adPrepareShow()
LogEx.logDebug(adEvent.TAG, "needLoad=$needLoad") LogEx.logDebug(adEvent.TAG, "needLoad=$needLoad")
if (needLoad) { if (needLoad) {
if (!adState.loadingAd) { if (!adState.loadingAd) {
LogEx.logDebug(adEvent.TAG, "inter adState !loadingAd") LogEx.logDebug(adEvent.TAG, "inter adState !loadingAd")
loadAd(activity, nowAdEvent) { loadAd(activity, adEvent) {
showReadyAd(activity, nowAdEvent) if (it) {
showReadyAd(activity, adEvent)
} else {
showCallBack?.adFailed()
}
} }
} else { } else {
LogEx.logDebug(adEvent.TAG, "inter adState is loadingAd") LogEx.logDebug(adEvent.TAG, "inter adState is loadingAd")
loadingCallBack = { loadingCallBack = {
showReadyAd(activity, nowAdEvent) showReadyAd(activity, adEvent)
} }
} }
} else { } else {
LogEx.logDebug(adEvent.TAG, "inter ad ready") LogEx.logDebug(adEvent.TAG, "inter ad ready")
showReadyAd(activity, nowAdEvent) showReadyAd(activity, adEvent)
} }
} }
...@@ -94,13 +98,12 @@ class AdInterMgr { ...@@ -94,13 +98,12 @@ class AdInterMgr {
private fun showReadyAd(ac: Activity, adEvent: AdEvent) { private fun showReadyAd(ac: Activity, adEvent: AdEvent) {
// val ac = adState.activityRef?.get()
val admobEvent = (adEvent as AdmobEvent) val admobEvent = (adEvent as AdmobEvent)
val tag = adEvent.TAG val tag = adEvent.TAG
LogEx.logDebug(tag, "showReadyAd ac=$ac currentAd=${adState.currentAd}") LogEx.logDebug(tag, "inter showReadyAd ac=${ac.javaClass.simpleName} currentAd=${adState.currentAd}")
if (ac.isFinishing || ac.isDestroyed || adState.currentAd == null) { if (ac.isFinishing || ac.isDestroyed || adState.currentAd == null) {
LogEx.logDebug(tag, "showReadyAd ac=null isFinishing isDestroyed") LogEx.logDebug(tag, "inter showReadyAd ac=null isFinishing isDestroyed")
showCallBack?.failed() showCallBack?.failed()
adState.onAdDisplayFailed() adState.onAdDisplayFailed()
return return
...@@ -112,12 +115,12 @@ class AdInterMgr { ...@@ -112,12 +115,12 @@ class AdInterMgr {
override fun onAdShowedFullScreenContent() { override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent() super.onAdShowedFullScreenContent()
admobEvent.showAd(responseInfo, ac) adState.onAdDisplayed(INSERT)
adState.onAdDisplayed()
showCallBack?.show() showCallBack?.show()
LimitUtils.addDisplayNum() LimitUtils.addDisplayNum()
admobEvent.showAd(responseInfo, ac)
} }
override fun onAdFailedToShowFullScreenContent(adError: AdError) { override fun onAdFailedToShowFullScreenContent(adError: AdError) {
...@@ -133,10 +136,11 @@ class AdInterMgr { ...@@ -133,10 +136,11 @@ class AdInterMgr {
override fun onAdDismissedFullScreenContent() { override fun onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent() super.onAdDismissedFullScreenContent()
adState.onAdHidden() adState.onAdHidden(INSERT)
showCallBack?.close() showCallBack?.close()
showCallBack = null showCallBack = null
loadAd(MyApplication.appContext, AdmobEvent("interAd", "preload")) loadAd(MyApplication.appContext, AdmobEvent("interAd", "preload"))
} }
...@@ -147,7 +151,6 @@ class AdInterMgr { ...@@ -147,7 +151,6 @@ class AdInterMgr {
LimitUtils.addClickNum() LimitUtils.addClickNum()
} }
} }
// val activity = adState.activityRef?.get()
if (AdConfigBean.adsConfigBean.showCountdown) { if (AdConfigBean.adsConfigBean.showCountdown) {
createUICountdownTimer(adState.adDialog) { createUICountdownTimer(adState.adDialog) {
show(ac) show(ac)
...@@ -158,10 +161,11 @@ class AdInterMgr { ...@@ -158,10 +161,11 @@ class AdInterMgr {
} }
} }
fun loadAd( fun loadAd(
context: Context, context: Context,
adEvent: AdEvent, adEvent: AdEvent,
loadCallBack: (() -> Unit)? = null loadCallBack: ((flag: Boolean) -> Unit)? = null
) { ) {
if (!adEvent.isUnLimit) { if (!adEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) { if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
...@@ -173,14 +177,12 @@ class AdInterMgr { ...@@ -173,14 +177,12 @@ class AdInterMgr {
} }
//避免无效预加载 //避免无效预加载
if (adState.loadingAd && loadCallBack == null && loadingCallBack == null) { if (adState.loadingAd) {
//容错机制
adState.loadingAd = false
return return
} }
adState.loadingAd = true
adEvent.adPulStart() adEvent.adPulStart()
adState.loadStart(adEvent)
InterstitialAd.load( InterstitialAd.load(
context, GlobalConfig.ID_ADMOB_INTER, AdRequest.Builder().build(), context, GlobalConfig.ID_ADMOB_INTER, AdRequest.Builder().build(),
...@@ -188,10 +190,10 @@ class AdInterMgr { ...@@ -188,10 +190,10 @@ class AdInterMgr {
override fun onAdLoaded(ad: InterstitialAd) { override fun onAdLoaded(ad: InterstitialAd) {
val event = (adEvent as AdmobEvent) val event = (adEvent as AdmobEvent)
ad.onPaidEventListener = AdmobOnPaidEventListener(ad, adEvent.scope) ad.onPaidEventListener = AdmobOnPaidEventListener(ad, adEvent.scope)
adState.onAdLoaded(ad, adEvent) adState.onAdLoaded(ad)
loadCallBack?.invoke() loadCallBack?.invoke(true)
loadingCallBack?.invoke() loadingCallBack?.invoke(true)
loadingCallBack = null loadingCallBack = null
LimitUtils.addRequestNum() LimitUtils.addRequestNum()
...@@ -200,11 +202,14 @@ class AdInterMgr { ...@@ -200,11 +202,14 @@ class AdInterMgr {
override fun onAdFailedToLoad(loadAdError: LoadAdError) { override fun onAdFailedToLoad(loadAdError: LoadAdError) {
adState.onAdLoadFailed() adState.onAdLoadFailed()
if (loadCallBack != null) { if (loadCallBack != null) {
adState.onAdDisplayFailed() adState.onAdDisplayFailed()
} }
showCallBack?.adFailed() loadCallBack?.invoke(false)
showCallBack = null loadingCallBack?.invoke(false)
loadingCallBack = null
(adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError) (adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
} }
...@@ -214,4 +219,4 @@ class AdInterMgr { ...@@ -214,4 +219,4 @@ class AdInterMgr {
} }
} }
\ No newline at end of file
...@@ -13,6 +13,7 @@ import com.google.android.gms.ads.AdRequest ...@@ -13,6 +13,7 @@ import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.LoadAdError import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.nativead.NativeAd import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.nativead.NativeAdOptions import com.google.android.gms.ads.nativead.NativeAdOptions
import com.rgt.superr.business.ads.AdsType.Companion.NATIVE
import java.util.concurrent.ConcurrentLinkedDeque import java.util.concurrent.ConcurrentLinkedDeque
/** /**
...@@ -40,7 +41,6 @@ class AdNativeMgr { ...@@ -40,7 +41,6 @@ class AdNativeMgr {
admobEvent.adPulStart() admobEvent.adPulStart()
if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) { if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) {
// Log.e(TAG, "loadAd return")
return return
} }
...@@ -60,7 +60,6 @@ class AdNativeMgr { ...@@ -60,7 +60,6 @@ class AdNativeMgr {
if (showAction != null) { if (showAction != null) {
showAction.invoke(nativeAd) showAction.invoke(nativeAd)
} else { } else {
// Log.e(TAG, "offer ad")
cacheItems.offer(nativeAd) cacheItems.offer(nativeAd)
} }
...@@ -93,16 +92,15 @@ class AdNativeMgr { ...@@ -93,16 +92,15 @@ class AdNativeMgr {
admobEvent.adPrepareShow() admobEvent.adPrepareShow()
if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) { if (!LimitUtils.isAdShow(NATIVE, admobEvent) || !LimitUtils.isShowNative(NATIVE, admobEvent)) {
Log.e(TAG, "!isAdShow")
cacheItems.clear() cacheItems.clear()
return return
} }
Log.e(TAG, "adNative can show") Log.e(admobEvent.TAG, "native can show")
if (!adAvailable()) { if (!adAvailable()) {
//缓存过期了就清空 //缓存过期了就清空
Log.e(TAG, "cacheItems clear") Log.e(admobEvent.TAG, "native cacheItems clear")
cacheItems.clear() cacheItems.clear()
} }
...@@ -111,7 +109,7 @@ class AdNativeMgr { ...@@ -111,7 +109,7 @@ class AdNativeMgr {
if (nativeAd == null) { if (nativeAd == null) {
loadAd(parent.context, admobEvent) { ad -> loadAd(parent.context, admobEvent) { ad ->
Log.e(TAG, "load show") Log.e(admobEvent.TAG, "native load show")
nativeCallBack?.invoke(ad) nativeCallBack?.invoke(ad)
parent.setNativeAd(ad, layout) parent.setNativeAd(ad, layout)
admobEvent.showAd(ad.responseInfo) admobEvent.showAd(ad.responseInfo)
...@@ -121,7 +119,7 @@ class AdNativeMgr { ...@@ -121,7 +119,7 @@ class AdNativeMgr {
} else { } else {
val flag = cacheItems.remove(nativeAd) val flag = cacheItems.remove(nativeAd)
Log.e(TAG, "ready show remove=$flag size=${cacheItems.size}") Log.e(admobEvent.TAG, "native ready show remove=$flag size=${cacheItems.size}")
nativeCallBack?.invoke(nativeAd) nativeCallBack?.invoke(nativeAd)
parent.setNativeAd(nativeAd, layout) parent.setNativeAd(nativeAd, layout)
......
...@@ -52,7 +52,7 @@ class AdOpenMgr { ...@@ -52,7 +52,7 @@ class AdOpenMgr {
} }
} }
val needLoad = !adState.adAvailable() val needLoad = !adState.needLoad()
this.showCallBack = showCallBack this.showCallBack = showCallBack
nowAdEvent.adPrepareShow() nowAdEvent.adPrepareShow()
......
...@@ -77,16 +77,17 @@ class AdmobEvent : AdEvent { ...@@ -77,16 +77,17 @@ class AdmobEvent : AdEvent {
key = "ad_pull_error" key = "ad_pull_error"
} }
EventUtils.event(key, ext = obj) EventUtils.event(key, ext = obj)
LogEx.logDebug(TAG, "$key obj=$obj") LogEx.logDebug(TAG, "${key}_$adUnit obj=$obj")
} }
fun clickAd(responseInfo: ResponseInfo?) = scope.launch { fun clickAd(responseInfo: ResponseInfo?) = scope.launch {
val response = responseInfo?.adapterResponses?.getOrNull(0) val response = responseInfo?.adapterResponses?.getOrNull(0)
val obj = JSONObject() val obj = JSONObject()
obj.put("ad_unit", adUnit)
obj.put("from", from)
obj.put("req_id", reqId) obj.put("req_id", reqId)
obj.put("source", response?.adSourceName) obj.put("source", response?.adSourceName)
obj.put("ad_unit", adUnit)
val credentials = mapOf( val credentials = mapOf(
"placementid" to response?.credentials?.get("placementid"), "placementid" to response?.credentials?.get("placementid"),
...@@ -95,7 +96,6 @@ class AdmobEvent : AdEvent { ...@@ -95,7 +96,6 @@ class AdmobEvent : AdEvent {
) )
obj.put("credentials", credentials.toString()) obj.put("credentials", credentials.toString())
obj.put("session_id", responseInfo?.responseId) obj.put("session_id", responseInfo?.responseId)
obj.put("from", from)
obj.put("networkname", responseInfo?.mediationAdapterClassName) obj.put("networkname", responseInfo?.mediationAdapterClassName)
if (adUnit != "nativeAd") { if (adUnit != "nativeAd") {
EventUtils.event("ad_click", ext = obj) EventUtils.event("ad_click", ext = obj)
...@@ -129,11 +129,11 @@ class AdmobEvent : AdEvent { ...@@ -129,11 +129,11 @@ class AdmobEvent : AdEvent {
fun adShowError(adError: AdError) = scope.launch { fun adShowError(adError: AdError) = scope.launch {
val obj = JSONObject() val obj = JSONObject()
obj.put("ad_unit", "openAd")
obj.put("from", from)
obj.put("req_id", reqId) obj.put("req_id", reqId)
obj.put("reason", adError.message) obj.put("reason", adError.message)
obj.put("code", adError.code) obj.put("code", adError.code)
obj.put("from", from)
obj.put("ad_unit", "openAd")
EventUtils.event("ad_show_error", ext = obj) EventUtils.event("ad_show_error", ext = obj)
LogEx.logDebug(TAG, "ad_show_error $obj") LogEx.logDebug(TAG, "ad_show_error $obj")
} }
......
package com.rgt.superr.business.ads.applovin //package com.rgt.superr.business.ads.applovin
//
import android.os.Bundle //import android.os.Bundle
import com.applovin.mediation.MaxAd //import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdRevenueListener //import com.applovin.mediation.MaxAdRevenueListener
import com.applovin.mediation.MaxError //import com.applovin.mediation.MaxError
import com.applovin.sdk.AppLovinSdk //import com.applovin.sdk.AppLovinSdk
import com.rgt.superr.MyApplication //import com.rgt.superr.MyApplication
import com.rgt.superr.business.ads.AdEvent //import com.rgt.superr.business.ads.AdEvent
import com.rgt.superr.business.ads.taichiPref //import com.rgt.superr.business.ads.taichiPref
import com.rgt.superr.business.ads.taichiSharedPreferencesEditor //import com.rgt.superr.business.ads.taichiSharedPreferencesEditor
import com.rgt.superr.business.helper.EventUtils //import com.rgt.superr.business.helper.EventUtils
import com.rgt.superr.utils.LogEx.logDebug //import com.rgt.superr.utils.LogEx.logDebug
import com.facebook.appevents.AppEventsConstants //import com.facebook.appevents.AppEventsConstants
import com.facebook.appevents.AppEventsLogger //import com.facebook.appevents.AppEventsLogger
import com.google.firebase.analytics.FirebaseAnalytics //import com.google.firebase.analytics.FirebaseAnalytics
import org.json.JSONObject //import org.json.JSONObject
//
//
class AdMaxEvent : AdEvent { //class AdMaxEvent : AdEvent {
//
override val TAG: String = "AdMaxEvent" // override val TAG: String = "AdMaxEvent"
//
constructor(adUnit: String, from: String) : super() { // constructor(adUnit: String, from: String) : super() {
this.adUnit = adUnit // this.adUnit = adUnit
this.from = from // this.from = from
} // }
//
fun pullAd( // fun pullAd(
ad: MaxAd?, // ad: MaxAd?,
error: MaxError? = null // error: MaxError? = null
) { // ) {
val obj = JSONObject() // val obj = JSONObject()
obj.put("UnitId", ad?.adUnitId) // obj.put("UnitId", ad?.adUnitId)
obj.put("ad_unit", adUnit) // obj.put("ad_unit", adUnit)
obj.put( // obj.put(
"creativeId", // "creativeId",
ad?.creativeId // ad?.creativeId
) // )
obj.put("req_id", reqId) // obj.put("req_id", reqId)
obj.put("from", from) // obj.put("from", from)
obj.put("status", if (ad == null) "0" else "1") // obj.put("status", if (ad == null) "0" else "1")
obj.put("networkname", ad?.networkName) // obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement) // obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement) // obj.put("networkplacement", ad?.networkPlacement)
obj.put("latency", ad?.requestLatencyMillis) // obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue) // obj.put("valueMicros", ad?.revenue)
if (error == null) { // if (error == null) {
obj.put("status", "1") // obj.put("status", "1")
} else { // } else {
obj.put("errMsg", error) // obj.put("errMsg", error)
obj.put("status", "2") // obj.put("status", "2")
} // }
EventUtils.event("ad_pull", ext = obj) // EventUtils.event("ad_pull", ext = obj)
logDebug(TAG, "ad_pull $obj") // logDebug(TAG, "ad_pull $obj")
} // }
//
fun clickAd(ad: MaxAd?) { // fun clickAd(ad: MaxAd?) {
//
val obj = JSONObject() // val obj = JSONObject()
obj.put("UnitId", ad?.adUnitId) // obj.put("UnitId", ad?.adUnitId)
obj.put("ad_unit", adUnit) // obj.put("ad_unit", adUnit)
obj.put( // obj.put(
"creativeId", // "creativeId",
ad?.creativeId // ad?.creativeId
) // )
obj.put("networkname", ad?.networkName) // obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement) // obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement) // obj.put("networkplacement", ad?.networkPlacement)
obj.put("latency", ad?.requestLatencyMillis) // obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue) // obj.put("valueMicros", ad?.revenue)
if (!adUnit.equals("nativeAd")) { // if (!adUnit.equals("nativeAd")) {
EventUtils.event("ad_click", ext = obj) // EventUtils.event("ad_click", ext = obj)
} else { // } else {
EventUtils.event("ad_click", ext = obj) // EventUtils.event("ad_click", ext = obj)
} // }
//
} // }
//
fun showAd(ad: MaxAd?, activity: String?) { // fun showAd(ad: MaxAd?, activity: String?) {
val obj = JSONObject() // val obj = JSONObject()
obj.put("UnitId", ad?.adUnitId) // obj.put("UnitId", ad?.adUnitId)
obj.put("ad_unit", adUnit) // obj.put("ad_unit", adUnit)
obj.put( // obj.put(
"creativeId", // "creativeId",
ad?.creativeId // ad?.creativeId
) // )
obj.put("networkname", ad?.networkName) // obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement) // obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement) // obj.put("networkplacement", ad?.networkPlacement)
obj.put("latency", ad?.requestLatencyMillis) // obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue) // obj.put("valueMicros", ad?.revenue)
obj.put("from", activity) // obj.put("from", activity)
obj.put("mediation", "applovin") // obj.put("mediation", "applovin")
if (adUnit != "nativeAd") { // if (adUnit != "nativeAd") {
EventUtils.event("ad_show", ext = obj) // EventUtils.event("ad_show", ext = obj)
} else { // } else {
EventUtils.event("ad_show", ext = obj) // EventUtils.event("ad_show", ext = obj)
} // }
//
} // }
//
//
class EventOnPaidEventListener : MaxAdRevenueListener { // class EventOnPaidEventListener : MaxAdRevenueListener {
override fun onAdRevenuePaid(ad: MaxAd) { // override fun onAdRevenuePaid(ad: MaxAd) {
val params = Bundle() // val params = Bundle()
val currentImpressionRevenue: Double = ad.revenue // In USD // val currentImpressionRevenue: Double = ad.revenue // In USD
val mFirebaseAnalytics = FirebaseAnalytics.getInstance(MyApplication.appContext) // val mFirebaseAnalytics = FirebaseAnalytics.getInstance(MyApplication.appContext)
params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin") // params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin")
params.putString(FirebaseAnalytics.Param.AD_SOURCE, ad.networkName) // params.putString(FirebaseAnalytics.Param.AD_SOURCE, ad.networkName)
params.putString(FirebaseAnalytics.Param.AD_FORMAT, ad.format.getDisplayName()) // params.putString(FirebaseAnalytics.Param.AD_FORMAT, ad.format.getDisplayName())
params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, ad.adUnitId) // params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, ad.adUnitId)
params.putDouble(FirebaseAnalytics.Param.VALUE, currentImpressionRevenue) // params.putDouble(FirebaseAnalytics.Param.VALUE, currentImpressionRevenue)
params.putString(FirebaseAnalytics.Param.CURRENCY, "USD") // params.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params) // mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params)
mFirebaseAnalytics.logEvent("Ad_Impression_Revenue", params) // mFirebaseAnalytics.logEvent("Ad_Impression_Revenue", params)
val previousTaichiTroasCache = taichiPref.getFloat("TaichiTroasCache", 0f) // val previousTaichiTroasCache = taichiPref.getFloat("TaichiTroasCache", 0f)
val currentTaichiTroasCache = previousTaichiTroasCache + currentImpressionRevenue // val currentTaichiTroasCache = previousTaichiTroasCache + currentImpressionRevenue
if (currentTaichiTroasCache >= 0.01) { // if (currentTaichiTroasCache >= 0.01) {
val roasbundle = Bundle() // val roasbundle = Bundle()
roasbundle.putDouble(FirebaseAnalytics.Param.VALUE, currentTaichiTroasCache) // roasbundle.putDouble(FirebaseAnalytics.Param.VALUE, currentTaichiTroasCache)
roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")///(Required)tROAS事件必须 // roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")///(Required)tROAS事件必须
mFirebaseAnalytics.logEvent("Total_Ads_Revenue_001", roasbundle) // 给Taichi用 // mFirebaseAnalytics.logEvent("Total_Ads_Revenue_001", roasbundle) // 给Taichi用
taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)//重新清零,开始计算 // taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)//重新清零,开始计算
//
val logger = AppEventsLogger.newLogger(MyApplication.appContext) // val logger = AppEventsLogger.newLogger(MyApplication.appContext)
val parameters = Bundle() // val parameters = Bundle()
parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "USD") // parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "USD")
logger.logEvent("ad_value", currentTaichiTroasCache, parameters) // logger.logEvent("ad_value", currentTaichiTroasCache, parameters)
} else { // } else {
taichiSharedPreferencesEditor.putFloat( // taichiSharedPreferencesEditor.putFloat(
"TaichiTroasCache", // "TaichiTroasCache",
currentTaichiTroasCache.toFloat() // currentTaichiTroasCache.toFloat()
) // )
taichiSharedPreferencesEditor.commit() // taichiSharedPreferencesEditor.commit()
} // }
val obj = JSONObject() // val obj = JSONObject()
val revenue = ad.revenue // val revenue = ad.revenue
val countryCode = // val countryCode =
AppLovinSdk.getInstance(MyApplication.appContext).configuration.countryCode // AppLovinSdk.getInstance(MyApplication.appContext).configuration.countryCode
val networkName = ad.networkName // val networkName = ad.networkName
val adUnitId = ad.adUnitId // val adUnitId = ad.adUnitId
val adFormat = ad.format // val adFormat = ad.format
val placement = ad.placement // val placement = ad.placement
val networkPlacement = ad.networkPlacement // val networkPlacement = ad.networkPlacement
obj.put("valueMicros", revenue) // obj.put("valueMicros", revenue)
obj.put("currencyCode", countryCode) // obj.put("currencyCode", countryCode)
obj.put("adUnitId", adUnitId) // obj.put("adUnitId", adUnitId)
obj.put("networkName", networkName) // obj.put("networkName", networkName)
obj.put("adFormat", adFormat) // obj.put("adFormat", adFormat)
obj.put("placement", placement) // obj.put("placement", placement)
obj.put("networkPlacement", networkPlacement) // obj.put("networkPlacement", networkPlacement)
EventUtils.event("ad_price", ext = obj) // EventUtils.event("ad_price", ext = obj)
} // }
} // }
//
} //}
\ No newline at end of file \ No newline at end of file
package com.rgt.superr.business.ads.applovin //package com.rgt.superr.business.ads.applovin
//
import android.app.Activity //import android.app.Activity
import android.content.Context //import android.content.Context
import com.applovin.mediation.MaxAd //import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdListener //import com.applovin.mediation.MaxAdListener
import com.applovin.mediation.MaxError //import com.applovin.mediation.MaxError
import com.applovin.mediation.ads.MaxInterstitialAd //import com.applovin.mediation.ads.MaxInterstitialAd
import com.rgt.superr.GlobalConfig //import com.rgt.superr.GlobalConfig
import com.rgt.superr.business.ads.AdCountDownDialog.showAdCountDownDialog //import com.rgt.superr.business.ads.AdCountDownDialog.showAdCountDownDialog
import com.rgt.superr.business.ads.AdEvent //import com.rgt.superr.business.ads.AdEvent
import com.rgt.superr.business.ads.AdState //import com.rgt.superr.business.ads.AdState
import com.rgt.superr.business.ads.AdsShowCallBack //import com.rgt.superr.business.ads.AdsShowCallBack
import com.rgt.superr.business.ads.AdsType //import com.rgt.superr.business.ads.AdsType
import com.rgt.superr.business.ads.LimitUtils //import com.rgt.superr.business.ads.LimitUtils
//
/** ///**
*插屏广告加载显示管理类 // *插屏广告加载显示管理类
*/ // */
class MaxInsertMgr { //class MaxInsertMgr {
//
private var adState = AdState<MaxInterstitialAd>() // private var adState = AdState<MaxInterstitialAd>()
private var showCallBack: AdsShowCallBack? = null // private var showCallBack: AdsShowCallBack? = null
//
fun show( // fun show(
activity: Activity, // activity: Activity,
isUnLimit: Boolean, // isUnLimit: Boolean,
adEvent: AdEvent, // adEvent: AdEvent,
showCallBack: AdsShowCallBack? // showCallBack: AdsShowCallBack?
) { // ) {
//
if (activity.isFinishing || activity.isDestroyed) { // if (activity.isFinishing || activity.isDestroyed) {
return // return
} // }
//
//
if (!adState.loadingAd) { // if (!adState.loadingAd) {
if (!isUnLimit) { // if (!isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) { // if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
showCallBack?.failed(3) // showCallBack?.failed(3)
return // return
} // }
if (LimitUtils.isIntervalLimited(adEvent)) { // if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed(4) // showCallBack?.failed(4)
return // return
} // }
} // }
//
if (!adAvailable() || adState.currentAd == null) { // if (!adAvailable() || adState.currentAd == null) {
loadAd(activity, adEvent) // loadAd(activity, adEvent)
return // return
} // }
//
if (showCallBack != null) { // if (showCallBack != null) {
this.showCallBack = showCallBack // this.showCallBack = showCallBack
if (adState.adDialog == null) { // if (adState.adDialog == null) {
adState.adDialog = activity.showAdCountDownDialog() // adState.adDialog = activity.showAdCountDownDialog()
} // }
adEvent.adPrepareShow() // adEvent.adPrepareShow()
} // }
//
//
if (adState.currentAd?.isReady == false) { // if (adState.currentAd?.isReady == false) {
loadAd(activity, adEvent) // loadAd(activity, adEvent)
return // return
} // }
showReadyAd(adEvent) // showReadyAd(adEvent)
} // }
//
} // }
//
//
private fun showReadyAd(adEvent: AdEvent) { // private fun showReadyAd(adEvent: AdEvent) {
adState.currentAd?.run { // adState.currentAd?.run {
setListener(object : MaxAdListener { // setListener(object : MaxAdListener {
override fun onAdLoaded(p0: MaxAd) = Unit // override fun onAdLoaded(p0: MaxAd) = Unit
override fun onAdLoadFailed(p0: String, p1: MaxError) = Unit // override fun onAdLoadFailed(p0: String, p1: MaxError) = Unit
//
override fun onAdDisplayed(ad: MaxAd) { // override fun onAdDisplayed(ad: MaxAd) {
//
adState.onAdDisplayed() // adState.onAdDisplayed()
showCallBack?.show() // showCallBack?.show()
//
(adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName) // (adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName)
//计数 // //计数
LimitUtils.addDisplayNum() // LimitUtils.addDisplayNum()
} // }
//
override fun onAdDisplayFailed(ad: MaxAd, error: MaxError) { // override fun onAdDisplayFailed(ad: MaxAd, error: MaxError) {
adState.onAdDisplayFailed() // adState.onAdDisplayFailed()
showCallBack?.adFailed() // showCallBack?.adFailed()
showCallBack = null // showCallBack = null
//
(adEvent as AdMaxEvent).adShowError(error) // (adEvent as AdMaxEvent).adShowError(error)
} // }
//
override fun onAdHidden(p0: MaxAd) { // override fun onAdHidden(p0: MaxAd) {
//
adState.onAdHidden() // adState.onAdHidden()
showCallBack?.close() // showCallBack?.close()
//
loadAd(activity.applicationContext, AdMaxEvent("interAd", "preload")) // loadAd(activity.applicationContext, AdMaxEvent("interAd", "preload"))
} // }
//
override fun onAdClicked(ad: MaxAd) { // override fun onAdClicked(ad: MaxAd) {
(adEvent as AdMaxEvent).clickAd(ad) // (adEvent as AdMaxEvent).clickAd(ad)
//计数 // //计数
LimitUtils.addClickNum() // LimitUtils.addClickNum()
} // }
//
//
}) // })
setRevenueListener(AdMaxEvent.EventOnPaidEventListener()) // setRevenueListener(AdMaxEvent.EventOnPaidEventListener())
//
showAd(activity) // showAd(activity)
} // }
} // }
//
//
fun loadAd( // fun loadAd(
context: Context, // context: Context,
adEvent: AdEvent, // adEvent: AdEvent,
loadCallback: (() -> Unit)? = null // loadCallback: (() -> Unit)? = null
) { // ) {
if (!adEvent.isUnLimit) { // if (!adEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) { // if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
this.showCallBack?.close(4) // this.showCallBack?.close(4)
this.showCallBack = null // this.showCallBack = null
return // return
} // }
} // }
//
if (!adState.loadingAd) { // if (!adState.loadingAd) {
adState.loadingAd = true // adState.loadingAd = true
//
adEvent.adPulStart() // adEvent.adPulStart()
//
adState.currentAd = MaxInterstitialAd(GlobalConfig.ID_MAX_INTER, context) // adState.currentAd = MaxInterstitialAd(GlobalConfig.ID_MAX_INTER, context)
adState.currentAd?.setListener(object : MaxAdListener { // adState.currentAd?.setListener(object : MaxAdListener {
//
override fun onAdDisplayed(p0: MaxAd) = Unit // override fun onAdDisplayed(p0: MaxAd) = Unit
override fun onAdHidden(p0: MaxAd) = Unit // override fun onAdHidden(p0: MaxAd) = Unit
override fun onAdClicked(p0: MaxAd) = Unit // override fun onAdClicked(p0: MaxAd) = Unit
override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) = Unit // override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) = Unit
//
override fun onAdLoaded(ad: MaxAd) { // override fun onAdLoaded(ad: MaxAd) {
adState.onAdLoaded(null, adEvent) // adState.onAdLoaded(null, adEvent)
loadCallback?.invoke() // loadCallback?.invoke()
//
(adEvent as AdMaxEvent).pullAd(ad) // (adEvent as AdMaxEvent).pullAd(ad)
LimitUtils.addRequestNum() // LimitUtils.addRequestNum()
} // }
//
override fun onAdLoadFailed(ad: String, error: MaxError) { // override fun onAdLoadFailed(ad: String, error: MaxError) {
adState.onAdLoadFailed() // adState.onAdLoadFailed()
//
(adEvent as AdMaxEvent).pullAd(null, error) // (adEvent as AdMaxEvent).pullAd(null, error)
//
showCallBack?.adFailed(5) // showCallBack?.adFailed(5)
showCallBack = null // showCallBack = null
} // }
//
}) // })
adState.currentAd?.loadAd() // adState.currentAd?.loadAd()
} // }
} // }
//
//
private fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30 // private fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30
} //}
\ No newline at end of file \ No newline at end of file
package com.rgt.superr.business.ads.applovin //package com.rgt.superr.business.ads.applovin
//
import androidx.annotation.LayoutRes //import androidx.annotation.LayoutRes
import com.applovin.mediation.MaxAd //import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxError //import com.applovin.mediation.MaxError
import com.applovin.mediation.nativeAds.MaxNativeAdListener //import com.applovin.mediation.nativeAds.MaxNativeAdListener
import com.applovin.mediation.nativeAds.MaxNativeAdLoader //import com.applovin.mediation.nativeAds.MaxNativeAdLoader
import com.applovin.mediation.nativeAds.MaxNativeAdView //import com.applovin.mediation.nativeAds.MaxNativeAdView
import com.rgt.superr.GlobalConfig //import com.rgt.superr.GlobalConfig
import com.rgt.superr.business.ads.AdsType //import com.rgt.superr.business.ads.AdsType
import com.rgt.superr.business.ads.LimitUtils //import com.rgt.superr.business.ads.LimitUtils
import com.rgt.superr.business.ads.NativeParentView //import com.rgt.superr.business.ads.NativeParentView
import com.rgt.superr.business.helper.EventUtils //import com.rgt.superr.business.helper.EventUtils
import org.json.JSONObject //import org.json.JSONObject
import java.util.UUID //import java.util.UUID
//
/** ///**
*原生广告加载显示管理类 // *原生广告加载显示管理类
*/ // */
class MaxNativeMgr { //class MaxNativeMgr {
//
/** // /**
* 上一次的缓存成功时间 // * 上一次的缓存成功时间
*/ // */
protected var lastTime: Long = 0 // protected var lastTime: Long = 0
//
/** // /**
* 原生广告 // * 原生广告
*/ // */
private var currentAd: MaxAd? = null // private var currentAd: MaxAd? = null
private var currentLoader: MaxNativeAdLoader? = null // private var currentLoader: MaxNativeAdLoader? = null
//
//
private fun loadAd( // private fun loadAd(
adMaxEvent: AdMaxEvent, // adMaxEvent: AdMaxEvent,
parent: NativeParentView, // parent: NativeParentView,
@LayoutRes layout: Int // @LayoutRes layout: Int
) { // ) {
//
if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) return // if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) return
//
val reqId = UUID.randomUUID().toString() // val reqId = UUID.randomUUID().toString()
val obj = JSONObject() // val obj = JSONObject()
obj.put("req_id", reqId) // obj.put("req_id", reqId)
obj.put("ad_type", "nativeAd") // obj.put("ad_type", "nativeAd")
//
val nativeAdLoader = MaxNativeAdLoader(GlobalConfig.ID_MAX_NATIVE, parent.context) // val nativeAdLoader = MaxNativeAdLoader(GlobalConfig.ID_MAX_NATIVE, parent.context)
//
nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() { // nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() {
//
override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView?, ad: MaxAd) { // override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView?, ad: MaxAd) {
currentLoader = nativeAdLoader // currentLoader = nativeAdLoader
currentAd = ad // currentAd = ad
lastTime = System.currentTimeMillis() // lastTime = System.currentTimeMillis()
adMaxEvent.pullAd(ad) // adMaxEvent.pullAd(ad)
nativeAdLoader.setRevenueListener(AdMaxEvent.EventOnPaidEventListener()) // nativeAdLoader.setRevenueListener(AdMaxEvent.EventOnPaidEventListener())
show(adMaxEvent, parent, layout) // show(adMaxEvent, parent, layout)
} // }
//
override fun onNativeAdLoadFailed(adUnitId: String, error: MaxError) { // override fun onNativeAdLoadFailed(adUnitId: String, error: MaxError) {
adMaxEvent.pullAd(null, error) // adMaxEvent.pullAd(null, error)
} // }
//
override fun onNativeAdClicked(ad: MaxAd) { // override fun onNativeAdClicked(ad: MaxAd) {
//
} // }
//
}) // })
nativeAdLoader.loadAd() // nativeAdLoader.loadAd()
} // }
//
fun show( // fun show(
adMaxEvent: AdMaxEvent, // adMaxEvent: AdMaxEvent,
parent: NativeParentView, // parent: NativeParentView,
@LayoutRes layout: Int, // @LayoutRes layout: Int,
nativeCallBack: ((Any?) -> Unit)? = null // nativeCallBack: ((Any?) -> Unit)? = null
) { // ) {
if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) { // if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) {
currentLoader = null // currentLoader = null
currentAd = null // currentAd = null
return // return
} // }
val nativeAd = currentAd // val nativeAd = currentAd
val nativeLoader = currentLoader // val nativeLoader = currentLoader
if ((nativeAd == null || nativeLoader == null).also { // if ((nativeAd == null || nativeLoader == null).also {
if (it) { // if (it) {
val obj2 = JSONObject() // val obj2 = JSONObject()
obj2.put("reason", "no_ad") // obj2.put("reason", "no_ad")
obj2.put("ad_unit", "nativeAd") // obj2.put("ad_unit", "nativeAd")
EventUtils.event("ad_show_error", ext = obj2) // EventUtils.event("ad_show_error", ext = obj2)
} // }
} || (!adAvailable()).also { // } || (!adAvailable()).also {
if (it) { // if (it) {
val obj2 = JSONObject() // val obj2 = JSONObject()
obj2.put("ad_unit", "nativeAd") // obj2.put("ad_unit", "nativeAd")
EventUtils.event("ad_expire", ext = obj2) // EventUtils.event("ad_expire", ext = obj2)
} // }
}) { // }) {
//缓存过期了就清空 // //缓存过期了就清空
currentLoader = null // currentLoader = null
currentAd = null // currentAd = null
loadAd(AdMaxEvent("nativeAd", "preload"), parent, layout) // loadAd(AdMaxEvent("nativeAd", "preload"), parent, layout)
return // return
} // }
val obj = JSONObject() // val obj = JSONObject()
obj.put("ad_unit", "nativeAd") // obj.put("ad_unit", "nativeAd")
EventUtils.event("ad_prepare_show", ext = obj) // EventUtils.event("ad_prepare_show", ext = obj)
parent.setNativeAd(nativeLoader!!, nativeAd!!, layout) // parent.setNativeAd(nativeLoader!!, nativeAd!!, layout)
nativeCallBack?.invoke(nativeAd) // nativeCallBack?.invoke(nativeAd)
} // }
//
private fun adAvailable(): Boolean { // private fun adAvailable(): Boolean {
return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30 // return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
} // }
} //}
\ No newline at end of file \ No newline at end of file
package com.rgt.superr.business.ads.applovin //package com.rgt.superr.business.ads.applovin
//
import android.app.Activity //import android.app.Activity
import android.content.Context //import android.content.Context
import com.applovin.mediation.MaxAd //import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdListener //import com.applovin.mediation.MaxAdListener
import com.applovin.mediation.MaxError //import com.applovin.mediation.MaxError
import com.applovin.mediation.ads.MaxAppOpenAd //import com.applovin.mediation.ads.MaxAppOpenAd
import com.rgt.superr.GlobalConfig //import com.rgt.superr.GlobalConfig
import com.rgt.superr.business.ads.AdEvent //import com.rgt.superr.business.ads.AdEvent
import com.rgt.superr.business.ads.AdState //import com.rgt.superr.business.ads.AdState
import com.rgt.superr.business.ads.AdsShowCallBack //import com.rgt.superr.business.ads.AdsShowCallBack
import com.rgt.superr.business.ads.AdsType //import com.rgt.superr.business.ads.AdsType
import com.rgt.superr.business.ads.LimitUtils //import com.rgt.superr.business.ads.LimitUtils
//
/** ///**
* 开屏广告加载显示管理类 // * 开屏广告加载显示管理类
*/ // */
class MaxOpenMgr { //class MaxOpenMgr {
//
private val adState = AdState<MaxAppOpenAd>() // private val adState = AdState<MaxAppOpenAd>()
private var showCallBack: AdsShowCallBack? = null // private var showCallBack: AdsShowCallBack? = null
//
fun show(activity: Activity, isUnLimit: Boolean, adEvent: AdEvent, showCallBack: AdsShowCallBack?) { // fun show(activity: Activity, isUnLimit: Boolean, adEvent: AdEvent, showCallBack: AdsShowCallBack?) {
if (activity.isFinishing || activity.isDestroyed) { // if (activity.isFinishing || activity.isDestroyed) {
return // return
} // }
//
if (showCallBack != null) { // if (showCallBack != null) {
this.showCallBack = showCallBack // this.showCallBack = showCallBack
adEvent.adPrepareShow() // adEvent.adPrepareShow()
} // }
//
if (!adState.loadingAd) { // if (!adState.loadingAd) {
//
if (!isUnLimit) { // if (!isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) { // if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
showCallBack?.failed() // showCallBack?.failed()
return // return
} // }
if (LimitUtils.isIntervalLimited(adEvent)) { // if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed() // showCallBack?.failed()
return // return
} // }
} // }
//
if (!adAvailable() || adState.currentAd == null) { // if (!adAvailable() || adState.currentAd == null) {
loadAd(activity, isUnLimit, adEvent) // loadAd(activity, isUnLimit, adEvent)
return // return
} // }
//
if (adState.currentAd?.isReady != true) { // if (adState.currentAd?.isReady != true) {
loadAd(activity, isUnLimit, adEvent) // loadAd(activity, isUnLimit, adEvent)
return // return
} // }
showReadyAd(activity, adEvent) // showReadyAd(activity, adEvent)
} // }
//
//
} // }
//
//
private fun showReadyAd(activity: Activity, adEvent: AdEvent) { // private fun showReadyAd(activity: Activity, adEvent: AdEvent) {
adState.currentAd?.run { // adState.currentAd?.run {
setListener(object : MaxAdListener { // setListener(object : MaxAdListener {
override fun onAdLoaded(p0: MaxAd) { // override fun onAdLoaded(p0: MaxAd) {
//
} // }
//
override fun onAdDisplayed(ad: MaxAd) { // override fun onAdDisplayed(ad: MaxAd) {
adState.onAdDisplayed() // adState.onAdDisplayed()
showCallBack?.show() // showCallBack?.show()
//
LimitUtils.addDisplayNum() // LimitUtils.addDisplayNum()
(adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName) // (adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName)
} // }
//
override fun onAdHidden(p0: MaxAd) { // override fun onAdHidden(p0: MaxAd) {
adState.onAdHidden() // adState.onAdHidden()
showCallBack?.close() // showCallBack?.close()
showCallBack = null // showCallBack = null
//
loadAd(activity.applicationContext, false, AdMaxEvent("openAd", "preload")) // loadAd(activity.applicationContext, false, AdMaxEvent("openAd", "preload"))
} // }
//
override fun onAdClicked(ad: MaxAd) { // override fun onAdClicked(ad: MaxAd) {
(adEvent as AdMaxEvent).clickAd(ad) // (adEvent as AdMaxEvent).clickAd(ad)
//计数 // //计数
LimitUtils.addClickNum() // LimitUtils.addClickNum()
} // }
//
override fun onAdLoadFailed(p0: String, p1: MaxError) { // override fun onAdLoadFailed(p0: String, p1: MaxError) {
//
} // }
//
override fun onAdDisplayFailed(p0: MaxAd, error: MaxError) { // override fun onAdDisplayFailed(p0: MaxAd, error: MaxError) {
adState.onAdDisplayFailed() // adState.onAdDisplayFailed()
showCallBack?.adFailed() // showCallBack?.adFailed()
showCallBack = null // showCallBack = null
adEvent.adShowError(error) // adEvent.adShowError(error)
} // }
//
}) // })
//
showAd() // showAd()
} // }
} // }
//
fun loadAd(context: Context, isUnLimit: Boolean, adEvent: AdEvent) { // fun loadAd(context: Context, isUnLimit: Boolean, adEvent: AdEvent) {
//
if (!isUnLimit) { // if (!isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) { // if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
this.showCallBack?.close() // this.showCallBack?.close()
this.showCallBack = null // this.showCallBack = null
return // return
} // }
} // }
//
if (!adState.loadingAd) { // if (!adState.loadingAd) {
adState.loadingAd = true // adState.loadingAd = true
//
adEvent.adPulStart() // adEvent.adPulStart()
//
adState.currentAd = MaxAppOpenAd(GlobalConfig.ID_MAX_OPEN, context) // adState.currentAd = MaxAppOpenAd(GlobalConfig.ID_MAX_OPEN, context)
adState.currentAd?.setListener(object : MaxAdListener { // adState.currentAd?.setListener(object : MaxAdListener {
override fun onAdLoaded(ad: MaxAd) { // override fun onAdLoaded(ad: MaxAd) {
adState.onAdLoaded(null, adEvent) // adState.onAdLoaded(null, adEvent)
(adEvent as AdMaxEvent).pullAd(ad) // (adEvent as AdMaxEvent).pullAd(ad)
LimitUtils.addRequestNum() // LimitUtils.addRequestNum()
} // }
//
override fun onAdDisplayed(p0: MaxAd) { // override fun onAdDisplayed(p0: MaxAd) {
//
} // }
//
override fun onAdHidden(p0: MaxAd) { // override fun onAdHidden(p0: MaxAd) {
//
} // }
//
override fun onAdClicked(p0: MaxAd) { // override fun onAdClicked(p0: MaxAd) {
} // }
//
override fun onAdLoadFailed(p0: String, error: MaxError) { // override fun onAdLoadFailed(p0: String, error: MaxError) {
adState.onAdLoadFailed() // adState.onAdLoadFailed()
showCallBack?.adFailed() // showCallBack?.adFailed()
showCallBack = null // showCallBack = null
(adEvent as AdMaxEvent).pullAd(null, error) // (adEvent as AdMaxEvent).pullAd(null, error)
} // }
//
override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) { // override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) {
//
} // }
//
}) // })
adState.currentAd?.loadAd() // adState.currentAd?.loadAd()
} // }
} // }
//
//
fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30 // fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30
} //}
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment