Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_goodmoney
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_goodmoney
Commits
6a8580b3
Commit
6a8580b3
authored
Jun 01, 2021
by
jyx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GroMore信息流代码优化
parent
badca490
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
489 additions
and
16 deletions
+489
-16
GroMoreCarrierExpressManager.kt
...ints/goodmoney/ad/express/GroMoreCarrierExpressManager.kt
+475
-9
GroMoreExpressManager.kt
...a/com/mints/goodmoney/ad/express/GroMoreExpressManager.kt
+5
-3
PreLoadExpressManager.kt
...a/com/mints/goodmoney/ad/express/PreLoadExpressManager.kt
+3
-3
TaskCpdFragment.kt
...n/java/com/mints/goodmoney/ui/fragment/TaskCpdFragment.kt
+1
-1
UIUtils.java
.../app/src/main/java/com/mints/goodmoney/utils/UIUtils.java
+5
-0
No files found.
GoodMoney/app/src/main/java/com/mints/goodmoney/ad/express/GroMoreCarrierExpressManager.kt
View file @
6a8580b3
...
@@ -2,11 +2,17 @@ package com.mints.goodmoney.ad.express
...
@@ -2,11 +2,17 @@ package com.mints.goodmoney.ad.express
import
android.os.Handler
import
android.os.Handler
import
android.os.HandlerThread
import
android.os.HandlerThread
import
android.text.TextUtils
import
android.view.Gravity
import
android.view.Gravity
import
android.widget.FrameLayout
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
com.bumptech.glide.Glide
import
com.bytedance.msdk.api.*
import
com.bytedance.msdk.api.*
import
com.bytedance.msdk.api.nativeAd.*
import
com.bytedance.msdk.api.nativeAd.*
import
com.mints.goodmoney.MintsApplication
import
com.mints.goodmoney.MintsApplication
import
com.mints.goodmoney.R
import
com.mints.goodmoney.common.Constant
import
com.mints.goodmoney.common.Constant
import
com.mints.goodmoney.manager.CsjGroMoreManager
import
com.mints.goodmoney.manager.CsjGroMoreManager
import
com.mints.goodmoney.manager.TrackManager
import
com.mints.goodmoney.manager.TrackManager
...
@@ -14,6 +20,7 @@ import com.mints.goodmoney.ui.widgets.seekbar.BubbleUtils
...
@@ -14,6 +20,7 @@ import com.mints.goodmoney.ui.widgets.seekbar.BubbleUtils
import
com.mints.goodmoney.utils.LogUtil
import
com.mints.goodmoney.utils.LogUtil
import
com.mints.goodmoney.utils.UIUtils
import
com.mints.goodmoney.utils.UIUtils
import
com.mints.goodmoney.utils.VideoOptionUtil
import
com.mints.goodmoney.utils.VideoOptionUtil
import
java.util.ArrayList
import
java.util.HashMap
import
java.util.HashMap
private
val
TAG
=
GroMoreCarrierExpressManager
::
class
.
java
.
simpleName
private
val
TAG
=
GroMoreCarrierExpressManager
::
class
.
java
.
simpleName
...
@@ -29,7 +36,7 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
...
@@ -29,7 +36,7 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
private
var
mAdStyle
=
0
private
var
mAdStyle
=
0
private
var
mExpressType
=
0
private
var
mExpressType
=
0
private
va
l
frameLayout
:
FrameLayout
?
=
null
private
va
r
frameLayout
:
FrameLayout
?
=
null
private
var
mHandlerThread
:
HandlerThread
?
=
null
private
var
mHandlerThread
:
HandlerThread
?
=
null
private
var
mWorkHandler
:
Handler
?
=
null
private
var
mWorkHandler
:
Handler
?
=
null
...
@@ -43,7 +50,7 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
...
@@ -43,7 +50,7 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
fun
loadADFrameLayout
()
{
fun
loadADFrameLayout
()
{
// 销毁及移除事件
// 销毁及移除事件
destroy
()
destroy
()
frameLayout
?.
removeAllViews
(
)
frameLayout
=
FrameLayout
(
MintsApplication
.
getContext
()
)
if
(
TTMediationAdSdk
.
configLoadSuccess
())
{
if
(
TTMediationAdSdk
.
configLoadSuccess
())
{
loadAd
()
loadAd
()
...
@@ -99,7 +106,7 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
...
@@ -99,7 +106,7 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
.
setTTVideoOption
(
videoOption
)
//视频声音相关的配置
.
setTTVideoOption
(
videoOption
)
//视频声音相关的配置
.
setAdmobNativeAdOptions
(
admobNativeAdOptions
)
.
setAdmobNativeAdOptions
(
admobNativeAdOptions
)
.
setAdStyleType
(
mAdStyle
)
//必传,表示请求的模板广告还是原生广告,AdSlot.TYPE_EXPRESS_AD:模板广告 ; AdSlot.TYPE_NATIVE_AD:原生广告
.
setAdStyleType
(
mAdStyle
)
//必传,表示请求的模板广告还是原生广告,AdSlot.TYPE_EXPRESS_AD:模板广告 ; AdSlot.TYPE_NATIVE_AD:原生广告
.
setImageAdSize
(
UIUtils
.
getScreenWidthDp
(
MintsApplication
.
getContext
()).
toInt
(),
32
0
)
// 必选参数 单位dp ,详情见上面备注解释
.
setImageAdSize
(
340
,
0
)
// 必选参数 单位dp ,详情见上面备注解释
.
setAdCount
(
1
)
//请求广告数量为1到3条
.
setAdCount
(
1
)
//请求广告数量为1到3条
.
setGdtNativeAdLogoParams
(
gdtNativeAdLogUtiloParams
)
// 设置gdt logo布局参数。
.
setGdtNativeAdLogoParams
(
gdtNativeAdLogUtiloParams
)
// 设置gdt logo布局参数。
.
build
()
.
build
()
...
@@ -127,15 +134,15 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
...
@@ -127,15 +134,15 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
}
}
if
(
ads
.
size
>
0
)
{
if
(
ads
.
size
>
0
)
{
frameLayout
?.
addView
(
ads
[
0
].
expressView
)
frameLayout
?.
addView
(
createAdView
(
ads
[
0
]))
val
ttNativeAd
=
ads
[
0
]
val
ttNativeAd
=
ads
[
0
]
val
vo
=
HashMap
<
String
,
Any
>()
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"adcode"
]
=
ttNativeAd
.
getAdNetworkRitId
()
vo
[
"adcode"
]
=
ttNativeAd
.
adNetworkRitId
vo
[
"ecpm"
]
=
ttNativeAd
.
getPreEcpm
()
vo
[
"ecpm"
]
=
ttNativeAd
.
preEcpm
vo
[
"adSource"
]
=
ttNativeAd
.
getAdNetworkPlatformId
()
vo
[
"adSource"
]
=
ttNativeAd
.
adNetworkPlatformId
vo
[
"adType"
]
=
Constant
.
GRO_MORE_ADTYPE1
vo
[
"adType"
]
=
Constant
.
GRO_MORE_ADTYPE1
TrackManager
.
getInstance
().
cmtGroMoreInfo
(
vo
)
TrackManager
.
getInstance
().
cmtGroMoreInfo
(
vo
)
// sAdFrameLayout.addView(createAdView(ads[0]))
}
}
}
}
...
@@ -154,8 +161,467 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
...
@@ -154,8 +161,467 @@ class GroMoreCarrierExpressManager : TTSettingConfigCallback {
mHandlerThread
=
null
mHandlerThread
=
null
mWorkHandler
?.
removeCallbacksAndMessages
(
null
)
mWorkHandler
?.
removeCallbacksAndMessages
(
null
)
mWorkHandler
=
null
mWorkHandler
=
null
TTMediationAdSdk
.
unregisterConfigCallback
(
this
)
}
private
fun
createAdView
(
ad
:
TTNativeAd
?):
View
?
{
if
(
ad
!=
null
&&
ad
.
isExpressAd
)
{
return
getExpressAdView
(
ad
)
}
return
when
{
ad
==
null
->
{
return
null
}
ad
.
adImageMode
==
TTAdConstant
.
IMAGE_MODE_SMALL_IMG
->
{
return
getSmallAdView
(
ad
)
}
ad
.
adImageMode
==
TTAdConstant
.
IMAGE_MODE_LARGE_IMG
->
{
return
getLargeAdView
(
ad
)
}
ad
.
adImageMode
==
TTAdConstant
.
IMAGE_MODE_GROUP_IMG
->
{
return
getGroupAdView
(
ad
)
}
ad
.
adImageMode
==
TTAdConstant
.
IMAGE_MODE_VIDEO
->
{
return
getVideoView
(
ad
)
}
ad
.
adImageMode
==
TTAdConstant
.
IMAGE_MODE_VERTICAL_IMG
->
{
return
getVerticalAdView
(
ad
)
}
ad
.
adImageMode
==
TTAdConstant
.
IMAGE_MODE_VIDEO_VERTICAL
->
{
return
getVideoView
(
ad
)
}
else
->
{
return
null
}
}
}
//渲染模板广告
private
fun
getExpressAdView
(
ad
:
TTNativeAd
):
View
?
{
val
adViewHolder
:
ExpressAdViewHolder
val
convertView
=
LayoutInflater
.
from
(
MintsApplication
.
getContext
()).
inflate
(
R
.
layout
.
listitem_ad_native_express
,
null
,
false
)
try
{
adViewHolder
=
ExpressAdViewHolder
()
adViewHolder
.
mAdContainerView
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_express
)
as
FrameLayout
convertView
.
tag
=
adViewHolder
//判断是否存在dislike按钮
// if (ad.hasDislike()) {
// ad.setDislikeCallback(MintsApplication.getContext() as Activity?, object : TTDislikeCallback {
// override fun onSelected(position: Int, value: String) {
// //用户选择不喜欢原因后,移除广告展示
// }
//
// override fun onCancel() {
// LogUtil.d(TAG, "dislike 点击了取消")
// }
//
// /**
// * 拒绝再次提交
// */
// override fun onRefuse() {}
// override fun onShow() {}
// })
// }
//设置点击展示回调监听
ad
.
setTTNativeAdListener
(
object
:
TTNativeExpressAdListener
{
override
fun
onAdClick
()
{
LogUtil
.
d
(
TAG
,
"onAdClick"
)
}
override
fun
onAdShow
()
{
LogUtil
.
d
(
TAG
,
"onAdShow"
)
}
override
fun
onRenderFail
(
view
:
View
,
msg
:
String
,
code
:
Int
)
{
LogUtil
.
d
(
TAG
,
"onRenderFail code=$code,msg=$msg"
)
}
// ** 注意点 ** 不要在广告加载成功回调里进行广告view展示,要在onRenderSucces进行广告view展示,否则会导致广告无法展示。
// 另外,不要直接使用参数view,而是通过ad.getExpressView()来获取广告view。
override
fun
onRenderSuccess
(
view
:
View
,
width
:
Float
,
height
:
Float
)
{
LogUtil
.
d
(
TAG
,
"onRenderSuccess"
)
//回调渲染成功后将模板布局添加的父View中
if
(
adViewHolder
.
mAdContainerView
!=
null
)
{
//获取视频播放view,该view SDK内部渲染,在媒体平台可配置视频是否自动播放等设置。
val
sWidth
:
Int
val
sHeight
:
Int
val
video
=
ad
.
expressView
// 使用该方式获取广告view,而不是直接使用onRenderSuccess的参数view。
if
(
width
==
TTAdSize
.
FULL_WIDTH
.
toFloat
()
&&
height
==
TTAdSize
.
AUTO_HEIGHT
.
toFloat
())
{
sWidth
=
FrameLayout
.
LayoutParams
.
MATCH_PARENT
sHeight
=
FrameLayout
.
LayoutParams
.
MATCH_PARENT
}
else
{
sWidth
=
UIUtils
.
getScreenWidth
(
MintsApplication
.
getContext
())
sHeight
=
(
sWidth
*
height
/
width
).
toInt
()
}
if
(
video
!=
null
)
{
if
(
video
.
parent
==
null
)
{
val
layoutParams
=
FrameLayout
.
LayoutParams
(
sWidth
,
sHeight
)
adViewHolder
.
mAdContainerView
!!
.
removeAllViews
()
adViewHolder
.
mAdContainerView
!!
.
addView
(
video
,
layoutParams
)
}
}
}
}
})
//视频广告设置播放状态回调(可选)
ad
.
setTTVideoListener
(
object
:
TTVideoListener
{
override
fun
onVideoStart
()
{
LogUtil
.
d
(
TAG
,
"onVideoStart"
)
}
override
fun
onVideoPause
()
{
LogUtil
.
d
(
TAG
,
"onVideoPause"
)
}
override
fun
onVideoResume
()
{
LogUtil
.
d
(
TAG
,
"onVideoResume"
)
}
override
fun
onVideoCompleted
()
{
LogUtil
.
d
(
TAG
,
"onVideoCompleted"
)
}
override
fun
onVideoError
(
adError
:
AdError
)
{
LogUtil
.
d
(
TAG
,
"onVideoError"
)
}
})
ad
.
render
()
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
convertView
}
/**
* @param ad
* @return
*/
private
fun
getVerticalAdView
(
ad
:
TTNativeAd
):
View
?
{
val
convertView
=
LayoutInflater
.
from
(
MintsApplication
.
getContext
()).
inflate
(
R
.
layout
.
listitem_ad_vertical_pic
,
null
,
false
)
val
adViewHolder
=
VerticalAdViewHolder
()
adViewHolder
.
mTitle
=
convertView
!!
.
findViewById
(
R
.
id
.
tv_listitem_ad_title
)
as
TextView
adViewHolder
.
mSource
=
convertView
.
findViewById
(
R
.
id
.
tv_listitem_ad_source
)
as
TextView
adViewHolder
.
mDescription
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_desc
)
as
TextView
adViewHolder
.
mVerticalImage
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_image
)
adViewHolder
.
mIcon
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_icon
)
as
ImageView
adViewHolder
.
mDislike
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_dislike
)
as
ImageView
adViewHolder
.
mCreativeButton
=
convertView
.
findViewById
<
View
>(
R
.
id
.
btn_listitem_creative
)
as
Button
adViewHolder
.
mLogo
=
convertView
.
findViewById
(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
val
viewBinder
:
TTViewBinder
=
TTViewBinder
.
Builder
(
R
.
layout
.
listitem_ad_vertical_pic
)
.
titleId
(
R
.
id
.
tv_listitem_ad_title
)
.
decriptionTextId
(
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
convertView
.
tag
=
adViewHolder
bindData
(
convertView
,
adViewHolder
,
ad
,
viewBinder
)
if
(
ad
.
imageUrl
!=
null
)
{
adViewHolder
.
mVerticalImage
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
ad
.
imageUrl
).
into
(
it
)
}
}
return
convertView
}
//渲染视频广告,以视频广告为例,以下说明
private
fun
getVideoView
(
ad
:
TTNativeAd
):
View
?
{
val
adViewHolder
:
VideoAdViewHolder
val
viewBinder
:
TTViewBinder
val
convertView
=
LayoutInflater
.
from
(
MintsApplication
.
getContext
()).
inflate
(
R
.
layout
.
listitem_ad_large_video
,
null
,
false
)
try
{
adViewHolder
=
VideoAdViewHolder
()
adViewHolder
.
mTitle
=
convertView
!!
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_title
)
as
TextView
adViewHolder
.
mDescription
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_desc
)
as
TextView
adViewHolder
.
mSource
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_source
)
as
TextView
adViewHolder
.
videoView
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_video
)
as
FrameLayout
adViewHolder
.
mIcon
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_icon
)
as
ImageView
adViewHolder
.
mDislike
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_dislike
)
as
ImageView
adViewHolder
.
mCreativeButton
=
convertView
.
findViewById
<
View
>(
R
.
id
.
btn_listitem_creative
)
as
Button
adViewHolder
.
mLogo
=
convertView
.
findViewById
(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
//TTViewBinder 是必须类,需要开发者在确定好View之后把Id设置给TTViewBinder类,并在注册事件时传递给SDK
viewBinder
=
TTViewBinder
.
Builder
(
R
.
layout
.
listitem_ad_large_video
)
.
titleId
(
R
.
id
.
tv_listitem_ad_title
)
.
sourceId
(
R
.
id
.
tv_listitem_ad_source
)
.
decriptionTextId
(
R
.
id
.
tv_listitem_ad_desc
)
.
mediaViewIdId
(
R
.
id
.
iv_listitem_video
)
.
callToActionId
(
R
.
id
.
btn_listitem_creative
)
.
logoLayoutId
(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
.
iconImageId
(
R
.
id
.
iv_listitem_icon
)
.
build
()
adViewHolder
.
viewBinder
=
viewBinder
convertView
.
tag
=
adViewHolder
//视频广告设置播放状态回调(可选)
ad
.
setTTVideoListener
(
object
:
TTVideoListener
{
override
fun
onVideoStart
()
{
LogUtil
.
d
(
TAG
,
"onVideoStart"
)
}
}
override
fun
onVideoPause
()
{
LogUtil
.
d
(
TAG
,
"onVideoPause"
)
}
override
fun
onVideoResume
()
{
LogUtil
.
d
(
TAG
,
"onVideoResume"
)
}
override
fun
onVideoCompleted
()
{
LogUtil
.
d
(
TAG
,
"onVideoCompleted"
)
}
override
fun
onVideoError
(
adError
:
AdError
)
{
LogUtil
.
d
(
TAG
,
"onVideoError"
)
}
})
//绑定广告数据、设置交互回调
bindData
(
convertView
,
adViewHolder
,
ad
,
viewBinder
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
convertView
}
private
fun
getLargeAdView
(
ad
:
TTNativeAd
):
View
?
{
val
convertView
=
LayoutInflater
.
from
(
MintsApplication
.
getContext
()).
inflate
(
R
.
layout
.
listitem_ad_large_pic
,
null
,
false
)
val
adViewHolder
=
LargeAdViewHolder
()
adViewHolder
.
mTitle
=
convertView
!!
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_title
)
as
TextView
adViewHolder
.
mDescription
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_desc
)
as
TextView
adViewHolder
.
mSource
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_source
)
as
TextView
adViewHolder
.
mLargeImage
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image
)
as
ImageView
adViewHolder
.
mIcon
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_icon
)
as
ImageView
adViewHolder
.
mDislike
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_dislike
)
as
ImageView
adViewHolder
.
mCreativeButton
=
convertView
.
findViewById
<
View
>(
R
.
id
.
btn_listitem_creative
)
as
Button
adViewHolder
.
mLogo
=
convertView
.
findViewById
(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
val
viewBinder
:
TTViewBinder
=
TTViewBinder
.
Builder
(
R
.
layout
.
listitem_ad_large_pic
)
.
titleId
(
R
.
id
.
tv_listitem_ad_title
)
.
decriptionTextId
(
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
)
//logoView 建议传入GroupView类型
.
iconImageId
(
R
.
id
.
iv_listitem_icon
)
.
build
()
adViewHolder
.
viewBinder
=
viewBinder
convertView
.
tag
=
adViewHolder
bindData
(
convertView
,
adViewHolder
,
ad
,
viewBinder
)
if
(
ad
.
imageUrl
!=
null
)
{
adViewHolder
.
mLargeImage
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
ad
.
imageUrl
).
into
(
it
)
}
}
return
convertView
}
private
fun
getGroupAdView
(
ad
:
TTNativeAd
):
View
?
{
val
convertView
=
LayoutInflater
.
from
(
MintsApplication
.
getContext
()).
inflate
(
R
.
layout
.
listitem_ad_group_pic
,
null
,
false
)
val
adViewHolder
=
GroupAdViewHolder
()
adViewHolder
.
mTitle
=
convertView
!!
.
findViewById
(
R
.
id
.
tv_listitem_ad_title
)
as
TextView
adViewHolder
.
mSource
=
convertView
.
findViewById
(
R
.
id
.
tv_listitem_ad_source
)
as
TextView
adViewHolder
.
mDescription
=
convertView
.
findViewById
(
R
.
id
.
tv_listitem_ad_desc
)
as
TextView
adViewHolder
.
mGroupImage1
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_image1
)
as
ImageView
adViewHolder
.
mGroupImage2
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_image2
)
as
ImageView
adViewHolder
.
mGroupImage3
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_image3
)
as
ImageView
adViewHolder
.
mIcon
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_icon
)
as
ImageView
adViewHolder
.
mDislike
=
convertView
.
findViewById
(
R
.
id
.
iv_listitem_dislike
)
as
ImageView
adViewHolder
.
mCreativeButton
=
convertView
.
findViewById
(
R
.
id
.
btn_listitem_creative
)
as
Button
adViewHolder
.
mLogo
=
convertView
.
findViewById
(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
val
viewBinder
:
TTViewBinder
=
TTViewBinder
.
Builder
(
R
.
layout
.
listitem_ad_group_pic
)
.
titleId
(
R
.
id
.
tv_listitem_ad_title
)
.
decriptionTextId
(
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
)
//logoView 建议传入GroupView类型
.
callToActionId
(
R
.
id
.
btn_listitem_creative
)
.
iconImageId
(
R
.
id
.
iv_listitem_icon
)
.
build
()
adViewHolder
.
viewBinder
=
viewBinder
convertView
.
tag
=
adViewHolder
bindData
(
convertView
,
adViewHolder
,
ad
,
viewBinder
)
if
(
ad
.
imageList
!=
null
&&
ad
.
imageList
.
size
>=
3
)
{
val
image1
=
ad
.
imageList
[
0
]
val
image2
=
ad
.
imageList
[
1
]
val
image3
=
ad
.
imageList
[
2
]
if
(
image1
!=
null
)
{
adViewHolder
.
mGroupImage1
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
image1
).
into
(
it
)
}
}
if
(
image2
!=
null
)
{
adViewHolder
.
mGroupImage2
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
image2
).
into
(
it
)
}
}
if
(
image3
!=
null
)
{
adViewHolder
.
mGroupImage3
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
image3
).
into
(
it
)
}
}
}
return
convertView
}
private
fun
getSmallAdView
(
ad
:
TTNativeAd
):
View
?
{
val
convertView
=
LayoutInflater
.
from
(
MintsApplication
.
getContext
()).
inflate
(
R
.
layout
.
listitem_ad_small_pic
,
null
,
false
)
val
adViewHolder
=
SmallAdViewHolder
()
adViewHolder
.
mTitle
=
convertView
!!
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_title
)
as
TextView
adViewHolder
.
mSource
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_source
)
as
TextView
adViewHolder
.
mDescription
=
convertView
.
findViewById
<
View
>(
R
.
id
.
tv_listitem_ad_desc
)
as
TextView
adViewHolder
.
mSmallImage
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image
)
as
ImageView
adViewHolder
.
mIcon
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_icon
)
as
ImageView
adViewHolder
.
mDislike
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_dislike
)
as
ImageView
adViewHolder
.
mCreativeButton
=
convertView
.
findViewById
<
View
>(
R
.
id
.
btn_listitem_creative
)
as
Button
val
viewBinder
:
TTViewBinder
=
TTViewBinder
.
Builder
(
R
.
layout
.
listitem_ad_small_pic
)
.
titleId
(
R
.
id
.
tv_listitem_ad_title
)
.
sourceId
(
R
.
id
.
tv_listitem_ad_source
)
.
decriptionTextId
(
R
.
id
.
tv_listitem_ad_desc
)
.
mainImageId
(
R
.
id
.
iv_listitem_image
)
.
logoLayoutId
(
R
.
id
.
tt_ad_logo
)
//logoView 建议为GroupView 类型
.
callToActionId
(
R
.
id
.
btn_listitem_creative
)
.
iconImageId
(
R
.
id
.
iv_listitem_icon
)
.
build
()
adViewHolder
.
viewBinder
=
viewBinder
convertView
.
tag
=
adViewHolder
bindData
(
convertView
,
adViewHolder
,
ad
,
viewBinder
)
if
(
ad
.
imageUrl
!=
null
)
{
adViewHolder
.
mSmallImage
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
ad
.
imageUrl
).
into
(
it
)
}
}
return
convertView
}
private
fun
bindData
(
convertView
:
View
,
adViewHolder
:
AdViewHolder
,
ad
:
TTNativeAd
,
viewBinder
:
TTViewBinder
)
{
//设置dislike弹窗,如果有
// if (ad.hasDislike()) {
// val ttAdDislike = ad.getDislikeDialog( MintsApplication.getContext() as Activity?)
// adViewHolder.mDislike.setVisibility(View.VISIBLE)
// adViewHolder.mDislike.setOnClickListener(View.OnClickListener {
// //使用接口来展示
// ttAdDislike.showDislikeDialog()
// ttAdDislike.setDislikeCallback(object : TTDislikeCallback {
// override fun onSelected(position: Int, value: String) {}
//
// override fun onCancel() {}
//
// /**
// * 拒绝再次提交
// */
// /**
// * 拒绝再次提交
// */
// override fun onRefuse() {}
// override fun onShow() {}
// })
// })
// } else {
// if (adViewHolder.mDislike != null) adViewHolder.mDislike.setVisibility(View.GONE)
// }
//设置事件回调
ad
.
setTTNativeAdListener
(
mTTNativeAdListener
)
//可以被点击的view, 也可以把convertView放进来意味item可被点击
val
clickViewList
:
MutableList
<
View
>
=
ArrayList
()
clickViewList
.
add
(
convertView
)
adViewHolder
.
mSource
?.
let
{
clickViewList
.
add
(
it
)
}
adViewHolder
.
mTitle
?.
let
{
clickViewList
.
add
(
it
)
}
adViewHolder
.
mDescription
?.
let
{
clickViewList
.
add
(
it
)
}
adViewHolder
.
mIcon
?.
let
{
clickViewList
.
add
(
it
)
}
//添加点击区域
if
(
adViewHolder
is
LargeAdViewHolder
)
{
adViewHolder
.
mLargeImage
?.
let
{
clickViewList
.
add
(
it
)
}
}
else
if
(
adViewHolder
is
SmallAdViewHolder
)
{
adViewHolder
.
mSmallImage
?.
let
{
clickViewList
.
add
(
it
)
}
}
else
if
(
adViewHolder
is
VerticalAdViewHolder
)
{
adViewHolder
.
mVerticalImage
?.
let
{
clickViewList
.
add
(
it
)
}
}
else
if
(
adViewHolder
is
VideoAdViewHolder
)
{
adViewHolder
.
videoView
?.
let
{
clickViewList
.
add
(
it
)
}
}
else
if
(
adViewHolder
is
GroupAdViewHolder
)
{
adViewHolder
.
mGroupImage1
?.
let
{
clickViewList
.
add
(
it
)
}
adViewHolder
.
mGroupImage2
?.
let
{
clickViewList
.
add
(
it
)
}
adViewHolder
.
mGroupImage3
?.
let
{
clickViewList
.
add
(
it
)
}
}
//触发创意广告的view(点击下载或拨打电话)
val
creativeViewList
:
MutableList
<
View
>
=
ArrayList
()
adViewHolder
.
mCreativeButton
?.
let
{
creativeViewList
.
add
(
it
)
}
//重要! 这个涉及到广告计费,必须正确调用。convertView必须使用ViewGroup。
ad
.
registerView
((
convertView
as
ViewGroup
),
clickViewList
,
creativeViewList
,
viewBinder
)
adViewHolder
.
mTitle
?.
text
=
ad
.
title
//title为广告的简单信息提示
adViewHolder
.
mDescription
?.
text
=
ad
.
description
//description为广告的较长的说明
adViewHolder
.
mSource
?.
text
=
if
(
TextUtils
.
isEmpty
(
ad
.
source
))
"广告来源"
else
ad
.
source
val
icon
=
ad
.
iconUrl
if
(
icon
!=
null
)
{
adViewHolder
.
mIcon
?.
let
{
Glide
.
with
(
MintsApplication
.
getContext
()).
load
(
icon
).
into
(
it
)
}
}
val
adCreativeButton
:
Button
?
=
adViewHolder
.
mCreativeButton
when
(
ad
.
interactionType
)
{
TTAdConstant
.
INTERACTION_TYPE_DOWNLOAD
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
adCreativeButton
?.
text
=
if
(
TextUtils
.
isEmpty
(
ad
.
actionText
))
"立即下载"
else
ad
.
actionText
}
TTAdConstant
.
INTERACTION_TYPE_DIAL
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
adCreativeButton
?.
text
=
"立即拨打"
}
TTAdConstant
.
INTERACTION_TYPE_LANDING_PAGE
,
TTAdConstant
.
INTERACTION_TYPE_BROWSER
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
adCreativeButton
?.
text
=
if
(
TextUtils
.
isEmpty
(
ad
.
actionText
))
"查看详情"
else
ad
.
actionText
}
else
->
{
adCreativeButton
?.
visibility
=
View
.
GONE
}
}
}
private
class
VideoAdViewHolder
:
AdViewHolder
()
{
var
videoView
:
FrameLayout
?
=
null
}
private
class
LargeAdViewHolder
:
AdViewHolder
()
{
var
mLargeImage
:
ImageView
?
=
null
}
private
class
SmallAdViewHolder
:
AdViewHolder
()
{
var
mSmallImage
:
ImageView
?
=
null
}
private
class
VerticalAdViewHolder
:
AdViewHolder
()
{
var
mVerticalImage
:
ImageView
?
=
null
}
private
class
GroupAdViewHolder
:
AdViewHolder
()
{
var
mGroupImage1
:
ImageView
?
=
null
var
mGroupImage2
:
ImageView
?
=
null
var
mGroupImage3
:
ImageView
?
=
null
}
private
class
ExpressAdViewHolder
{
var
mAdContainerView
:
FrameLayout
?
=
null
}
private
open
class
AdViewHolder
{
var
viewBinder
:
TTViewBinder
?
=
null
var
mIcon
:
ImageView
?
=
null
var
mDislike
:
ImageView
?
=
null
var
mCreativeButton
:
Button
?
=
null
var
mTitle
:
TextView
?
=
null
var
mDescription
:
TextView
?
=
null
var
mSource
:
TextView
?
=
null
var
mLogo
:
RelativeLayout
?
=
null
}
private
var
mTTNativeAdListener
:
TTNativeAdListener
=
object
:
TTNativeAdListener
{
override
fun
onAdClick
()
{
LogUtil
.
d
(
TAG
,
"onAdClick"
)
}
override
fun
onAdShow
()
{
LogUtil
.
d
(
TAG
,
"onAdShow"
)
}
}
//渲染模板广告
//渲染模板广告
// private fun getExpressAdView(ad: TTNativeAd): View? {
// private fun getExpressAdView(ad: TTNativeAd): View? {
// val adViewHolder: GroMoreExpressManager.ExpressAdViewHolder
// val adViewHolder: GroMoreExpressManager.ExpressAdViewHolder
...
...
GoodMoney/app/src/main/java/com/mints/goodmoney/ad/express/GroMoreExpressManager.kt
View file @
6a8580b3
...
@@ -101,7 +101,7 @@ class GroMoreExpressManager : TTSettingConfigCallback {
...
@@ -101,7 +101,7 @@ class GroMoreExpressManager : TTSettingConfigCallback {
.
setTTVideoOption
(
videoOption
)
//视频声音相关的配置
.
setTTVideoOption
(
videoOption
)
//视频声音相关的配置
.
setAdmobNativeAdOptions
(
admobNativeAdOptions
)
.
setAdmobNativeAdOptions
(
admobNativeAdOptions
)
.
setAdStyleType
(
mAdStyle
)
//必传,表示请求的模板广告还是原生广告,AdSlot.TYPE_EXPRESS_AD:模板广告 ; AdSlot.TYPE_NATIVE_AD:原生广告
.
setAdStyleType
(
mAdStyle
)
//必传,表示请求的模板广告还是原生广告,AdSlot.TYPE_EXPRESS_AD:模板广告 ; AdSlot.TYPE_NATIVE_AD:原生广告
.
setImageAdSize
(
UIUtils
.
getScreenWidthDp
(
MintsApplication
.
getContext
()).
toInt
(),
32
0
)
// 必选参数 单位dp ,详情见上面备注解释
.
setImageAdSize
(
340
,
0
)
// 必选参数 单位dp ,详情见上面备注解释
.
setAdCount
(
1
)
//请求广告数量为1到3条
.
setAdCount
(
1
)
//请求广告数量为1到3条
.
setGdtNativeAdLogoParams
(
gdtNativeAdLogUtiloParams
)
// 设置gdt logo布局参数。
.
setGdtNativeAdLogoParams
(
gdtNativeAdLogUtiloParams
)
// 设置gdt logo布局参数。
.
build
()
.
build
()
...
@@ -129,7 +129,9 @@ class GroMoreExpressManager : TTSettingConfigCallback {
...
@@ -129,7 +129,9 @@ class GroMoreExpressManager : TTSettingConfigCallback {
}
}
if
(
ads
.
size
>
0
)
{
if
(
ads
.
size
>
0
)
{
mADLoadSuccessListener
?.
onGMAdLoadSuc
(
ads
[
0
])
mADLoadSuccessListener
?.
onGMAdLoadSuc
(
createAdView
(
ads
[
0
]))
val
ttNativeAd
=
ads
[
0
]
val
ttNativeAd
=
ads
[
0
]
val
vo
=
HashMap
<
String
,
Any
>()
val
vo
=
HashMap
<
String
,
Any
>()
vo
[
"adcode"
]
=
ttNativeAd
.
getAdNetworkRitId
()
vo
[
"adcode"
]
=
ttNativeAd
.
getAdNetworkRitId
()
...
@@ -252,7 +254,7 @@ class GroMoreExpressManager : TTSettingConfigCallback {
...
@@ -252,7 +254,7 @@ class GroMoreExpressManager : TTSettingConfigCallback {
sWidth
=
FrameLayout
.
LayoutParams
.
MATCH_PARENT
sWidth
=
FrameLayout
.
LayoutParams
.
MATCH_PARENT
sHeight
=
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
sHeight
=
FrameLayout
.
LayoutParams
.
WRAP_CONTENT
}
else
{
}
else
{
sWidth
=
UIUtils
.
getScreenWidth
Dp
(
MintsApplication
.
getContext
()).
toInt
()
sWidth
=
UIUtils
.
getScreenWidth
(
MintsApplication
.
getContext
()).
toInt
()
sHeight
=
(
sWidth
*
height
/
width
).
toInt
()
sHeight
=
(
sWidth
*
height
/
width
).
toInt
()
}
}
if
(
video
!=
null
)
{
if
(
video
!=
null
)
{
...
...
GoodMoney/app/src/main/java/com/mints/goodmoney/ad/express/PreLoadExpressManager.kt
View file @
6a8580b3
...
@@ -152,11 +152,11 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
...
@@ -152,11 +152,11 @@ object PreLoadExpressManager : TTADLoadSuccessListener, YLHADLoadSuccessListener
mAdFrameLayout
?.
addView
(
view
)
mAdFrameLayout
?.
addView
(
view
)
}
}
override
fun
onGMAdLoadSuc
(
ttNativeAd
:
TTNativeAd
?)
{
override
fun
onGMAdLoadSuc
(
ttNativeAd
:
View
?)
{
// if (currentIndex == 3) {
// if (currentIndex == 3) {
// mAdFrameLayout?.addView(view)
// mAdFrameLayout?.addView(view)
// }
// }
mAdFrameLayout
?.
addView
(
ttNativeAd
?.
expressView
)
mAdFrameLayout
?.
addView
(
ttNativeAd
)
}
}
}
}
...
@@ -174,5 +174,5 @@ interface KSADLoadSuccessListener {
...
@@ -174,5 +174,5 @@ interface KSADLoadSuccessListener {
}
}
interface
GMADLoadSuccessListener
{
interface
GMADLoadSuccessListener
{
fun
onGMAdLoadSuc
(
ttNativeAd
:
TTNativeAd
?)
fun
onGMAdLoadSuc
(
ttNativeAd
:
View
?)
}
}
\ No newline at end of file
GoodMoney/app/src/main/java/com/mints/goodmoney/ui/fragment/TaskCpdFragment.kt
View file @
6a8580b3
...
@@ -322,7 +322,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
...
@@ -322,7 +322,7 @@ class TaskCpdFragment : BaseFragment(), TaskView,
// cpdLoadCountTime = cpdMax
// cpdLoadCountTime = cpdMax
RxjavaUtil
.
executeRxTask
<
MutableList
<
TzTaskBean
>>
(
object
:
CommonRxTask
<
MutableList
<
TzTaskBean
>>()
{
RxjavaUtil
.
executeRxTask
(
object
:
CommonRxTask
<
MutableList
<
TzTaskBean
>>()
{
override
fun
doInIOThread
()
{
override
fun
doInIOThread
()
{
val
newPkgData
=
mutableListOf
<
TzTaskBean
>()
val
newPkgData
=
mutableListOf
<
TzTaskBean
>()
...
...
GoodMoney/app/src/main/java/com/mints/goodmoney/utils/UIUtils.java
View file @
6a8580b3
...
@@ -29,6 +29,11 @@ public class UIUtils {
...
@@ -29,6 +29,11 @@ public class UIUtils {
return
width
/
(
scale
<=
0
?
1
:
scale
)
+
0.5f
;
return
width
/
(
scale
<=
0
?
1
:
scale
)
+
0.5f
;
}
}
public
static
int
getScreenWidth
(
Context
context
)
{
DisplayMetrics
dm
=
context
.
getResources
().
getDisplayMetrics
();
return
dm
.
widthPixels
;
}
//全面屏、刘海屏适配
//全面屏、刘海屏适配
public
static
float
getHeight
(
Activity
activity
)
{
public
static
float
getHeight
(
Activity
activity
)
{
hideBottomUIMenu
(
activity
);
hideBottomUIMenu
(
activity
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment