|
@@ -2,31 +2,37 @@ package com.composition.android.ad.gromore.load
|
|
|
|
|
|
import android.app.Activity
|
|
|
import android.content.Context
|
|
|
+import android.os.Bundle
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
-import com.bytedance.msdk.api.AdError
|
|
|
-import com.bytedance.msdk.api.format.TTNativeAdView
|
|
|
-import com.bytedance.msdk.api.reward.RewardItem
|
|
|
-import com.bytedance.msdk.api.v2.ad.banner.GMBannerAd
|
|
|
-import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAd
|
|
|
-import com.bytedance.msdk.api.v2.ad.interstitialFull.GMInterstitialFullAdListener
|
|
|
-import com.bytedance.msdk.api.v2.ad.nativeAd.GMNativeAd
|
|
|
-import com.bytedance.msdk.api.v2.ad.nativeAd.GMUnifiedNativeAd
|
|
|
-import com.bytedance.msdk.api.v2.ad.reward.GMRewardAd
|
|
|
-import com.bytedance.msdk.api.v2.ad.reward.GMRewardedAdListener
|
|
|
-import com.bytedance.msdk.api.v2.ad.splash.GMSplashAd
|
|
|
-import com.bytedance.msdk.api.v2.ad.splash.GMSplashAdListener
|
|
|
-import com.composition.android.ad.gromore.load.request.*
|
|
|
+import com.bytedance.sdk.openadsdk.TTAdConstant
|
|
|
+import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd
|
|
|
+import com.bytedance.sdk.openadsdk.TTNativeAd
|
|
|
+import com.bytedance.sdk.openadsdk.TTNativeExpressAd
|
|
|
+import com.bytedance.sdk.openadsdk.TTRewardVideoAd
|
|
|
+import com.bytedance.sdk.openadsdk.TTSplashAd
|
|
|
+import com.composition.android.ad.gromore.load.request.GMAppOpenRequestImpl
|
|
|
+import com.composition.android.ad.gromore.load.request.GMBannerRequestImpl
|
|
|
+import com.composition.android.ad.gromore.load.request.GMInterstitialRequestImpl
|
|
|
+import com.composition.android.ad.gromore.load.request.GMNativeRequestImpl
|
|
|
+import com.composition.android.ad.gromore.load.request.GMNativeTemplateRequestImpl
|
|
|
+import com.composition.android.ad.gromore.load.request.GMRewardRequestImpl
|
|
|
+import com.composition.android.ad.gromore.load.view.CSJNativeAdView
|
|
|
import com.composition.android.ad.gromore.load.view.GMBannerView
|
|
|
import com.composition.android.ad.gromore.load.view.GMNativeTemplateAdView
|
|
|
import com.composition.android.lib.ad.AdManager
|
|
|
-import com.composition.android.lib.ad.basic.*
|
|
|
+import com.composition.android.lib.ad.basic.AdResult
|
|
|
+import com.composition.android.lib.ad.basic.AdType
|
|
|
+import com.composition.android.lib.ad.basic.Advertisers
|
|
|
+import com.composition.android.lib.ad.basic.BannerAdViewHolder
|
|
|
+import com.composition.android.lib.ad.basic.BasicAdView
|
|
|
+import com.composition.android.lib.ad.basic.NativeAdViewHolder
|
|
|
import com.composition.android.lib.ad.bean.AdUnitBean
|
|
|
import com.composition.android.lib.ad.interfaces.AdListener
|
|
|
import com.composition.android.lib.ad.interfaces.AdLoader
|
|
|
-import com.composition.android.lib.ad.util.adLog
|
|
|
import com.composition.android.lib.ad.util.adLogE
|
|
|
import com.composition.android.lib.ad.util.adLogWithFrame
|
|
|
+import com.composition.android.lib.ad.util.parentRemove
|
|
|
|
|
|
/**
|
|
|
* @classname:
|
|
@@ -46,6 +52,7 @@ class GroMoreAdLoader : AdLoader {
|
|
|
override suspend fun load(context: Context, adUnitBean: AdUnitBean): AdResult {
|
|
|
val adRequest = when (adUnitBean.getAdType()) {
|
|
|
AdType.BANNER -> GMBannerRequestImpl()
|
|
|
+ AdType.NATIVE -> GMNativeRequestImpl()
|
|
|
AdType.NATIVE_TEMPLATE -> GMNativeTemplateRequestImpl()
|
|
|
AdType.INTERSTITIAL, AdType.REWARDED_INTERSTITIAL -> GMInterstitialRequestImpl()
|
|
|
AdType.REWARDED_VIDEO -> GMRewardRequestImpl()
|
|
@@ -71,190 +78,182 @@ class GroMoreAdLoader : AdLoader {
|
|
|
}
|
|
|
|
|
|
override fun getNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder): View? {
|
|
|
- return if (adResult.adObject != null){
|
|
|
- when(adResult.adBean.getAdType()){
|
|
|
- AdType.NATIVE_TEMPLATE ->{
|
|
|
+ return if (adResult.adObject != null) {
|
|
|
+ AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
+ when (adResult.adBean.getAdType()) {
|
|
|
+ AdType.NATIVE -> {
|
|
|
+ CSJNativeAdView(context).apply {
|
|
|
+ setViewHolder(viewHolder)
|
|
|
+ render(adResult)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ AdType.NATIVE_TEMPLATE -> {
|
|
|
GMNativeTemplateAdView(context).apply {
|
|
|
setViewHolder(viewHolder)
|
|
|
render(adResult)
|
|
|
- AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
}
|
|
|
}
|
|
|
- else->null
|
|
|
+
|
|
|
+ else -> {
|
|
|
+ null
|
|
|
+ }
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
null
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ override fun populateNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder, advertisersContainerView: ViewGroup) {
|
|
|
+ AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
+ when (adResult.adBean.getAdType()) {
|
|
|
+ AdType.NATIVE -> {
|
|
|
+ CSJNativeAdView.populateNativeAdView(context = context, adResult, viewHolder, advertisersContainerView)
|
|
|
+ }
|
|
|
|
|
|
+ AdType.NATIVE_TEMPLATE -> {
|
|
|
+ val ttNativeExpressAd = adResult.adObject as TTNativeExpressAd
|
|
|
+ advertisersContainerView.removeAllViews()
|
|
|
+ val expressAdView = ttNativeExpressAd.expressAdView
|
|
|
+ expressAdView.parentRemove()
|
|
|
+ advertisersContainerView.addView(expressAdView)
|
|
|
+ GMNativeTemplateAdView.populateNativeTemplateAdView(context, adResult, viewHolder)
|
|
|
+ }
|
|
|
|
|
|
- override fun populateNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder, advertisersContainerView: ViewGroup) {
|
|
|
- if (advertisersContainerView is TTNativeAdView) {
|
|
|
- val gmNativeAd = adResult?.adObject as? GMNativeAd
|
|
|
- advertisersContainerView.removeAllViews()
|
|
|
- advertisersContainerView.addView(gmNativeAd?.expressView)
|
|
|
- GMNativeTemplateAdView.populateNativeAdView(context, adResult, viewHolder, advertisersContainerView)
|
|
|
- } else {
|
|
|
- adLogE(AdManager.TAG, "GroMore广告-原生模板-填充失败, adRootView错误,当前类型为${advertisersContainerView.javaClass.simpleName},需要为${TTNativeAdView::class.java.simpleName}")
|
|
|
+ else -> {
|
|
|
+ adLogE(tag = AdManager.TAG, msg = "GroMore-填充原生,adType类型错误,不支持")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun showInterstitialAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
|
|
|
- if (adResult.adObject is GMInterstitialFullAd) {
|
|
|
- val mInterstitialFullAd = adResult.adObject as GMInterstitialFullAd
|
|
|
- mInterstitialFullAd.setAdInterstitialFullListener(object : GMInterstitialFullAdListener {
|
|
|
- override fun onInterstitialFullShow() {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-展示")
|
|
|
+ if (adResult.adObject is TTFullScreenVideoAd) {
|
|
|
+ val ttFullScreenVideoAd = adResult.adObject as TTFullScreenVideoAd
|
|
|
+ ttFullScreenVideoAd.setFullScreenVideoAdInteractionListener(object : TTFullScreenVideoAd.FullScreenVideoAdInteractionListener {
|
|
|
+ override fun onAdShow() {
|
|
|
+ adLogWithFrame(msg = "GroMore-插屏-展示")
|
|
|
adListener.onAdShow(adResult.adBean)
|
|
|
AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
}
|
|
|
|
|
|
- override fun onInterstitialFullShowFail(p0: AdError) {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-展示失败")
|
|
|
- adListener.onAdShowFail("GorMore广告-插屏-展示失败\n${p0.message}")
|
|
|
- }
|
|
|
-
|
|
|
- override fun onInterstitialFullClick() {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-点击")
|
|
|
+ override fun onAdVideoBarClick() {
|
|
|
+ adLogWithFrame(msg = "GroMore-插屏-点击")
|
|
|
adListener.onAdClick()
|
|
|
}
|
|
|
|
|
|
- override fun onInterstitialFullClosed() {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-关闭")
|
|
|
+ override fun onAdClose() {
|
|
|
+ adLogWithFrame(msg = "GroMore-插屏-关闭")
|
|
|
adListener.onAdClose()
|
|
|
+ destroyAd(adResult)
|
|
|
}
|
|
|
|
|
|
override fun onVideoComplete() {
|
|
|
- }
|
|
|
|
|
|
- override fun onVideoError() {
|
|
|
}
|
|
|
|
|
|
override fun onSkippedVideo() {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-跳过")
|
|
|
+ adLogWithFrame(msg = "GroMore-插屏-视频跳过")
|
|
|
adListener.onAdSkip()
|
|
|
}
|
|
|
-
|
|
|
- override fun onAdOpened() {
|
|
|
- }
|
|
|
-
|
|
|
- override fun onAdLeftApplication() {
|
|
|
- }
|
|
|
-
|
|
|
- override fun onRewardVerify(p0: RewardItem) {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-获取奖励")
|
|
|
- adListener.onAdRewarded()
|
|
|
- }
|
|
|
-
|
|
|
})
|
|
|
- mInterstitialFullAd.showAd(activity)
|
|
|
-
|
|
|
+ ttFullScreenVideoAd.showFullScreenVideoAd(activity, TTAdConstant.RitScenes.CUSTOMIZE_SCENES, null)
|
|
|
} else {
|
|
|
- adLogWithFrame(msg = "GorMore广告-插屏-展示失败:类型错误,adObject类型错误或为空:${adResult.adObject?.javaClass?.simpleName}")
|
|
|
- adListener.onAdShowFail("GorMore广告-插屏-加载失败:类型错误,adObject类型错误或为空:${adResult.adObject?.javaClass?.simpleName}")
|
|
|
+ adLogWithFrame(
|
|
|
+ msg = "GroMore-插屏-错误-类型错误,当前为:${adResult.adObject?.javaClass?.simpleName}, 应该为:TTNativeExpressAd"
|
|
|
+ )
|
|
|
+ adListener.onAdShowFail("类型错误,当前为:${adResult.adObject?.javaClass?.simpleName}, 应该为:TTNativeExpressAd")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun showRewardedAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
|
|
|
- if (adResult.adObject is GMRewardAd) {
|
|
|
- val gmRewardAd = adResult.adObject as GMRewardAd
|
|
|
- gmRewardAd.setRewardAdListener(object : GMRewardedAdListener {
|
|
|
- override fun onRewardedAdShow() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-激励视频-展示")
|
|
|
+ if (adResult.adObject is TTRewardVideoAd) {
|
|
|
+ val ttRewardVideoAd = adResult.adObject as TTRewardVideoAd
|
|
|
+ ttRewardVideoAd.setRewardAdInteractionListener(object : TTRewardVideoAd.RewardAdInteractionListener {
|
|
|
+ override fun onAdShow() {
|
|
|
+ adLogWithFrame(msg = "GroMore-激励视频-展示")
|
|
|
adListener.onAdShow(adResult.adBean)
|
|
|
AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
}
|
|
|
|
|
|
- override fun onRewardedAdShowFail(p0: AdError) {
|
|
|
- adLogWithFrame(msg = "GroMore广告-激励视频-展示失败\n${p0.message}")
|
|
|
- adListener.onAdShowFail("GroMore广告-激励视频-展示失败\n${p0.message}")
|
|
|
- }
|
|
|
-
|
|
|
- override fun onRewardClick() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-激励视频-点击")
|
|
|
+ override fun onAdVideoBarClick() {
|
|
|
+ adLogWithFrame(msg = "GroMore-激励视频-点击")
|
|
|
adListener.onAdClick()
|
|
|
}
|
|
|
|
|
|
- override fun onRewardedAdClosed() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-激励视频-关闭")
|
|
|
+ override fun onAdClose() {
|
|
|
+ adLogWithFrame(msg = "GroMore-激励视频-关闭")
|
|
|
adListener.onAdClose()
|
|
|
+ destroyAd(adResult)
|
|
|
}
|
|
|
|
|
|
override fun onVideoComplete() {
|
|
|
+
|
|
|
}
|
|
|
|
|
|
override fun onVideoError() {
|
|
|
+ adLogWithFrame(msg = "GroMore-激励视频-视频异常")
|
|
|
}
|
|
|
|
|
|
- override fun onRewardVerify(p0: RewardItem) {
|
|
|
- adLogWithFrame(msg = "GroMore广告-激励视频-获取奖励")
|
|
|
+ override fun onRewardVerify(p0: Boolean, p1: Int, p2: String?, p3: Int, p4: String?) {
|
|
|
+ adLogWithFrame(msg = "GroMore-激励视频-获取奖励")
|
|
|
adListener.onAdRewarded()
|
|
|
}
|
|
|
|
|
|
+ override fun onRewardArrived(p0: Boolean, p1: Int, p2: Bundle?) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
override fun onSkippedVideo() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-激励视频-跳过")
|
|
|
+ adLogWithFrame(msg = "GroMore-激励视频-视频跳过")
|
|
|
adListener.onAdSkip()
|
|
|
}
|
|
|
})
|
|
|
-
|
|
|
- if (gmRewardAd.isReady) {
|
|
|
- gmRewardAd.showRewardAd(activity)
|
|
|
- } else {
|
|
|
- adListener.onAdShowFail("GroMore广告-激励视频-实例还未准备完成,显示失败")
|
|
|
- }
|
|
|
+ ttRewardVideoAd.showRewardVideoAd(activity)
|
|
|
} else {
|
|
|
- adLogWithFrame(msg = "GorMore广告-激励视频-展示失败:类型错误,adObject类型错误或为空:${adResult.adObject?.javaClass?.simpleName}")
|
|
|
- adListener.onAdShowFail("GorMore广告-激励视频-加载失败:类型错误,adObject类型错误或为空:${adResult.adObject?.javaClass?.simpleName}")
|
|
|
+ adLogWithFrame(
|
|
|
+ msg = "穿山甲广告-激励视频-异常-类型错误,当前类型为:${adResult.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd"
|
|
|
+ )
|
|
|
+ adListener.onAdShowFail("类型错误,当前类型为:${adResult.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
override fun showRewardedInterstitialAd(activity: Activity, adResult: AdResult.Success, adListener: AdListener) {
|
|
|
- adLogWithFrame(msg = "GorMore广告-激励插屏-展示失败:不支持激励插屏广告")
|
|
|
- adListener.onAdShowFail("GorMore广告-激励插屏-展示失败:不支持激励插屏广告")
|
|
|
+ adLogWithFrame(msg = "GroMore-激励插屏-不支持的广告类型")
|
|
|
+ adListener.onAdShowFail("GroMore广告不支持激励插屏广告,请使用激励视频广告")
|
|
|
}
|
|
|
|
|
|
override fun showSplashAd(activity: Activity, splashViewGroup: ViewGroup?, adResult: AdResult.Success, adListener: AdListener) {
|
|
|
- if (adResult.adObject is GMSplashAd) {
|
|
|
- val gmAppOpenAd = adResult.adObject as GMSplashAd
|
|
|
- if (gmAppOpenAd.isReady) {
|
|
|
- gmAppOpenAd.setAdSplashListener(object : GMSplashAdListener {
|
|
|
- override fun onAdClicked() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-开屏-点击")
|
|
|
- adListener.onAdClick()
|
|
|
- }
|
|
|
+ if (adResult.adObject is TTSplashAd) {
|
|
|
+ val ttSplashAd = adResult.adObject as TTSplashAd
|
|
|
+ ttSplashAd.setSplashInteractionListener(object : TTSplashAd.AdInteractionListener {
|
|
|
+ override fun onAdClicked(p0: View?, p1: Int) {
|
|
|
+ adLogWithFrame(msg = "GroMore-开屏-点击")
|
|
|
+ adListener.onAdClick()
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdShow() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-开屏-展示")
|
|
|
- adListener.onAdShow(adResult.adBean)
|
|
|
- AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
- }
|
|
|
+ override fun onAdShow(p0: View?, p1: Int) {
|
|
|
+ adLogWithFrame(msg = "GroMore-开屏-展示")
|
|
|
+ adListener.onAdShow(adResult.adBean)
|
|
|
+ AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdShowFail(p0: AdError) {
|
|
|
- adLogWithFrame(msg = "GroMore广告-开屏-展示失败\n${p0.message}")
|
|
|
- adListener.onAdShowFail("GroMore广告-开屏-展示失败\n${p0.message}")
|
|
|
- }
|
|
|
+ override fun onAdSkip() {
|
|
|
+ adLogWithFrame(msg = "GroMore-开屏-跳过")
|
|
|
+ adListener.onAdSkip()
|
|
|
+ destroyAd(adResult)
|
|
|
|
|
|
- override fun onAdSkip() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-开屏-跳过")
|
|
|
- adListener.onAdSkip()
|
|
|
- gmAppOpenAd.destroy()
|
|
|
- adResult.adObject = null
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdDismiss() {
|
|
|
- adLogWithFrame(msg = "GroMore广告-开屏-关闭")
|
|
|
- adListener.onAdClose()
|
|
|
- gmAppOpenAd.destroy()
|
|
|
- adResult.adObject = null
|
|
|
- }
|
|
|
- })
|
|
|
- gmAppOpenAd.showAd(splashViewGroup)
|
|
|
- }
|
|
|
+ override fun onAdTimeOver() {
|
|
|
+ adLogWithFrame(msg = "GroMore-开屏-超时")
|
|
|
+ adListener.onTimeOver()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ splashViewGroup?.removeAllViews()
|
|
|
+ splashViewGroup?.addView(ttSplashAd.splashView)
|
|
|
} else {
|
|
|
- adLogWithFrame(msg = "GorMore广告-开屏-展示失败:类型错误,adObject类型错误或为空:${adResult.adObject?.javaClass?.simpleName}")
|
|
|
- adListener.onAdShowFail("GorMore广告-激励视频-加载失败:类型错误,adObject类型错误或为空:${adResult.adObject?.javaClass?.simpleName}")
|
|
|
+ adLogWithFrame(msg = "GroMore-开屏-异常-类型错误,当前类型为:${adResult.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
|
+ adListener.onAdShowFail("类型错误,当前类型为:${adResult.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -273,15 +272,15 @@ class GroMoreAdLoader : AdLoader {
|
|
|
try {
|
|
|
if (adResult is AdResult.Success) {
|
|
|
when (val ad = adResult.adObject) {
|
|
|
- is GMBannerAd -> ad.destroy()
|
|
|
- is GMUnifiedNativeAd -> ad.destroy()
|
|
|
+ is TTNativeExpressAd -> ad.destroy()
|
|
|
+ is TTNativeAd -> ad.destroy()
|
|
|
else -> {}
|
|
|
}
|
|
|
adResult.adObject = null
|
|
|
}
|
|
|
adLogWithFrame(msg = "GroMore广告-销毁广告对象完成")
|
|
|
- }catch (e : Exception){
|
|
|
-
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
}
|
|
|
}
|
|
|
}
|