Commit ca56df1e authored by mengcuiguang's avatar mengcuiguang

代码优化

parent a5432f3c
...@@ -129,7 +129,7 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener ...@@ -129,7 +129,7 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
mAdFrameLayout = adFrameLayout mAdFrameLayout = adFrameLayout
} }
override fun onYlhAdLoadSuc(view: NativeExpressADView?) { override fun onYlhAdLoadSuc(view: View?) {
// if (currentIndex == 2) { // if (currentIndex == 2) {
// mAdFrameLayout?.addView(view) // mAdFrameLayout?.addView(view)
// } // }
...@@ -150,7 +150,7 @@ interface TTADLoadSuccessListener { ...@@ -150,7 +150,7 @@ interface TTADLoadSuccessListener {
} }
interface YLHADLoadSuccessListener { interface YLHADLoadSuccessListener {
fun onYlhAdLoadSuc(view: NativeExpressADView?) fun onYlhAdLoadSuc(view: View?)
} }
interface KSADLoadSuccessListener { interface KSADLoadSuccessListener {
......
package com.wenshu.youyou.ad.express package com.wenshu.youyou.ad.express
import com.wenshu.youyou.BuildConfig import com.qq.e.ads.nativ.ADSize
import com.qq.e.ads.nativ.express2.*
import com.qq.e.comm.util.AdError
import com.wenshu.youyou.WenshuApplication import com.wenshu.youyou.WenshuApplication
import com.wenshu.youyou.manager.YlhAdManager import com.wenshu.youyou.manager.YlhAdManager
import com.wenshu.youyou.utils.LogUtil import com.wenshu.youyou.utils.LogUtil
import com.qq.e.ads.nativ.ADSize
import com.qq.e.ads.nativ.NativeExpressAD
import com.qq.e.ads.nativ.NativeExpressADView
import com.qq.e.comm.util.AdError
/** /**
* 优量汇预加载信息流 * 优量汇预加载信息流
*/ */
object YlhPreLoadExpressManager { object YlhPreLoadExpressManager {
private var nativeExpressAD: NativeExpressAD? = null private var nativeExpressAD: NativeExpressAD2? = null
private var nativeExpressADView: NativeExpressADView? = null private var mNativeExpressADData2: NativeExpressADData2? = null
private var mADLoadSuccessListener: YLHADLoadSuccessListener? = null private var mADLoadSuccessListener: YLHADLoadSuccessListener? = null
...@@ -25,55 +24,90 @@ object YlhPreLoadExpressManager { ...@@ -25,55 +24,90 @@ object YlhPreLoadExpressManager {
fun loadYlhFrameLayout() { fun loadYlhFrameLayout() {
try { try {
nativeExpressAD = NativeExpressAD(WenshuApplication.getContext(), ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), YlhAdManager.YLH_AD_NATIVEEXPRESS_AWARD, object : NativeExpressAD.NativeExpressADListener { nativeExpressAD = NativeExpressAD2(WenshuApplication.getContext(), YlhAdManager.YLH_AD_NATIVEEXPRESS_AWARD, object : NativeExpressAD2.AdLoadListener {
override fun onNoAD(p0: AdError?) { override fun onLoadSuccess(adDataList: MutableList<NativeExpressADData2>) {
if (BuildConfig.DEBUG) { // 渲染广告
LogUtil.d("通用奖励 ylh:TTNativeExpressManager", "onError ${p0?.errorCode} ${p0?.errorMsg}") renderAd(adDataList)
}
override fun onNoAD(p0: AdError?) {
LogUtil.d("YlhPreLoadExpressManager", "code:${p0?.errorCode} msg:${p0?.errorMsg}")
} }
})
loadAd()
} catch (e: Exception) {
e.printStackTrace()
} }
override fun onADClicked(p0: NativeExpressADView?) {
} }
override fun onADCloseOverlay(p0: NativeExpressADView?) { private fun loadAd() {
} nativeExpressAD?.setAdSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT)
// 如果您在平台上新建平台模板2.0广告位时,选择了支持视频,那么可以进行个性化设置(可选)
val builder = VideoOption2.Builder()
override fun onADClosed(p0: NativeExpressADView?) { /**
* 如果广告位支持视频广告,强烈建议在调用loadData请求广告前设置setAutoPlayPolicy,有助于提高视频广告的eCPM值 <br/>
* 如果广告位仅支持图文广告,则无需调用
*/
/**
* 如果广告位支持视频广告,强烈建议在调用loadData请求广告前设置setAutoPlayPolicy,有助于提高视频广告的eCPM值 <br></br>
* 如果广告位仅支持图文广告,则无需调用
*/
builder.setAutoPlayPolicy(VideoOption2.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频
.setAutoPlayMuted(true) // 自动播放时为静音
.setDetailPageMuted(false) // 视频详情页播放时不静音
.setMaxVideoDuration(0) // 设置返回视频广告的最大视频时长(闭区间,可单独设置),单位:秒,默认为 0 代表无限制,合法输入为:5<=maxVideoDuration<=61. 此设置会影响广告填充,请谨慎设置
.setMinVideoDuration(0) // 设置返回视频广告的最小视频时长(闭区间,可单独设置),单位:秒,默认为 0 代表无限制, 此设置会影响广告填充,请谨慎设置
nativeExpressAD?.setVideoOption2(builder.build())
nativeExpressAD?.loadAd(1)
} }
override fun onADExposure(p0: NativeExpressADView?) { private fun renderAd(adDataList: List<NativeExpressADData2>) {
// 释放前一个展示的NativeExpressADView的资源
mNativeExpressADData2?.destroy()
if (adDataList.size > 0) {
mNativeExpressADData2 = adDataList[0]
mNativeExpressADData2?.getECPMLevel() + " Video duration: " + mNativeExpressADData2?.getVideoDuration()
mNativeExpressADData2?.setAdEventListener(object : AdEventListener {
override fun onClick() {
} }
override fun onADLeftApplication(p0: NativeExpressADView?) { override fun onExposed() {
} }
override fun onADLoaded(p0: MutableList<NativeExpressADView>?) { override fun onRenderSuccess() {
// 释放前一个展示的NativeExpressADView的资源 if (mNativeExpressADData2?.getAdView() != null) {
nativeExpressADView?.destroy() mADLoadSuccessListener?.onYlhAdLoadSuc(mNativeExpressADData2?.getAdView())
}
}
nativeExpressADView = p0?.get(0) override fun onRenderFail() {
}
// 广告可见才会产生曝光,否则将无法产生收益。 override fun onAdClosed() {
mADLoadSuccessListener?.onYlhAdLoadSuc(nativeExpressADView) }
})
mNativeExpressADData2?.setMediaListener(object : MediaEventListener {
override fun onVideoCache() {
}
nativeExpressADView?.render() override fun onVideoStart() {
} }
override fun onADOpenOverlay(p0: NativeExpressADView?) { override fun onVideoResume() {
} }
override fun onRenderFail(p0: NativeExpressADView?) { override fun onVideoPause() {
} }
override fun onRenderSuccess(p0: NativeExpressADView?) { override fun onVideoComplete() {
} }
override fun onVideoError() {
}
}) })
nativeExpressAD?.loadAD(1) mNativeExpressADData2?.render()
} catch (e: Exception) {
e.printStackTrace()
} }
} }
...@@ -82,7 +116,7 @@ object YlhPreLoadExpressManager { ...@@ -82,7 +116,7 @@ object YlhPreLoadExpressManager {
*/ */
fun onDestroy() { fun onDestroy() {
// 使用完了每一个NativeExpressADView之后都要释放掉资源 // 使用完了每一个NativeExpressADView之后都要释放掉资源
nativeExpressADView?.destroy() mNativeExpressADData2?.destroy()
} }
} }
\ No newline at end of file
...@@ -39,7 +39,7 @@ object YlhAdManager { ...@@ -39,7 +39,7 @@ object YlhAdManager {
/*信息流*/ /*信息流*/
var YLH_AD_NATIVEEXPRESS_JULEYUN = "" //聚乐云 var YLH_AD_NATIVEEXPRESS_JULEYUN = "" //聚乐云
var YLH_AD_NATIVEEXPRESS_AWARD = "5061071124059461" //奖励弹窗 var YLH_AD_NATIVEEXPRESS_AWARD = "4021677125089838" //奖励弹窗
/* 插屏 */ /* 插屏 */
var YLH_AD_INTERSTITIALAD_LIEBAO = "" //猎豹 var YLH_AD_INTERSTITIALAD_LIEBAO = "" //猎豹
......
...@@ -28,9 +28,8 @@ import retrofit2.Converter; ...@@ -28,9 +28,8 @@ import retrofit2.Converter;
import retrofit2.Retrofit; import retrofit2.Retrofit;
/** /**
* Description:gson 2.2 gson全局解析问题 * Description:gson全局解析
*/ */
public class GsonConverterFactory extends Converter.Factory { public class GsonConverterFactory extends Converter.Factory {
private final Gson gson; private final Gson gson;
......
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:text="我们依据最新的法律,向您说明好赚钱软件的隐私政策,特向您推送本提示。请您阅读并充分理解相关条款。" android:text="我们依据最新的法律,向您说明尤友软件的隐私政策,特向您推送本提示。请您阅读并充分理解相关条款。"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="14sp" /> android:textSize="14sp" />
......
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