Commit 7096cfc1 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 2abf2287
package com.mints.goodmoney.ad.draw package com.mints.goodmoney.ad.draw
import android.app.Activity import android.app.Activity
import android.view.View
import com.bytedance.sdk.openadsdk.AdSlot import com.bytedance.sdk.openadsdk.AdSlot
import com.bytedance.sdk.openadsdk.TTAdNative import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTNativeExpressAd import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.bytedance.sdk.openadsdk.TTRewardVideoAd import com.bytedance.sdk.openadsdk.TTRewardVideoAd
import com.mints.goodmoney.manager.TTNativeExpressManager import com.mints.goodmoney.manager.TTNativeExpressManager
import com.mints.goodmoney.manager.TtCsjAdManager import com.mints.goodmoney.manager.TtCsjAdManager
import com.mints.goodmoney.mvp.model.DrawVideoBean
import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity
import com.mints.goodmoney.utils.LogUtil import com.mints.goodmoney.utils.LogUtil
import com.mints.goodmoney.utils.ToastUtil
import com.mints.goodmoney.utils.UIUtils import com.mints.goodmoney.utils.UIUtils
class CsjDrawAdManager private constructor(activity: Activity) { class CsjDrawAdManager private constructor(activity: Activity) {
...@@ -60,15 +64,66 @@ class CsjDrawAdManager private constructor(activity: Activity) { ...@@ -60,15 +64,66 @@ class CsjDrawAdManager private constructor(activity: Activity) {
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail() this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
} }
override fun onNativeExpressAdLoad(p0: MutableList<TTNativeExpressAd>?) { override fun onNativeExpressAdLoad(ads: MutableList<TTNativeExpressAd>?) {
if (p0 == null || p0.isEmpty()) { if (ads == null || ads.isEmpty()) {
// ToastUtil.show(activity, "未请求到广告") // ToastUtil.show(activity, "未请求到广告")
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail() this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
LogUtil.d("未请求到广告") LogUtil.d("未请求到广告")
return return
} }
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdSuccess(p0) for (ad in ads) {
//点击监听器必须在getAdView之前调
ad.setVideoAdListener(object : TTNativeExpressAd.ExpressVideoAdListener {
override fun onVideoLoad() {
}
override fun onVideoError(p0: Int, p1: Int) {
}
override fun onVideoAdStartPlay() {
}
override fun onVideoAdPaused() {
}
override fun onVideoAdContinuePlay() {
}
override fun onProgressUpdate(p0: Long, p1: Long) {
}
override fun onVideoAdComplete() {
}
override fun onClickRetry() {
}
})
ad.setCanInterruptVideoPlay(true)
ad.setExpressInteractionListener(object : TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(p0: View?, p1: Int) {
}
override fun onAdShow(p0: View?, p1: Int) {
}
override fun onRenderFail(p0: View?, p1: String?, p2: Int) {
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
}
override fun onRenderSuccess(p0: View?, p1: Float, p2: Float) {
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdSuccess(ad)
}
})
ad.render()
}
} }
}) })
...@@ -80,7 +135,7 @@ class CsjDrawAdManager private constructor(activity: Activity) { ...@@ -80,7 +135,7 @@ class CsjDrawAdManager private constructor(activity: Activity) {
interface CsjDrawAdListener { interface CsjDrawAdListener {
fun csjDrawAdFail() fun csjDrawAdFail()
fun csjDrawAdSuccess(data: MutableList<TTNativeExpressAd>?) fun csjDrawAdSuccess(data: TTNativeExpressAd)
} }
fun onDestroy() { fun onDestroy() {
......
...@@ -19,7 +19,6 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener ...@@ -19,7 +19,6 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
private val TAG = PreLoadExpressManager::class.java.simpleName private val TAG = PreLoadExpressManager::class.java.simpleName
// 是否是穿山甲信息流
@Volatile @Volatile
private var currentIndex = 0 private var currentIndex = 0
...@@ -99,7 +98,7 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener ...@@ -99,7 +98,7 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
var randomWeight = r.nextInt(weight) + 1 var randomWeight = r.nextInt(weight) + 1
LogUtil.d(TAG, "2、权重随机值EXPRESS:$randomWeight") LogUtil.d(TAG, "2、权重随机值EXPRESS:$randomWeight")
ToastUtil.show(MintsApplication.getContext(), "权重随机值EXPRESS:" + randomWeight); // ToastUtil.show(MintsApplication.getContext(), "权重随机值EXPRESS:" + randomWeight);
for (weightBean in weightList) { for (weightBean in weightList) {
randomWeight -= weightBean.weight randomWeight -= weightBean.weight
if (randomWeight <= 0) { if (randomWeight <= 0) {
......
...@@ -120,7 +120,8 @@ class DrawNativeVideoActivity : BaseActivity(), ...@@ -120,7 +120,8 @@ class DrawNativeVideoActivity : BaseActivity(),
mCsjDrawAdManager?.setCsjDrawAdListener(this) mCsjDrawAdManager?.setCsjDrawAdListener(this)
mLayoutManager = ViewPagerLayoutManager(this, OrientationHelper.VERTICAL) mLayoutManager = ViewPagerLayoutManager(this, OrientationHelper.VERTICAL)
mDrawVideoAdapter = DrawVideoAdapter(this, drawDatas) // mDrawVideoAdapter = DrawVideoAdapter(this, drawDatas)
mDrawVideoAdapter = DrawVideoAdapter(drawDatas)
recy_draw_native.setItemViewCacheSize(1) recy_draw_native.setItemViewCacheSize(1)
recy_draw_native.layoutManager = mLayoutManager recy_draw_native.layoutManager = mLayoutManager
recy_draw_native.adapter = mDrawVideoAdapter recy_draw_native.adapter = mDrawVideoAdapter
...@@ -388,59 +389,11 @@ class DrawNativeVideoActivity : BaseActivity(), ...@@ -388,59 +389,11 @@ class DrawNativeVideoActivity : BaseActivity(),
} }
override fun csjDrawAdFail() { override fun csjDrawAdFail() {
showToast("加载失败,请稍候再试") // showToast("当前视频加载失败")
finish() // finish()
}
override fun csjDrawAdSuccess(ads: MutableList<TTNativeExpressAd>?) {
if (ads == null || ads.isEmpty()) {
ToastUtil.show(this, "请求广告为空")
return
}
for (ad in ads) {
//点击监听器必须在getAdView之前调
ad.setVideoAdListener(object : TTNativeExpressAd.ExpressVideoAdListener {
override fun onVideoLoad() {
}
override fun onVideoError(p0: Int, p1: Int) {
} }
override fun onVideoAdStartPlay() { override fun csjDrawAdSuccess(ad: TTNativeExpressAd) {
}
override fun onVideoAdPaused() {
}
override fun onVideoAdContinuePlay() {
}
override fun onProgressUpdate(p0: Long, p1: Long) {
}
override fun onVideoAdComplete() {
}
override fun onClickRetry() {
}
})
ad.setCanInterruptVideoPlay(true)
ad.setExpressInteractionListener(object : TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(p0: View?, p1: Int) {
}
override fun onAdShow(p0: View?, p1: Int) {
}
override fun onRenderFail(p0: View?, p1: String?, p2: Int) {
}
override fun onRenderSuccess(p0: View?, p1: Float, p2: Float) {
// 数据源每次刷新添加3个视频加1个广告 则需+1 // 数据源每次刷新添加3个视频加1个广告 则需+1
var index = drawDatas.size / (AD_INSERT_INDEX + 1) + mAdPage * AD_INSERT_INDEX var index = drawDatas.size / (AD_INSERT_INDEX + 1) + mAdPage * AD_INSERT_INDEX
if (index == 0) { if (index == 0) {
...@@ -454,11 +407,6 @@ class DrawNativeVideoActivity : BaseActivity(), ...@@ -454,11 +407,6 @@ class DrawNativeVideoActivity : BaseActivity(),
mAdPage++ mAdPage++
} }
})
ad.render()
}
}
override fun getXfPageMsgSuc(data: KylBean) { override fun getXfPageMsgSuc(data: KylBean) {
for (data in data.data) { for (data in data.data) {
......
...@@ -14,14 +14,16 @@ import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity ...@@ -14,14 +14,16 @@ import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity
import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener
import com.mints.library.utils.GlideUtils import com.mints.library.utils.GlideUtils
class DrawVideoAdapter(context: Context, datas: List<DrawVideoBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { //class DrawVideoAdapter(context: Context, datas: List<DrawVideoBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class DrawVideoAdapter(datas: List<DrawVideoBean>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var mContext: Context = context private var mContext:Context?=null
private var mDrawVideoData: List<DrawVideoBean> = datas private var mDrawVideoData: List<DrawVideoBean> = datas
private var mOnItemClickListener: OnItemClickListener? = null private var mOnItemClickListener: OnItemClickListener? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
mContext=parent.context
val view = LayoutInflater.from(mContext).inflate(R.layout.item_view_pager, parent, false) val view = LayoutInflater.from(mContext).inflate(R.layout.item_view_pager, parent, false)
return ViewHolder(view) return ViewHolder(view)
} }
......
...@@ -103,7 +103,7 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall ...@@ -103,7 +103,7 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
if (count == 0) { if (count == 0) {
// LogUtil.d("ForegroundOrBackground", System.currentTimeMillis() - leaveTime + " onActivityStarted"); // LogUtil.d("ForegroundOrBackground", System.currentTimeMillis() - leaveTime + " onActivityStarted");
// 60秒后打开应用 显示开屏广告 // 60秒后打开应用 显示开屏广告
if (System.currentTimeMillis() - leaveTime >= 3000) { if (System.currentTimeMillis() - leaveTime >= 60000) {
if (isYlhSplash) { if (isYlhSplash) {
isYlhSplash = false; isYlhSplash = false;
......
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