Commit 8175cb30 authored by mengcuiguang2's avatar mengcuiguang2

代码优化

parent ace01f89
......@@ -70,19 +70,19 @@ object BannerManager {
if (it.size > 0) {
val ad: TTNativeExpressAd = it[0]
bannerAd = ad
if (bannerAd != null && bannerAd!!.mediationManager != null && bannerAd!!.mediationManager.showEcpm != null) {
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE3
vo["cpmFen"] = bannerAd!!.mediationManager.showEcpm.ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
bannerAd?.setExpressInteractionListener(object :
TTNativeExpressAd.ExpressAdInteractionListener {
override fun onAdClicked(view: View?, type: Int) {
}
override fun onAdShow(view: View?, type: Int) {
if (bannerAd != null && bannerAd!!.mediationManager != null && bannerAd!!.mediationManager.showEcpm != null
&& bannerAd!!.mediationManager.showEcpm.ecpm != null) {
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE3
vo["cpmFen"] = bannerAd!!.mediationManager.showEcpm.ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
}
override fun onRenderFail(view: View?, msg: String?, code: Int) {
......
......@@ -150,7 +150,7 @@ class DrawExpressManager {
private fun showAd(ttFeedAd: TTFeedAd?) {
ttFeedAd?.let {
if (it.mediationManager != null && it.mediationManager.showEcpm != null) {
if (it.mediationManager != null && it.mediationManager.showEcpm != null&& it.mediationManager.showEcpm.ecpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE4
......
......@@ -143,7 +143,7 @@ class HomeDrawExpressManager {
private fun showAd(ttFeedAd: TTFeedAd?) {
ttFeedAd?.let {
if (it.mediationManager != null && it.mediationManager.showEcpm != null) {
if (it.mediationManager != null && it.mediationManager.showEcpm != null&& it.mediationManager.showEcpm.ecpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE4
......
......@@ -55,13 +55,13 @@ class ExpressManager {
val isPreingOversped = TimeRender.isOverspedMin(adPreingTime, AdManager.AD_REQUEST_TIME_OUT)
LogUtil.d(
TAG,
"gromore信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
TAG,
"gromore信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if ((isLoadSuccess == 0 // 加载失败
|| adLoadTime > 0 && isOversped // 超过45分钟
|| adPreingTime > 0 && isPreingOversped && isLoadSuccess == 1) // 预加载超时
|| adLoadTime > 0 && isOversped // 超过45分钟
|| adPreingTime > 0 && isPreingOversped && isLoadSuccess == 1) // 预加载超时
) {
LogUtil.d(TAG, "gromore信息流--> 2、执行预加载去了=$isLoadSuccess")
adPreingTime = System.currentTimeMillis()
......@@ -82,16 +82,16 @@ class ExpressManager {
val adNativeLoader = TTAdSdk.getAdManager().createAdNative(activity)
val adslot = AdSlot.Builder()
.setCodeId(BuildConfig.GROMORE_EXPRESS_CODE)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.setImageAcceptedSize(UIUtils.getAdWidth(MintsApplication.getContext()).toInt(), 0)
.setAdCount(3)//请求广告数量为1到3条 (优先采用平台配置的数量)
.build()
.setCodeId(BuildConfig.GROMORE_EXPRESS_CODE)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.setImageAcceptedSize(UIUtils.getAdWidth(MintsApplication.getContext()).toInt(), 0)
.setAdCount(3)//请求广告数量为1到3条 (优先采用平台配置的数量)
.build()
adNativeLoader.loadFeedAd(adslot, object : TTAdNative.FeedAdListener {
override fun onError(p0: Int, p1: String?) {
......@@ -119,13 +119,6 @@ class ExpressManager {
private fun showAd() {
mTTFeedAd?.let {
if (it.mediationManager != null && it.mediationManager.showEcpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE1
vo["cpmFen"] = ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
if (it.mediationManager.isExpress) {
//--------------信息流模板广告渲染----------------
showExpressView(it)
......@@ -145,8 +138,8 @@ class ExpressManager {
}
view?.let {
it.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
frameLayout?.removeAllViews()
frameLayout?.addView(it)
......@@ -168,8 +161,8 @@ class ExpressManager {
if (isLoadSuccess == 2 && !isOversped) {
LogUtil.d(
TAG,
"gromore信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
TAG,
"gromore信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
)
isLoadSuccess = 0
callback?.loadSuccess(frameLayout)
......@@ -186,19 +179,19 @@ class ExpressManager {
override fun onRenderSuccess(p0: View?, p1: Float, p2: Float, p3: Boolean) {
Log.i(TAG, "onRenderSuccess")
it.setDislikeCallback(ForegroundOrBackground.getTopActivity(),
object : TTAdDislike.DislikeInteractionCallback {
override fun onShow() {
Log.i(TAG, "express dislike 点击show")
}
override fun onSelected(position: Int, value: String?, enforce: Boolean) {
Log.i(TAG, "express 点击 $value")
}
override fun onCancel() {
Log.i(TAG, "express dislike 点击了取消")
}
})
object : TTAdDislike.DislikeInteractionCallback {
override fun onShow() {
Log.i(TAG, "express dislike 点击show")
}
override fun onSelected(position: Int, value: String?, enforce: Boolean) {
Log.i(TAG, "express 点击 $value")
}
override fun onCancel() {
Log.i(TAG, "express dislike 点击了取消")
}
})
it.adView?.let { view ->
if (view.parent != null) {
(view.parent as ViewGroup).removeView(view)
......@@ -226,6 +219,14 @@ class ExpressManager {
override fun onAdShow() {
Log.i(TAG, "onAdShow")
Log.i(TAG, "ad mediaExtraInfo ${it.mediaExtraInfo}")
if (it.mediationManager != null && it.mediationManager.showEcpm != null && it.mediationManager.showEcpm.ecpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE1
vo["cpmFen"] = ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
}
})
......@@ -249,62 +250,62 @@ class ExpressManager {
private fun getSmallAdView(parent: ViewGroup?): View? {
val convertView =
LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_small_pic,
parent,
false
)
LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_small_pic,
parent,
false
)
val adViewHolder = SmallAdViewHolder()
adViewHolder.mTitle =
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mSmallImage =
convertView.findViewById<View>(R.id.iv_listitem_image) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_image) as ImageView
adViewHolder.mIcon =
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.app_info =
convertView.findViewById<LinearLayout>(R.id.app_info)
convertView.findViewById<LinearLayout>(R.id.app_info)
adViewHolder.app_name =
convertView.findViewById<TextView>(R.id.app_name)
convertView.findViewById<TextView>(R.id.app_name)
adViewHolder.author_name =
convertView.findViewById<TextView>(R.id.author_name)
convertView.findViewById<TextView>(R.id.author_name)
adViewHolder.package_size =
convertView.findViewById<TextView>(R.id.package_size)
convertView.findViewById<TextView>(R.id.package_size)
adViewHolder.permissions_url =
convertView.findViewById<TextView>(R.id.permissions_url)
convertView.findViewById<TextView>(R.id.permissions_url)
adViewHolder.permissions_content =
convertView.findViewById<TextView>(R.id.permissions_content)
convertView.findViewById<TextView>(R.id.permissions_content)
adViewHolder.privacy_agreement =
convertView.findViewById<TextView>(R.id.privacy_agreement)
convertView.findViewById<TextView>(R.id.privacy_agreement)
adViewHolder.version_name =
convertView.findViewById<TextView>(R.id.version_name)
convertView.findViewById<TextView>(R.id.version_name)
val viewBinder =
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_small_pic)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source).descriptionTextId(
R.id.tv_listitem_ad_desc
)
.mainImageId(R.id.iv_listitem_image)
.logoLayoutId(R.id.tt_ad_logo)
.callToActionId(R.id.btn_listitem_creative)
.iconImageId(R.id.iv_listitem_icon).build()
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_small_pic)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source).descriptionTextId(
R.id.tv_listitem_ad_desc
)
.mainImageId(R.id.iv_listitem_image)
.logoLayoutId(R.id.tt_ad_logo)
.callToActionId(R.id.btn_listitem_creative)
.iconImageId(R.id.iv_listitem_icon).build()
adViewHolder.viewBinder = viewBinder
bindData(convertView, adViewHolder)
if (mTTFeedAd?.imageList?.size != 0) {
mTTFeedAd?.let { ttfeedad ->
ttfeedad.imageList[0]?.imageUrl?.let {
Glide.with(ForegroundOrBackground.getTopActivity()).load(it)
.into(adViewHolder.mSmallImage!!)
.into(adViewHolder.mSmallImage!!)
}
}
}
......@@ -314,64 +315,64 @@ class ExpressManager {
private fun getLargeAdView(parent: ViewGroup?): View {
val adViewHolder = LargeAdViewHolder()
var convertView: View =
LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_large_pic,
parent,
false
)
LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_large_pic,
parent,
false
)
adViewHolder.mTitle =
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mLargeImage =
convertView.findViewById<View>(R.id.iv_listitem_image) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_image) as ImageView
adViewHolder.mIcon =
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo =
convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
adViewHolder.app_info =
convertView.findViewById<LinearLayout>(R.id.app_info)
convertView.findViewById<LinearLayout>(R.id.app_info)
adViewHolder.app_name =
convertView.findViewById<TextView>(R.id.app_name)
convertView.findViewById<TextView>(R.id.app_name)
adViewHolder.author_name =
convertView.findViewById<TextView>(R.id.author_name)
convertView.findViewById<TextView>(R.id.author_name)
adViewHolder.package_size =
convertView.findViewById<TextView>(R.id.package_size)
convertView.findViewById<TextView>(R.id.package_size)
adViewHolder.permissions_url =
convertView.findViewById<TextView>(R.id.permissions_url)
convertView.findViewById<TextView>(R.id.permissions_url)
adViewHolder.permissions_content =
convertView.findViewById<TextView>(R.id.permissions_content)
convertView.findViewById<TextView>(R.id.permissions_content)
adViewHolder.privacy_agreement =
convertView.findViewById<TextView>(R.id.privacy_agreement)
convertView.findViewById<TextView>(R.id.privacy_agreement)
adViewHolder.version_name =
convertView.findViewById<TextView>(R.id.version_name)
convertView.findViewById<TextView>(R.id.version_name)
val viewBinder =
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_large_pic)
.titleId(R.id.tv_listitem_ad_title)
.descriptionTextId(R.id.tv_listitem_ad_desc).sourceId(
R.id.tv_listitem_ad_source
)
.mainImageId(R.id.iv_listitem_image)
.callToActionId(R.id.btn_listitem_creative)
.logoLayoutId(R.id.tt_ad_logo)
.iconImageId(R.id.iv_listitem_icon).build()
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_large_pic)
.titleId(R.id.tv_listitem_ad_title)
.descriptionTextId(R.id.tv_listitem_ad_desc).sourceId(
R.id.tv_listitem_ad_source
)
.mainImageId(R.id.iv_listitem_image)
.callToActionId(R.id.btn_listitem_creative)
.logoLayoutId(R.id.tt_ad_logo)
.iconImageId(R.id.iv_listitem_icon).build()
adViewHolder.viewBinder = viewBinder
bindData(convertView, adViewHolder)
if (mTTFeedAd?.imageList?.size != 0) {
mTTFeedAd?.let { ttfeedad ->
ttfeedad.imageList[0]?.imageUrl?.let {
Glide.with(ForegroundOrBackground.getTopActivity()).load(it)
.into(adViewHolder.mLargeImage!!)
.into(adViewHolder.mLargeImage!!)
}
}
}
......@@ -381,64 +382,64 @@ class ExpressManager {
private fun getGroupAdView(parent: ViewGroup?): View? {
val adViewHolder = GroupAdViewHolder()
var convertView: View = LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_group_pic,
parent,
false
)
.inflate(
R.layout.mediation_listitem_ad_group_pic,
parent,
false
)
adViewHolder.mTitle =
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mGroupImage1 =
convertView.findViewById<View>(R.id.iv_listitem_image1) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_image1) as ImageView
adViewHolder.mGroupImage2 =
convertView.findViewById<View>(R.id.iv_listitem_image2) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_image2) as ImageView
adViewHolder.mGroupImage3 =
convertView.findViewById<View>(R.id.iv_listitem_image3) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_image3) as ImageView
adViewHolder.mIcon =
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo =
convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
adViewHolder.app_info =
convertView.findViewById<LinearLayout>(R.id.app_info)
convertView.findViewById<LinearLayout>(R.id.app_info)
adViewHolder.app_name =
convertView.findViewById<TextView>(R.id.app_name)
convertView.findViewById<TextView>(R.id.app_name)
adViewHolder.author_name =
convertView.findViewById<TextView>(R.id.author_name)
convertView.findViewById<TextView>(R.id.author_name)
adViewHolder.package_size =
convertView.findViewById<TextView>(R.id.package_size)
convertView.findViewById<TextView>(R.id.package_size)
adViewHolder.permissions_url =
convertView.findViewById<TextView>(R.id.permissions_url)
convertView.findViewById<TextView>(R.id.permissions_url)
adViewHolder.permissions_content =
convertView.findViewById<TextView>(R.id.permissions_content)
convertView.findViewById<TextView>(R.id.permissions_content)
adViewHolder.privacy_agreement =
convertView.findViewById<TextView>(R.id.privacy_agreement)
convertView.findViewById<TextView>(R.id.privacy_agreement)
adViewHolder.version_name =
convertView.findViewById<TextView>(R.id.version_name)
convertView.findViewById<TextView>(R.id.version_name)
val viewBinder =
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_group_pic)
.titleId(R.id.tv_listitem_ad_title)
.descriptionTextId(R.id.tv_listitem_ad_desc).sourceId(
R.id.tv_listitem_ad_source
)
.mainImageId(R.id.iv_listitem_image1)
.logoLayoutId(R.id.tt_ad_logo).callToActionId(
R.id.btn_listitem_creative
).iconImageId(R.id.iv_listitem_icon)
.groupImage1Id(R.id.iv_listitem_image1).groupImage2Id(
R.id.iv_listitem_image2
)
.groupImage3Id(R.id.iv_listitem_image3).build()
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_group_pic)
.titleId(R.id.tv_listitem_ad_title)
.descriptionTextId(R.id.tv_listitem_ad_desc).sourceId(
R.id.tv_listitem_ad_source
)
.mainImageId(R.id.iv_listitem_image1)
.logoLayoutId(R.id.tt_ad_logo).callToActionId(
R.id.btn_listitem_creative
).iconImageId(R.id.iv_listitem_icon)
.groupImage1Id(R.id.iv_listitem_image1).groupImage2Id(
R.id.iv_listitem_image2
)
.groupImage3Id(R.id.iv_listitem_image3).build()
adViewHolder.viewBinder = viewBinder
bindData(convertView, adViewHolder)
......@@ -448,15 +449,15 @@ class ExpressManager {
val image3: String? = mTTFeedAd?.imageList?.get(2)?.imageUrl
if (image1 != null) {
Glide.with(ForegroundOrBackground.getTopActivity()).load(image1)
.into(adViewHolder.mGroupImage1!!)
.into(adViewHolder.mGroupImage1!!)
}
if (image2 != null) {
Glide.with(ForegroundOrBackground.getTopActivity()).load(image2)
.into(adViewHolder.mGroupImage2!!)
.into(adViewHolder.mGroupImage2!!)
}
if (image3 != null) {
Glide.with(ForegroundOrBackground.getTopActivity()).load(image3)
.into(adViewHolder.mGroupImage3!!)
.into(adViewHolder.mGroupImage3!!)
}
}
return convertView
......@@ -467,55 +468,55 @@ class ExpressManager {
var convertView: View? = null
try {
convertView = LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_large_video,
parent,
false
)
.inflate(
R.layout.mediation_listitem_ad_large_video,
parent,
false
)
adViewHolder.mTitle =
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mDescription =
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.videoView =
convertView.findViewById<View>(R.id.iv_listitem_video) as FrameLayout
convertView.findViewById<View>(R.id.iv_listitem_video) as FrameLayout
adViewHolder.mIcon =
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
adViewHolder.mLogo =
convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
adViewHolder.app_info =
convertView.findViewById<LinearLayout>(R.id.app_info)
convertView.findViewById<LinearLayout>(R.id.app_info)
adViewHolder.app_name =
convertView.findViewById<TextView>(R.id.app_name)
convertView.findViewById<TextView>(R.id.app_name)
adViewHolder.author_name =
convertView.findViewById<TextView>(R.id.author_name)
convertView.findViewById<TextView>(R.id.author_name)
adViewHolder.package_size =
convertView.findViewById<TextView>(R.id.package_size)
convertView.findViewById<TextView>(R.id.package_size)
adViewHolder.permissions_url =
convertView.findViewById<TextView>(R.id.permissions_url)
convertView.findViewById<TextView>(R.id.permissions_url)
adViewHolder.permissions_content =
convertView.findViewById<TextView>(R.id.permissions_content)
convertView.findViewById<TextView>(R.id.permissions_content)
adViewHolder.privacy_agreement =
convertView.findViewById<TextView>(R.id.privacy_agreement)
convertView.findViewById<TextView>(R.id.privacy_agreement)
adViewHolder.version_name =
convertView.findViewById<TextView>(R.id.version_name)
convertView.findViewById<TextView>(R.id.version_name)
val viewBinder =
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_large_video)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source)
.descriptionTextId(R.id.tv_listitem_ad_desc)
.mediaViewIdId(
R.id.iv_listitem_video
)
.callToActionId(R.id.btn_listitem_creative)
.logoLayoutId(R.id.tt_ad_logo)
.iconImageId(R.id.iv_listitem_icon).build()
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_large_video)
.titleId(R.id.tv_listitem_ad_title)
.sourceId(R.id.tv_listitem_ad_source)
.descriptionTextId(R.id.tv_listitem_ad_desc)
.mediaViewIdId(
R.id.iv_listitem_video
)
.callToActionId(R.id.btn_listitem_creative)
.logoLayoutId(R.id.tt_ad_logo)
.iconImageId(R.id.iv_listitem_icon).build()
adViewHolder.viewBinder = viewBinder
// 如果自己有需求进行视频播放操作,则按如下步骤进行。注意:不是所有adn都支持,因此需要进行判空操作。
......@@ -565,36 +566,36 @@ class ExpressManager {
}
override fun onDownloadActive(
totalBytes: Long,
currBytes: Long,
fileName: String?,
appName: String?
totalBytes: Long,
currBytes: Long,
fileName: String?,
appName: String?
) {
Log.i(TAG, "onDownloadActive")
}
override fun onDownloadPaused(
totalBytes: Long,
currBytes: Long,
fileName: String?,
appName: String?
totalBytes: Long,
currBytes: Long,
fileName: String?,
appName: String?
) {
Log.i(TAG, "onDownloadPaused")
}
override fun onDownloadFailed(
totalBytes: Long,
currBytes: Long,
fileName: String?,
appName: String?
totalBytes: Long,
currBytes: Long,
fileName: String?,
appName: String?
) {
Log.i(TAG, "onDownloadFailed")
}
override fun onDownloadFinished(
totalBytes: Long,
fileName: String?,
appName: String?
totalBytes: Long,
fileName: String?,
appName: String?
) {
Log.i(TAG, "onDownloadFinished")
}
......@@ -625,9 +626,9 @@ class ExpressManager {
mVideoView?.setOnErrorListener { mp, what, extra ->
if (customVideoReporter != null) {
customVideoReporter?.reportVideoError(
mVideoView!!.currentPosition.toLong(),
what,
extra
mVideoView!!.currentPosition.toLong(),
what,
extra
)
}
false
......@@ -644,63 +645,63 @@ class ExpressManager {
private fun getVerticalAdView(parent: ViewGroup?): View? {
val adViewHolder = VerticalAdViewHolder()
var convertView = LayoutInflater.from(ForegroundOrBackground.getTopActivity())
.inflate(
R.layout.mediation_listitem_ad_vertical_pic,
parent,
false
)
.inflate(
R.layout.mediation_listitem_ad_vertical_pic,
parent,
false
)
adViewHolder.mTitle =
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_title) as TextView
adViewHolder.mSource =
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
convertView.findViewById<View>(R.id.tv_listitem_ad_source) as TextView
adViewHolder.mDescription =
convertView?.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
convertView?.findViewById<View>(R.id.tv_listitem_ad_desc) as TextView
adViewHolder.mVerticalImage =
convertView.findViewById<ImageView>(R.id.iv_listitem_image)
convertView.findViewById<ImageView>(R.id.iv_listitem_image)
adViewHolder.mIcon =
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_icon) as ImageView
adViewHolder.mDislike =
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
convertView.findViewById<View>(R.id.iv_listitem_dislike) as ImageView
adViewHolder.mCreativeButton =
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
convertView.findViewById<View>(R.id.btn_listitem_creative) as Button
// adViewHolder.mLogo =
// convertView.findViewById<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
adViewHolder.app_info =
convertView.findViewById<LinearLayout>(R.id.app_info)
convertView.findViewById<LinearLayout>(R.id.app_info)
adViewHolder.app_name =
convertView.findViewById<TextView>(R.id.app_name)
convertView.findViewById<TextView>(R.id.app_name)
adViewHolder.author_name =
convertView.findViewById<TextView>(R.id.author_name)
convertView.findViewById<TextView>(R.id.author_name)
adViewHolder.package_size =
convertView.findViewById<TextView>(R.id.package_size)
convertView.findViewById<TextView>(R.id.package_size)
adViewHolder.permissions_url =
convertView.findViewById<TextView>(R.id.permissions_url)
convertView.findViewById<TextView>(R.id.permissions_url)
adViewHolder.permissions_content =
convertView.findViewById<TextView>(R.id.permissions_content)
convertView.findViewById<TextView>(R.id.permissions_content)
adViewHolder.privacy_agreement =
convertView.findViewById<TextView>(R.id.privacy_agreement)
convertView.findViewById<TextView>(R.id.privacy_agreement)
adViewHolder.version_name =
convertView.findViewById<TextView>(R.id.version_name)
convertView.findViewById<TextView>(R.id.version_name)
val viewBinder =
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_vertical_pic)
.titleId(R.id.tv_listitem_ad_title)
.descriptionTextId(R.id.tv_listitem_ad_desc)
.mainImageId(R.id.iv_listitem_image)
.iconImageId(R.id.iv_listitem_icon)
.callToActionId(R.id.btn_listitem_creative)
.sourceId(R.id.tv_listitem_ad_source)
.logoLayoutId(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
.build()
MediationViewBinder.Builder(R.layout.mediation_listitem_ad_vertical_pic)
.titleId(R.id.tv_listitem_ad_title)
.descriptionTextId(R.id.tv_listitem_ad_desc)
.mainImageId(R.id.iv_listitem_image)
.iconImageId(R.id.iv_listitem_icon)
.callToActionId(R.id.btn_listitem_creative)
.sourceId(R.id.tv_listitem_ad_source)
.logoLayoutId(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
.build()
adViewHolder.viewBinder = viewBinder
bindData(convertView, adViewHolder)
if (mTTFeedAd?.imageList?.size != 0) {
mTTFeedAd?.let { ttfeedad ->
ttfeedad.imageList[0]?.imageUrl?.let {
Glide.with(ForegroundOrBackground.getTopActivity()).load(it)
.into(adViewHolder.mVerticalImage!!)
.into(adViewHolder.mVerticalImage!!)
}
}
}
......@@ -711,13 +712,13 @@ class ExpressManager {
mTTFeedAd?.let {
if (it.mediationManager?.hasDislike() == true) {
val ttAdDislike: TTAdDislike =
it.getDislikeDialog(ForegroundOrBackground.getTopActivity())
it.getDislikeDialog(ForegroundOrBackground.getTopActivity())
adViewHolder.mDislike?.visibility = View.VISIBLE
adViewHolder.mDislike?.setOnClickListener(View.OnClickListener {
//使用接口来展示
ttAdDislike.showDislikeDialog()
ttAdDislike.setDislikeInteractionCallback(object :
TTAdDislike.DislikeInteractionCallback {
TTAdDislike.DislikeInteractionCallback {
override fun onShow() {
Log.i(TAG, "dislike 点击show")
}
......@@ -768,28 +769,28 @@ class ExpressManager {
creativeViewList.add(adViewHolder.mCreativeButton)
//重要! 这个涉及到广告计费,必须正确调用。**** convertView必须是com.bytedance.msdk.api.format.TTNativeAdView ****
it.registerViewForInteraction(
ForegroundOrBackground.getTopActivity(),
convertView as ViewGroup,
clickViewList,
creativeViewList,
null,
object : TTNativeAd.AdInteractionListener {
override fun onAdClicked(view: View?, ad: TTNativeAd?) {
Log.i(TAG, "onAdClicked")
}
ForegroundOrBackground.getTopActivity(),
convertView as ViewGroup,
clickViewList,
creativeViewList,
null,
object : TTNativeAd.AdInteractionListener {
override fun onAdClicked(view: View?, ad: TTNativeAd?) {
Log.i(TAG, "onAdClicked")
}
override fun onAdCreativeClick(view: View?, ad: TTNativeAd?) {
Log.i(TAG, "onAdCreativeClick")
}
override fun onAdCreativeClick(view: View?, ad: TTNativeAd?) {
Log.i(TAG, "onAdCreativeClick")
}
override fun onAdShow(ad: TTNativeAd?) {
Log.i(TAG, "onAdShow")
ad?.let {
override fun onAdShow(ad: TTNativeAd?) {
Log.i(TAG, "onAdShow")
ad?.let {
// PrintUtil.printShowInfo(ad.mediationManager)
}
}
}
},
adViewHolder.viewBinder
},
adViewHolder.viewBinder
)
adViewHolder.mTitle?.text = it.title //title为广告的简单信息提示
......@@ -797,12 +798,12 @@ class ExpressManager {
adViewHolder.mDescription?.text = it.description //description为广告的较长的说明
adViewHolder.mSource?.text =
if (TextUtils.isEmpty(it.source)) "广告来源" else it.source
if (TextUtils.isEmpty(it.source)) "广告来源" else it.source
val icon: TTImage? = it.icon
if (icon != null) {
Glide.with(ForegroundOrBackground.getTopActivity()).load(icon.imageUrl)
.into(adViewHolder.mIcon!!)
.into(adViewHolder.mIcon!!)
}
val adCreativeButton = adViewHolder.mCreativeButton
when (it.interactionType) {
......@@ -840,7 +841,7 @@ class ExpressManager {
adViewHolder.privacy_agreement?.text = "隐私url:" + appInfo.privacyUrl
adViewHolder.version_name?.text = "版本号:" + appInfo.appVersion
adViewHolder.permissions_content!!.text =
"权限内容:" + getPermissionsContent(appInfo.permissionsMap)
"权限内容:" + getPermissionsContent(appInfo.permissionsMap)
}
}
......@@ -852,7 +853,7 @@ class ExpressManager {
val keyList = permissionsMap.keys
for (s in keyList) {
stringBuffer.append(
"""$s : ${permissionsMap[s]} """
"""$s : ${permissionsMap[s]} """
)
}
return stringBuffer.toString()
......
......@@ -13,6 +13,7 @@ import com.duben.speedplayletu.utils.ForegroundOrBackground
import com.duben.speedplayletu.utils.LogUtil
import com.duben.speedplayletu.utils.UIUtils
import com.duben.speedplayletu.BuildConfig
private val TAG = MainExpressManager::class.java.simpleName
/**
......@@ -33,21 +34,21 @@ class MainExpressManager {
val adNativeLoader = TTAdSdk.getAdManager().createAdNative(activity)
val adslot = AdSlot.Builder()
.setCodeId(BuildConfig.GROMORE_EXPRESS_CODE)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.setCodeId(BuildConfig.GROMORE_EXPRESS_CODE)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
// .setImageAcceptedSize(
// UIUtils.getAdWidth2(MintsApplication.getContext()).toInt(),
//// UIUtils.dip2px(MintsApplication.getContext(), 192f)
// 0
// )
.setImageAcceptedSize(UIUtils.getScreenWidth(activity), 0)
.setAdCount(2)//请求广告数量为1到3条 (优先采用平台配置的数量)
.build()
.setImageAcceptedSize(UIUtils.getScreenWidth(activity), 0)
.setAdCount(2)//请求广告数量为1到3条 (优先采用平台配置的数量)
.build()
adNativeLoader.loadFeedAd(adslot, object : TTAdNative.FeedAdListener {
override fun onError(p0: Int, p1: String?) {
......@@ -56,8 +57,8 @@ class MainExpressManager {
override fun onFeedAdLoad(ads: MutableList<TTFeedAd>?) {
LogUtil.d(
TAG,
"gromore首页信息流--> 3、Gromore onAdLoaded"
TAG,
"gromore首页信息流--> 3、Gromore onAdLoaded"
)
ads?.let {
if (it.isEmpty()) {
......@@ -75,17 +76,11 @@ class MainExpressManager {
}
private fun showAd(
ttNativeAd: TTFeedAd?,
expressAdCallback: ExpressAdCallback
ttNativeAd: TTFeedAd?,
expressAdCallback: ExpressAdCallback
) {
ttNativeAd?.let {
if (it.mediationManager != null && it.mediationManager.showEcpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE1
vo["cpmFen"] = ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
if (it.mediationManager.isExpress) {
//--------------信息流模板广告渲染----------------
showExpressView(it, expressAdCallback)
......@@ -120,19 +115,19 @@ class MainExpressManager {
override fun onRenderSuccess(p0: View?, p1: Float, p2: Float, p3: Boolean) {
Log.i(TAG, "onRenderSuccess")
it.setDislikeCallback(ForegroundOrBackground.getTopActivity(),
object : TTAdDislike.DislikeInteractionCallback {
override fun onShow() {
Log.i(TAG, "express dislike 点击show")
}
object : TTAdDislike.DislikeInteractionCallback {
override fun onShow() {
Log.i(TAG, "express dislike 点击show")
}
override fun onSelected(position: Int, value: String?, enforce: Boolean) {
Log.i(TAG, "express 点击 $value")
}
override fun onSelected(position: Int, value: String?, enforce: Boolean) {
Log.i(TAG, "express 点击 $value")
}
override fun onCancel() {
Log.i(TAG, "express dislike 点击了取消")
}
})
override fun onCancel() {
Log.i(TAG, "express dislike 点击了取消")
}
})
it.adView?.let { view ->
if (view.parent != null) {
(view.parent as ViewGroup).removeView(view)
......@@ -154,6 +149,13 @@ class MainExpressManager {
override fun onAdShow() {
Log.i(TAG, "onAdShow")
Log.i(TAG, "ad mediaExtraInfo ${it.mediaExtraInfo}")
if (it.mediationManager != null && it.mediationManager.showEcpm != null && it.mediationManager.showEcpm.ecpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE1
vo["cpmFen"] = ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
}
})
......
......@@ -118,13 +118,6 @@ class MyExpressManager {
private fun showAd() {
mTTFeedAd?.let {
if (it.mediationManager != null && it.mediationManager.showEcpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE1
vo["cpmFen"] = ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
if (it.mediationManager.isExpress) {
//--------------信息流模板广告渲染----------------
showExpressView(it)
......@@ -226,6 +219,13 @@ class MyExpressManager {
override fun onAdShow() {
Log.i(TAG, "onAdShow")
Log.i(TAG, "ad mediaExtraInfo ${it.mediaExtraInfo}")
if (it.mediationManager != null && it.mediationManager.showEcpm != null && it.mediationManager.showEcpm.ecpm != null) {
val ecpm = it.mediationManager.showEcpm.ecpm
val vo = HashMap<String, Any>()
vo["adType"] = Constant.GRO_MORE_ADTYPE1
vo["cpmFen"] = ecpm
TrackManager.getInstance().cmtEcpm(vo)
}
}
})
......
......@@ -163,7 +163,7 @@ object SplashManager {
LogUtil.d(TAG, "gromore 开屏广告--> 6、onAdShow ")
mTTSplashAd?.let {
if (it.mediationManager != null && it.mediationManager.showEcpm != null) {
if (it.mediationManager != null && it.mediationManager.showEcpm != null&& it.mediationManager.showEcpm.ecpm != null) {
val vo = HashMap<String, Any>()
vo["cpmFen"] = it.mediationManager.showEcpm.ecpm
vo["adType"] = Constant.GRO_MORE_ADTYPE0
......
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