Commit 9249decf authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 3b5714d4
package com.mints.bcurd.ad
import android.app.Activity
import com.mints.bcurd.ad.AdManager
import com.mints.bcurd.ad.express.ExpressManager
import com.mints.bcurd.common.Constant
/**
* 描述:广告管理
* 作者:孟崔广
* 时间:2021/08/10 10:51
*/
object AdHelper {
const val AD_NO_SHOWTIME_OUT = 50 // 广告请示成功但在规定时间内未展示
const val AD_REQUEST_TIME_OUT = 1 // 广告预加载时长超时
/**
* 预加载应用内广告
*/
fun preInAd(activity: Activity?) {
// 预加载信息流
ExpressManager.loadExpress(Constant.CARRIER_SPLASH)
activity?.let {
AdManager.instance.splashPreLoadAll(activity)
}
}
}
\ No newline at end of file
......@@ -5,18 +5,14 @@ import android.widget.FrameLayout
import com.bytedance.msdk.adapter.pangle.PangleNetworkRequestInfo
import com.bytedance.msdk.api.AdError
import com.bytedance.msdk.api.v2.GMAdConstant
import com.bytedance.msdk.api.v2.GMNetworkRequestInfo
import com.bytedance.msdk.api.v2.ad.splash.GMSplashAd
import com.bytedance.msdk.api.v2.ad.splash.GMSplashAdListener
import com.bytedance.msdk.api.v2.ad.splash.GMSplashAdLoadCallback
import com.bytedance.msdk.api.v2.slot.GMAdSlotSplash
import com.mints.tanzhi.WifiAdStatusListener
import com.mints.tanzhi.AdHelper
import com.mints.tanzhi.AdReportManager
import com.mints.tanzhi.AdReportManager.eventSplash
import com.mints.bcurd.ad.AdHelper
import com.mints.bcurd.ad.WifiAdStatusListener
import com.mints.bcurd.common.Constant
import com.mints.bcurd.manager.CsjGroMoreManager
import com.mints.bcurd.manager.CsjGroMoreManager.getInMoneySplashId
import com.mints.bcurd.manager.TTGroMoreAdManagerHolder
import com.mints.bcurd.manager.TrackManager
import com.mints.bcurd.utils.LogUtil
......@@ -48,14 +44,6 @@ object InMoneySplash {
*/
fun preLoadAd(activity: Activity) {
val weakActivity = WeakReference<Activity>(activity)
// 不加载广告
// if (!AppPreferencesManager.get().getBoolean(Constant.GROMORE_LOAD_SPLASH, true)) {
// isLoadSuccess = 0
// LogUtil.d(TAG, "开屏 不加载广告 load")
//
// return
// }
val isOversped = TimeRender.isOverspedMin(adLoadTime, AdHelper.AD_NO_SHOWTIME_OUT)
val isPreingOversped = TimeRender.isOverspedMin(adPreingTime, AdHelper.AD_REQUEST_TIME_OUT)
LogUtil.d(
......@@ -71,19 +59,7 @@ object InMoneySplash {
isLoadSuccess = 1
LogUtil.d(TAG, "gromore应用内开屏广告-> 2、执行预加载去了=$isLoadSuccess")
adUnitId = getInMoneySplashId()
eventSplash(
AdReportManager.EVENT_TYPE_REQUEST,
"",
adUnitId,
"",
"",
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
adUnitId = CsjGroMoreManager.IN_MONEY_SPLASH_CODE
mTTSplashAd = GMSplashAd(weakActivity.get(), adUnitId)
val adSlot = GMAdSlotSplash.Builder()
......@@ -94,95 +70,31 @@ object InMoneySplash {
.build()
//自定义兜底方案 选择使用
val gmNetworkRequestInfo =
PangleNetworkRequestInfo(TTGroMoreAdManagerHolder.CURRENT_USE_APPID, "102165872")
// val gmNetworkRequestInfo =
// PangleNetworkRequestInfo(TTGroMoreAdManagerHolder.CURRENT_USE_APPID, "102165872")
//step4:请求广告,调用开屏广告异步请求接口,对请求回调的广告作渲染处理
mTTSplashAd?.setAdSplashListener(mSplashAdListener)
mTTSplashAd?.loadAd(adSlot, gmNetworkRequestInfo, object : GMSplashAdLoadCallback {
// mTTSplashAd?.loadAd(adSlot, object : GMSplashAdLoadCallback {
// mTTSplashAd?.loadAd(adSlot, gmNetworkRequestInfo, object : GMSplashAdLoadCallback {
mTTSplashAd?.loadAd(adSlot, object : GMSplashAdLoadCallback {
override fun onSplashAdLoadFail(adError: AdError) {
AdReportManager.lazyRegister(
Constant.GRO_MORE_ADTYPE0,
AdReportManager.REQUEST_FAIL,
adError.code.toString(),
adError.message
)
LogUtil.d(
TAG,
"gromore应用内开屏广告--> 3、Gromore onSplashAdLoadFail " + adError.message+"list ==>"+JsonUtil.toJson(mTTSplashAd?.adLoadInfoList)
)
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_FAIL,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
adError.code.toString(),
adError.message,
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
isLoadSuccess = 0
}
override fun onSplashAdLoadSuccess() {
AdReportManager.lazyRegister(
Constant.GRO_MORE_ADTYPE0,
AdReportManager.REQUEST_SUC,
"",
""
)
LogUtil.d(TAG, "gromore应用内开屏广告--> 3、Gromore onSplashAdLoadSuccess ")
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SUC,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
isLoadSuccess = 2
}
override fun onAdLoadTimeout() {
AdReportManager.lazyRegister(
Constant.GRO_MORE_ADTYPE0,
AdReportManager.REQUEST_FAIL,
"",
""
)
LogUtil.d(TAG, "gromore应用内开屏广告--> 3、Gromore onAdLoadTimeout ")
isLoadSuccess = 0
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SHOWFAIL,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
"超时"
)
}
}
})
}
......@@ -227,36 +139,8 @@ object InMoneySplash {
override fun onAdClicked() {
LogUtil.d(TAG, "gromore应用内开屏广告--> 7、onAdClicked ")
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_CLICK,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
if (isClickScreen) {
// 防止重复
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_REPEAT,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
isClickScreen = false
}
}
......@@ -264,32 +148,6 @@ object InMoneySplash {
override fun onAdShow() {
LogUtil.d(TAG, "gromore应用内开屏广告--> 6、onAdShow ")
isShowAd = true
if (mTTSplashAd != null) {
val vo = HashMap<String, Any>()
mTTSplashAd?.let {
vo["adcode"] = it.showEcpm.adNetworkRitId
vo["ecpm"] = it.showEcpm.preEcpm
vo["adSource"] = it.showEcpm.adNetworkPlatformName
vo["adType"] = Constant.GRO_MORE_ADTYPE0
vo["adid"] = getInMoneySplashId()
vo["isAddCoin"] = false
TrackManager.getInstance().cmtGroMoreInfo(vo)
}
}
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SHOW,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
}
override fun onAdShowFail(adError: AdError) {
......@@ -298,20 +156,6 @@ object InMoneySplash {
"gromore应用内开屏广告--> 6、onAdShowFail ${adError.code} ${adError.message}"
)
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_SHOWFAIL,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
adError.code.toString(),
adError.message,
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
"onAdShowFail"
)
}
wifiAdStatusListener?.adFail()
}
......@@ -325,20 +169,6 @@ object InMoneySplash {
LogUtil.d(TAG, "gromore应用内开屏广告--> 7、onAdDismiss ")
wifiAdStatusListener?.adClose()
if (mTTSplashAd != null) {
eventSplash(
AdReportManager.EVENT_TYPE_CLOSE,
mTTSplashAd?.showEcpm?.adNetworkRitId,
adUnitId,
mTTSplashAd?.showEcpm?.preEcpm,
mTTSplashAd?.showEcpm?.adNetworkPlatformName,
"",
"",
System.currentTimeMillis(),
Constant.CARRIER_SPLASH,
""
)
}
}
}
......
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