Commit 7096cfc1 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 2abf2287
package com.mints.goodmoney.ad.draw
import android.app.Activity
import android.view.View
import com.bytedance.sdk.openadsdk.AdSlot
import com.bytedance.sdk.openadsdk.TTAdNative
import com.bytedance.sdk.openadsdk.TTNativeExpressAd
import com.bytedance.sdk.openadsdk.TTRewardVideoAd
import com.mints.goodmoney.manager.TTNativeExpressManager
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.ToastUtil
import com.mints.goodmoney.utils.UIUtils
class CsjDrawAdManager private constructor(activity: Activity) {
......@@ -60,15 +64,66 @@ class CsjDrawAdManager private constructor(activity: Activity) {
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
}
override fun onNativeExpressAdLoad(p0: MutableList<TTNativeExpressAd>?) {
if (p0 == null || p0.isEmpty()) {
override fun onNativeExpressAdLoad(ads: MutableList<TTNativeExpressAd>?) {
if (ads == null || ads.isEmpty()) {
// ToastUtil.show(activity, "未请求到广告")
this@CsjDrawAdManager.csjDrawAdListener?.csjDrawAdFail()
LogUtil.d("未请求到广告")
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) {
interface CsjDrawAdListener {
fun csjDrawAdFail()
fun csjDrawAdSuccess(data: MutableList<TTNativeExpressAd>?)
fun csjDrawAdSuccess(data: TTNativeExpressAd)
}
fun onDestroy() {
......
......@@ -19,7 +19,6 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
private val TAG = PreLoadExpressManager::class.java.simpleName
// 是否是穿山甲信息流
@Volatile
private var currentIndex = 0
......@@ -99,7 +98,7 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
var randomWeight = r.nextInt(weight) + 1
LogUtil.d(TAG, "2、权重随机值EXPRESS:$randomWeight")
ToastUtil.show(MintsApplication.getContext(), "权重随机值EXPRESS:" + randomWeight);
// ToastUtil.show(MintsApplication.getContext(), "权重随机值EXPRESS:" + randomWeight);
for (weightBean in weightList) {
randomWeight -= weightBean.weight
if (randomWeight <= 0) {
......
......@@ -120,7 +120,8 @@ class DrawNativeVideoActivity : BaseActivity(),
mCsjDrawAdManager?.setCsjDrawAdListener(this)
mLayoutManager = ViewPagerLayoutManager(this, OrientationHelper.VERTICAL)
mDrawVideoAdapter = DrawVideoAdapter(this, drawDatas)
// mDrawVideoAdapter = DrawVideoAdapter(this, drawDatas)
mDrawVideoAdapter = DrawVideoAdapter(drawDatas)
recy_draw_native.setItemViewCacheSize(1)
recy_draw_native.layoutManager = mLayoutManager
recy_draw_native.adapter = mDrawVideoAdapter
......@@ -388,59 +389,11 @@ class DrawNativeVideoActivity : BaseActivity(),
}
override fun csjDrawAdFail() {
showToast("加载失败,请稍候再试")
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) {
// showToast("当前视频加载失败")
// finish()
}
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) {
}
override fun onRenderSuccess(p0: View?, p1: Float, p2: Float) {
override fun csjDrawAdSuccess(ad: TTNativeExpressAd) {
// 数据源每次刷新添加3个视频加1个广告 则需+1
var index = drawDatas.size / (AD_INSERT_INDEX + 1) + mAdPage * AD_INSERT_INDEX
if (index == 0) {
......@@ -454,11 +407,6 @@ class DrawNativeVideoActivity : BaseActivity(),
mAdPage++
}
})
ad.render()
}
}
override fun getXfPageMsgSuc(data: KylBean) {
for (data in data.data) {
......
......@@ -14,14 +14,16 @@ import com.mints.goodmoney.ui.activitys.DrawNativeVideoActivity
import com.mints.goodmoney.ui.adapter.listener.OnItemClickListener
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 mOnItemClickListener: OnItemClickListener? = null
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)
return ViewHolder(view)
}
......
......@@ -103,7 +103,7 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
if (count == 0) {
// LogUtil.d("ForegroundOrBackground", System.currentTimeMillis() - leaveTime + " onActivityStarted");
// 60秒后打开应用 显示开屏广告
if (System.currentTimeMillis() - leaveTime >= 3000) {
if (System.currentTimeMillis() - leaveTime >= 60000) {
if (isYlhSplash) {
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