|
@@ -25,54 +25,54 @@ class CSJAdLoader : AdLoader {
|
|
|
|
|
|
|
|
|
|
override suspend fun load(context: Context, adUnitBean: AdUnitBean): AdResult {
|
|
override suspend fun load(context: Context, adUnitBean: AdUnitBean): AdResult {
|
|
- if (adUnitBean.isAvailable().not()){
|
|
|
|
|
|
+ if (adUnitBean.isAvailable().not()) {
|
|
return AdResult.Fail(adUnitBean, msg = "AdUnitBean无效")
|
|
return AdResult.Fail(adUnitBean, msg = "AdUnitBean无效")
|
|
}
|
|
}
|
|
//获取到具体的广告格式加载类
|
|
//获取到具体的广告格式加载类
|
|
val adFormatRequestImpl =
|
|
val adFormatRequestImpl =
|
|
- when(adUnitBean.getAdType()){
|
|
|
|
- AdType.REWARDED_VIDEO, AdType.REWARDED_INTERSTITIAL-> CSJRewardRequestImpl()
|
|
|
|
- AdType.INTERSTITIAL-> CSJInterstitialRequestImpl()
|
|
|
|
- AdType.APP_OPEN -> CSJAppOpenRequestImpl()
|
|
|
|
- AdType.BANNER-> CSJBannerRequestImpl()
|
|
|
|
- AdType.NATIVE-> CSJNativeRequestImpl()
|
|
|
|
- else-> null
|
|
|
|
- }
|
|
|
|
|
|
+ when (adUnitBean.getAdType()) {
|
|
|
|
+ AdType.REWARDED_VIDEO -> CSJRewardRequestImpl()
|
|
|
|
+ AdType.INTERSTITIAL -> CSJInterstitialRequestImpl()
|
|
|
|
+ AdType.APP_OPEN -> CSJAppOpenRequestImpl()
|
|
|
|
+ AdType.BANNER -> CSJBannerRequestImpl()
|
|
|
|
+ AdType.NATIVE_TEMPLATE -> CSJNativeTemplateRequestImpl()
|
|
|
|
+ else -> null
|
|
|
|
+ }
|
|
return loadByStrategy(context, adUnitBean, adFormatRequestImpl)
|
|
return loadByStrategy(context, adUnitBean, adFormatRequestImpl)
|
|
}
|
|
}
|
|
|
|
|
|
override fun getBannerView(context: Context, adResult: AdResult.Success, viewHolder: BannerAdViewHolder): BasicAdView<*>? {
|
|
override fun getBannerView(context: Context, adResult: AdResult.Success, viewHolder: BannerAdViewHolder): BasicAdView<*>? {
|
|
- return if (adResult.adObject != null) {
|
|
|
|
- AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
|
- CSJBannerView(context, viewHolder).apply {
|
|
|
|
- render(adResult)
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- null
|
|
|
|
- }
|
|
|
|
|
|
+ return if (adResult.adObject != null) {
|
|
|
|
+ AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
|
|
+ CSJBannerView(context, viewHolder).apply {
|
|
|
|
+ render(adResult)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ null
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
override fun getNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder): View? {
|
|
override fun getNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder): View? {
|
|
- return if (adResult.adObject != null){
|
|
|
|
|
|
+ return if (adResult.adObject != null) {
|
|
AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
CSJNativeAdView(context).apply {
|
|
CSJNativeAdView(context).apply {
|
|
setViewHolder(viewHolder)
|
|
setViewHolder(viewHolder)
|
|
render(adResult)
|
|
render(adResult)
|
|
}
|
|
}
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
null
|
|
null
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override fun populateNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder, adRootView: View) {
|
|
override fun populateNativeAdView(context: Context, adResult: AdResult.Success, viewHolder: NativeAdViewHolder, adRootView: View) {
|
|
AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
AdManager.instance.globalListener?.invoke(adResult.adBean)
|
|
- CSJNativeAdView.populateNativeAdView(context,adResult, viewHolder, adRootView)
|
|
|
|
|
|
+ CSJNativeAdView.populateNativeAdView(context, adResult, viewHolder, adRootView)
|
|
}
|
|
}
|
|
|
|
|
|
override fun showInterstitialAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
override fun showInterstitialAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
- if (success.adObject is TTFullScreenVideoAd){
|
|
|
|
|
|
+ if (success.adObject is TTFullScreenVideoAd) {
|
|
val ttFullScreenVideoAd = success.adObject as TTFullScreenVideoAd
|
|
val ttFullScreenVideoAd = success.adObject as TTFullScreenVideoAd
|
|
- ttFullScreenVideoAd.setFullScreenVideoAdInteractionListener(object : TTFullScreenVideoAd.FullScreenVideoAdInteractionListener{
|
|
|
|
|
|
+ ttFullScreenVideoAd.setFullScreenVideoAdInteractionListener(object : TTFullScreenVideoAd.FullScreenVideoAdInteractionListener {
|
|
override fun onAdShow() {
|
|
override fun onAdShow() {
|
|
adListener.onAdShow(success.adBean)
|
|
adListener.onAdShow(success.adBean)
|
|
AdManager.instance.globalListener?.invoke(success.adBean)
|
|
AdManager.instance.globalListener?.invoke(success.adBean)
|
|
@@ -97,18 +97,18 @@ class CSJAdLoader : AdLoader {
|
|
|
|
|
|
})
|
|
})
|
|
ttFullScreenVideoAd.showFullScreenVideoAd(activity, TTAdConstant.RitScenes.CUSTOMIZE_SCENES, null)
|
|
ttFullScreenVideoAd.showFullScreenVideoAd(activity, TTAdConstant.RitScenes.CUSTOMIZE_SCENES, null)
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
adListener.onAdShowFail("adObject类型错误,当前为:${success.adObject?.javaClass?.simpleName}, 应该为:TTNativeExpressAd")
|
|
adListener.onAdShowFail("adObject类型错误,当前为:${success.adObject?.javaClass?.simpleName}, 应该为:TTNativeExpressAd")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override fun showRewardedAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
override fun showRewardedAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
|
|
|
|
- if (success.adObject is TTRewardVideoAd){
|
|
|
|
|
|
+ if (success.adObject is TTRewardVideoAd) {
|
|
val ttRewardVideoAd = success.adObject as TTRewardVideoAd
|
|
val ttRewardVideoAd = success.adObject as TTRewardVideoAd
|
|
|
|
|
|
|
|
|
|
- ttRewardVideoAd.setRewardAdInteractionListener(object : TTRewardVideoAd.RewardAdInteractionListener{
|
|
|
|
|
|
+ ttRewardVideoAd.setRewardAdInteractionListener(object : TTRewardVideoAd.RewardAdInteractionListener {
|
|
override fun onAdShow() {
|
|
override fun onAdShow() {
|
|
adListener.onAdShow(success.adBean)
|
|
adListener.onAdShow(success.adBean)
|
|
AdManager.instance.globalListener?.invoke(success.adBean)
|
|
AdManager.instance.globalListener?.invoke(success.adBean)
|
|
@@ -138,14 +138,14 @@ class CSJAdLoader : AdLoader {
|
|
}
|
|
}
|
|
|
|
|
|
override fun onSkippedVideo() {
|
|
override fun onSkippedVideo() {
|
|
- adListener.onAdSkip()
|
|
|
|
|
|
+ adListener.onAdSkip()
|
|
}
|
|
}
|
|
|
|
|
|
})
|
|
})
|
|
|
|
|
|
ttRewardVideoAd.showRewardVideoAd(activity)
|
|
ttRewardVideoAd.showRewardVideoAd(activity)
|
|
|
|
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
adListener.onAdShowFail("穿山甲激励广告展示失败,类型错误,当前类型为:${success.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
adListener.onAdShowFail("穿山甲激励广告展示失败,类型错误,当前类型为:${success.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
}
|
|
}
|
|
|
|
|
|
@@ -153,13 +153,13 @@ class CSJAdLoader : AdLoader {
|
|
}
|
|
}
|
|
|
|
|
|
override fun showRewardedInterstitialAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
override fun showRewardedInterstitialAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
- showRewardedAd(activity, success, adListener)
|
|
|
|
|
|
+ adListener.onAdShowFail("穿山甲广告不支持激励插屏广告,请使用激励视频广告")
|
|
}
|
|
}
|
|
|
|
|
|
override fun showSplashAd(activity: Activity, splashViewGroup: ViewGroup?, success: AdResult.Success, adListener: AdListener) {
|
|
override fun showSplashAd(activity: Activity, splashViewGroup: ViewGroup?, success: AdResult.Success, adListener: AdListener) {
|
|
- if (success.adObject is TTSplashAd){
|
|
|
|
|
|
+ if (success.adObject is TTSplashAd) {
|
|
val ttSplashAd = success.adObject as TTSplashAd
|
|
val ttSplashAd = success.adObject as TTSplashAd
|
|
- ttSplashAd.setSplashInteractionListener(object : TTSplashAd.AdInteractionListener{
|
|
|
|
|
|
+ ttSplashAd.setSplashInteractionListener(object : TTSplashAd.AdInteractionListener {
|
|
override fun onAdClicked(p0: View?, p1: Int) {
|
|
override fun onAdClicked(p0: View?, p1: Int) {
|
|
adListener.onAdClick()
|
|
adListener.onAdClick()
|
|
}
|
|
}
|
|
@@ -179,16 +179,16 @@ class CSJAdLoader : AdLoader {
|
|
})
|
|
})
|
|
splashViewGroup?.removeAllViews()
|
|
splashViewGroup?.removeAllViews()
|
|
splashViewGroup?.addView(ttSplashAd.splashView)
|
|
splashViewGroup?.addView(ttSplashAd.splashView)
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
adListener.onAdShowFail("穿山甲激励广告展示失败,类型错误,当前类型为:${success.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
adListener.onAdShowFail("穿山甲激励广告展示失败,类型错误,当前类型为:${success.adObject?.javaClass?.simpleName}, 应为:TTRewardVideoAd")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
override fun showFullScreenAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
override fun showFullScreenAd(activity: Activity, success: AdResult.Success, adListener: AdListener) {
|
|
- when(success.adBean.getAdType()){
|
|
|
|
- AdType.REWARDED_INTERSTITIAL,AdType.INTERSTITIAL-> showInterstitialAd(activity, success, adListener)
|
|
|
|
|
|
+ when (success.adBean.getAdType()) {
|
|
|
|
+ AdType.INTERSTITIAL -> showInterstitialAd(activity, success, adListener)
|
|
AdType.REWARDED_VIDEO -> showRewardedAd(activity, success, adListener)
|
|
AdType.REWARDED_VIDEO -> showRewardedAd(activity, success, adListener)
|
|
- else->{
|
|
|
|
|
|
+ else -> {
|
|
adListener.onAdShowFail("不支持的广告类型:${success.adBean.adType}")
|
|
adListener.onAdShowFail("不支持的广告类型:${success.adBean.adType}")
|
|
}
|
|
}
|
|
}
|
|
}
|