Commit bf1c775b authored by wanglei's avatar wanglei

[商业化]上报链

parent b3860549
......@@ -26,25 +26,25 @@ abstract class AdEvent {
var adUnit: String = ""
var from: String = ""
val reqId = UUID.randomUUID().toString()
var reqId = UUID.randomUUID().toString()
var isUnLimit: Boolean = false
fun adPrepareShow() {
val obj1 = JSONObject()
obj1.put("ad_unit", adUnit)
obj1.put("req_id", reqId)
obj1.put("from", from)
obj1.put("req_id", reqId)
EventUtils.event("ad_prepare_show", ext = obj1)
LogEx.logDebug(TAG, "ad_prepare_show_$adUnit $obj1")
}
fun adPulStart() {
val obj = JSONObject()
obj.put("req_id", reqId)
obj.put("ad_unit", adUnit)
obj.put("ad_type", adUnit)
obj.put("from", from)
obj.put("req_id", reqId)
obj.put("ad_type", adUnit)
EventUtils.event("ad_pull_start", ext = obj)
LogEx.logDebug(TAG, "ad_pull_start_$adUnit $obj")
}
......
......@@ -182,13 +182,13 @@ object AdsMgr {
val from = activity::class.java.simpleName
if (adsConfigBean.adSwitch) {
val admobEvent = AdmobEvent("openAd", from)
val admobEvent = AdmobEvent("openAd", from).apply { this.isUnLimit = isUnLimit }
if (isAdmobInit) {
adOpenMgr.show(activity, isUnLimit, admobEvent, showCallBack)
adOpenMgr.show(activity, admobEvent, showCallBack)
} else {
admobInitCallBack = {
}
adOpenMgr.show(activity, isUnLimit, admobEvent, showCallBack)
adOpenMgr.show(activity, admobEvent, showCallBack)
}
} else {
if (isMaxInit) {
......@@ -229,7 +229,7 @@ object AdsMgr {
LogEx.logDebug("showAd", "adSwitch=${adsConfigBean.adSwitch}")
val from = activity::class.java.simpleName
if (adsConfigBean.adSwitch) {
adInterMgr.show(activity, isUnLimit, AdmobEvent("interAd", from), showCallBack)
adInterMgr.show(activity, AdmobEvent("interAd", from).apply { this.isUnLimit = isUnLimit }, showCallBack)
} else {
maxInsertMgr.show(activity, isUnLimit, AdMaxEvent("interAd", from), showCallBack)
}
......
......@@ -3,6 +3,7 @@ package com.base.appzxhy.business.ads
abstract class AdsShowCallBack {
var adShowed: Boolean = false
var nextCalled: Boolean = false
open fun show() {
adShowed = true
......@@ -10,18 +11,27 @@ abstract class AdsShowCallBack {
open fun failed(where: Int = 0) {
adShowed = false
if (!nextCalled) {
nextCalled = true
next()
}
}
open fun adFailed(where: Int = 0) {
adShowed = false
if (!nextCalled) {
nextCalled = true
next()
}
}
open fun close(where: Int = 0) {
adShowed = false
if (!nextCalled) {
nextCalled = true
next()
}
}
abstract fun next()
......
......@@ -146,10 +146,10 @@ object LimitUtils {
/**
* 开屏和插页广告的显示间隔限制
*/
fun isIntervalLimited(adEvent: AdEvent): Boolean {
fun isIntervalLimited(adEvent: AdEvent?): Boolean {
val flag = ((System.currentTimeMillis() - openInterLastShowTime) / 1000).toInt() < (AdConfigBean.adsConfigBean.timeInterval)
if (flag) {
adEvent.adShowError("ad in timeInterval")
adEvent?.adShowError("ad in timeInterval")
}
return flag
}
......
......@@ -36,20 +36,17 @@ class AdInterMgr {
fun show(
activity: Activity,
isUnLimit: Boolean,
adEvent: AdEvent,
showCallBack: AdsShowCallBack? = null
) {
if (activity.isFinishing || activity.isDestroyed) {
showCallBack?.failed(0)
adState.onAdDisplayFailed()
return
}
val nowAdEvent = adState.currentAdEvent ?: adEvent
nowAdEvent.from = adEvent.from
nowAdEvent.isUnLimit = isUnLimit
val nowAdEvent = adEvent
//currentAdEvent!=null 有缓存广告,关联reqId
adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId }
if (!nowAdEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, nowAdEvent)) {
......@@ -73,13 +70,14 @@ class AdInterMgr {
adState.adDialog?.dismiss()
}
nowAdEvent.adPrepareShow()
LogEx.logDebug(adEvent.TAG, "needLoad=$needLoad")
if (needLoad) {
if (!adState.loadingAd) {
LogEx.logDebug(adEvent.TAG, "inter adState !loadingAd")
loadAd(activity, adEvent) {
loadAd(activity, nowAdEvent) {
showReadyAd()
}
} else {
......@@ -99,10 +97,14 @@ class AdInterMgr {
private fun showReadyAd() {
val ac = adState.activityRef?.get()
LogEx.logDebug("AdmobEvent", "inter showReadyAd ac=$ac currentAd=${adState.currentAd}")
if (ac == null || ac.isFinishing || ac.isDestroyed) {
LogEx.logDebug(TAG, "showReadyAd ac=null isFinishing isDestroyed")
showCallBack?.failed()
adState.onAdDisplayFailed()
return
}
adState.currentAd?.run {
val adEvent = (adState.currentAdEvent as AdmobEvent?)
......@@ -149,11 +151,11 @@ class AdInterMgr {
}
val activity = adState.activityRef?.get()
activity?.let {
if (AdConfigBean.adsConfigBean.showCountdown){
if (AdConfigBean.adsConfigBean.showCountdown) {
createUICountdownTimer(adState.adDialog) {
show(it)
}
}else{
} else {
show(it)
}
}
......@@ -182,7 +184,6 @@ class AdInterMgr {
}
adState.loadingAd = true
adState.currentAdEvent = adEvent
adEvent.adPulStart()
InterstitialAd.load(
......@@ -202,9 +203,13 @@ class AdInterMgr {
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
adState.onAdLoadFailed()
(adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
if (loadCallBack != null) {
adState.onAdDisplayFailed()
}
showCallBack?.adFailed()
showCallBack = null
(adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
}
}
)
......
......@@ -32,7 +32,6 @@ class AdOpenMgr {
fun show(
activity: Activity,
isUnLimit: Boolean,
adEvent: AdEvent,
showCallBack: AdsShowCallBack?
) {
......@@ -40,9 +39,8 @@ class AdOpenMgr {
return
}
val nowAdEvent = adState.currentAdEvent ?: adEvent
nowAdEvent.from = adEvent.from
nowAdEvent.isUnLimit = isUnLimit
val nowAdEvent = adEvent
adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId }
if (!nowAdEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, nowAdEvent)) {
......@@ -161,7 +159,6 @@ class AdOpenMgr {
}
adState.loadingAd = true
adState.currentAdEvent = adEvent
adEvent.adPulStart()
AppOpenAd.load(
......
......@@ -51,6 +51,8 @@ class AdmobEvent : AdEvent {
) = scope.launch {
var key = "ad_pull"
val obj = JSONObject()
obj.put("ad_unit", adUnit)
obj.put("from", from)
obj.put("req_id", reqId)
if (responseInfo != null) {
val response = responseInfo.adapterResponses.getOrNull(0)
......@@ -67,8 +69,6 @@ class AdmobEvent : AdEvent {
obj.put("session_id", responseInfo.responseId)
}
obj.put("networkname", responseInfo?.mediationAdapterClassName)
obj.put("ad_unit", adUnit)
obj.put("from", from)
if (error == null) {
obj.put("status", "1")
} else {
......@@ -107,9 +107,10 @@ class AdmobEvent : AdEvent {
fun showAd(responseInfo: ResponseInfo?, activity: Activity? = null) = scope.launch {
val response = responseInfo?.adapterResponses?.getOrNull(0)
val obj = JSONObject()
obj.put("ad_unit", adUnit)
obj.put("from", activity?.javaClass?.simpleName)
obj.put("req_id", reqId)
obj.put("source", response?.adSourceName)
obj.put("ad_unit", adUnit)
obj.put("networkname", responseInfo?.mediationAdapterClassName)
val credentials = mapOf(
"placementid" to response?.credentials?.get("placementid"),
......@@ -118,7 +119,6 @@ class AdmobEvent : AdEvent {
)
obj.put("credentials", credentials.toString())
obj.put("session_id", responseInfo?.responseId)
obj.put("from", activity?.javaClass?.simpleName)
if (adUnit != "nativeAd") {
EventUtils.event("ad_show", ext = obj)
} else {
......
......@@ -200,6 +200,7 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
if (this.adShowed) {
action.invoke()
} else {
LogEx.logDebug("AdmobEvent", "inter open show inter")
AdsMgr.showInsert(this@SplashActivity, showCallBack = object : AdsShowCallBack() {
override fun next() {
action.invoke()
......
......@@ -77,7 +77,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginBottom="67dp"
android:layout_marginBottom="@dimen/dp_38"
android:text="@string/screenshots_totally"
android:textColor="@color/white"
android:textSize="16sp"
......
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