Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_vedio
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_vedio
Commits
3b5ddb43
Commit
3b5ddb43
authored
Nov 20, 2024
by
mengcuiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化
parent
9185435e
Changes
42
Hide whitespace changes
Inline
Side-by-side
Showing
42 changed files
with
1 addition
and
6218 deletions
+1
-6218
build.gradle
video/app/build.gradle
+0
-14
Baidu_MobAds_SDK_v9.37.aar
video/app/libs/Baidu_MobAds_SDK_v9.37.aar
+0
-0
GDTSDK.unionNormal.4.591.1461.aar
video/app/libs/GDTSDK.unionNormal.4.591.1461.aar
+0
-0
kssdk-ad-3.3.67.1.aar
video/app/libs/kssdk-ad-3.3.67.1.aar
+0
-0
mediation_baidu_adapter_9.37.0.aar
video/app/libs/mediation_baidu_adapter_9.37.0.aar
+0
-0
mediation_gdt_adapter_4.591.1461.2.aar
video/app/libs/mediation_gdt_adapter_4.591.1461.2.aar
+0
-0
mediation_ks_adapter_3.3.67.1.0.aar
video/app/libs/mediation_ks_adapter_3.3.67.1.0.aar
+0
-0
AndroidManifest.xml
video/app/src/main/AndroidManifest.xml
+0
-8
MintsApplication.java
...app/src/main/java/com/duben/heliapp/MintsApplication.java
+0
-3
AdManager.kt
video/app/src/main/java/com/duben/heliapp/ad/AdManager.kt
+0
-47
AdStatusListener.kt
...pp/src/main/java/com/duben/heliapp/ad/AdStatusListener.kt
+0
-11
NoPreAdManager.kt
.../app/src/main/java/com/duben/heliapp/ad/NoPreAdManager.kt
+0
-36
TTAdManagerHolder.java
...src/main/java/com/duben/heliapp/ad/TTAdManagerHolder.java
+0
-183
BannerManager.kt
...rc/main/java/com/duben/heliapp/ad/banner/BannerManager.kt
+0
-133
DrawExpressManager.kt
...main/java/com/duben/heliapp/ad/draw/DrawExpressManager.kt
+0
-938
HomeDrawExpressManager.kt
.../java/com/duben/heliapp/ad/draw/HomeDrawExpressManager.kt
+0
-931
ExpressAdCallback.kt
...in/java/com/duben/heliapp/ad/express/ExpressAdCallback.kt
+0
-13
ExpressManager.kt
.../main/java/com/duben/heliapp/ad/express/ExpressManager.kt
+0
-906
MainExpressManager.kt
...n/java/com/duben/heliapp/ad/express/MainExpressManager.kt
+0
-830
MyExpressManager.kt
...ain/java/com/duben/heliapp/ad/express/MyExpressManager.kt
+0
-905
SplashManager.kt
...rc/main/java/com/duben/heliapp/ad/splash/SplashManager.kt
+0
-155
InMoneyVideo.java
...rc/main/java/com/duben/heliapp/ad/video/InMoneyVideo.java
+0
-263
InMoneyVideoNoPre.java
...in/java/com/duben/heliapp/ad/video/InMoneyVideoNoPre.java
+0
-201
LocalVedioManager.kt
.../main/java/com/duben/heliapp/manager/LocalVedioManager.kt
+0
-4
NineActivity.kt
.../main/java/com/duben/heliapp/ui/activitys/NineActivity.kt
+0
-40
SplashActivity.kt
...ain/java/com/duben/heliapp/ui/activitys/SplashActivity.kt
+1
-21
SplashAdActivity.kt
...n/java/com/duben/heliapp/ui/activitys/SplashAdActivity.kt
+0
-132
SplashForeAdActivity.kt
...va/com/duben/heliapp/ui/activitys/SplashForeAdActivity.kt
+0
-117
MainFragment.kt
...c/main/java/com/duben/heliapp/ui/fragment/MainFragment.kt
+0
-8
MovieFragment.kt
.../main/java/com/duben/heliapp/ui/fragment/MovieFragment.kt
+0
-17
MyFragment.kt
...src/main/java/com/duben/heliapp/ui/fragment/MyFragment.kt
+0
-74
VipCountDialog.kt
.../main/java/com/duben/heliapp/ui/widgets/VipCountDialog.kt
+0
-27
ForegroundOrBackground.java
.../java/com/duben/heliapp/utils/ForegroundOrBackground.java
+0
-11
RecommendVideoView.java
...n/java/com/duben/heliapp/video/tx/RecommendVideoView.java
+0
-7
SuperShortVideoView.java
.../java/com/duben/heliapp/video/tx/SuperShortVideoView.java
+0
-8
TxVideoActivity.kt
...c/main/java/com/duben/heliapp/video/tx/TxVideoActivity.kt
+0
-50
TxVideoFragment.kt
...c/main/java/com/duben/heliapp/video/tx/TxVideoFragment.kt
+0
-3
TxRecommendVideoAdapter.kt
...duben/heliapp/video/tx/adapter/TxRecommendVideoAdapter.kt
+0
-20
TxVideoAdapter.kt
...java/com/duben/heliapp/video/tx/adapter/TxVideoAdapter.kt
+0
-22
NewTxVideoActivity.kt
...duben/heliapp/video/tx/newrecommend/NewTxVideoActivity.kt
+0
-39
NewTxVideoAdapter.kt
.../duben/heliapp/video/tx/newrecommend/NewTxVideoAdapter.kt
+0
-30
build.gradle
video/build.gradle
+0
-11
No files found.
video/app/build.gradle
View file @
3b5ddb43
...
...
@@ -207,20 +207,6 @@ dependencies {
// 头条分包接入
// umeng 接入
// 穿山甲短剧
// implementation("com.pangle.cn:pangrowth-sdk:3.9.0.2") {
// exclude group: 'com.pangle.cn', module: 'pangrowth-game-sdk'
// exclude group: 'com.pangle.cn', module: 'pangrowth-novel-sdk'
// exclude group: 'com.pangle.cn', module: 'pangrowth-luckycat-sdk'
// exclude group: 'com.pangle.cn', module: 'partner-luckycat-api-sdk'
// exclude group: 'com.pangle.cn', module: 'pangrowth-reward-sdk'
// exclude group: 'com.pangle.cn', module: 'partner-live-sdk'
// exclude group: 'com.tencent.mm.opensdk', module: 'wechat-sdk-android'
// }
// 穿山甲聚合 接入【穿山甲、快手】
implementation
"com.pangle.cn:mediation-sdk:6.4.1.5"
// 穿山甲Applog 上报组件(必须)
implementation
'com.bytedance.applog:RangersAppLog-Lite-cn:6.16.3'
// 穿山甲商业化转化组件(必须)
...
...
video/app/libs/Baidu_MobAds_SDK_v9.37.aar
deleted
100644 → 0
View file @
9185435e
File deleted
video/app/libs/GDTSDK.unionNormal.4.591.1461.aar
deleted
100644 → 0
View file @
9185435e
File deleted
video/app/libs/kssdk-ad-3.3.67.1.aar
deleted
100644 → 0
View file @
9185435e
File deleted
video/app/libs/mediation_baidu_adapter_9.37.0.aar
deleted
100644 → 0
View file @
9185435e
File deleted
video/app/libs/mediation_gdt_adapter_4.591.1461.2.aar
deleted
100644 → 0
View file @
9185435e
File deleted
video/app/libs/mediation_ks_adapter_3.3.67.1.0.aar
deleted
100644 → 0
View file @
9185435e
File deleted
video/app/src/main/AndroidManifest.xml
View file @
3b5ddb43
...
...
@@ -82,14 +82,6 @@
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".ui.activitys.SplashAdActivity"
android:exported=
"false"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ui.activitys.SplashForeAdActivity"
android:exported=
"false"
android:screenOrientation=
"portrait"
/>
<activity
android:name=
".ui.activitys.MobileLoginActivity"
android:configChanges=
"orientation|screenSize|keyboardHidden"
...
...
video/app/src/main/java/com/duben/heliapp/MintsApplication.java
View file @
3b5ddb43
...
...
@@ -9,7 +9,6 @@ import androidx.multidex.MultiDexApplication;
import
com.downloader.PRDownloader
;
import
com.downloader.PRDownloaderConfig
;
import
com.duben.heliapp.ad.TTAdManagerHolder
;
import
com.duben.heliapp.common.Constant
;
import
com.duben.heliapp.manager.CsjAppLogManager
;
import
com.duben.heliapp.manager.TXCSDKService
;
...
...
@@ -78,8 +77,6 @@ public class MintsApplication extends MultiDexApplication {
initMiitHelper
();
TTAdManagerHolder
.
init
(
this
);
TXCSDKService
.
init
(
this
);
CsjAppLogManager
.
INSTANCE
.
init
(
this
);
...
...
video/app/src/main/java/com/duben/heliapp/ad/AdManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad
import
android.app.Activity
import
com.duben.heliapp.ad.splash.SplashManager
import
com.duben.heliapp.ad.video.InMoneyVideo
import
com.duben.heliapp.manager.UserManager
/**
* 预加载-全屏及激励视频管理类
*/
class
AdManager
{
companion
object
{
const
val
AD_NO_SHOWTIME_OUT
=
50
// 广告请示成功但在规定时间内未展示
const
val
AD_REQUEST_TIME_OUT
=
1
// 广告预加载时长超时
val
instance
:
AdManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
AdManager
()
}
}
/**
* 根据服务器概率预加载广告
*
* isPreLoad:是否是预加载调用,需要躲避监听
*/
fun
preLoadAd
(
activity
:
Activity
,
isPreLoad
:
Boolean
=
false
)
{
InMoneyVideo
.
getInstance
().
preLoadAd
(
activity
,
isPreLoad
)
}
/**
* 根据预加载类型 展示广告
*/
fun
showAd
(
activity
:
Activity
,
carrierType
:
String
,
AdStatusListener
:
AdStatusListener
?,
)
{
InMoneyVideo
.
getInstance
()
.
showRewardAd
(
activity
,
AdStatusListener
,
carrierType
,
)
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/AdStatusListener.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad
import
java.util.HashMap
interface
AdStatusListener
{
fun
adSuccess
()
fun
adFail
()
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/NoPreAdManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad
import
android.app.Activity
import
com.duben.heliapp.ad.video.InMoneyVideoNoPre
import
java.util.HashMap
/**
* 实时加载激励视频、全屏
*/
object
NoPreAdManager
{
private
val
TAG
=
NoPreAdManager
::
class
.
java
.
simpleName
fun
loadVideoAd
(
activity
:
Activity
,
carrierType
:
String
,
listener
:
AdStatusListener
?
)
{
val
adNoProListener
=
object
:
AdStatusListener
{
override
fun
adFail
()
{
listener
?.
adFail
()
}
override
fun
adSuccess
()
{
listener
?.
adSuccess
()
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
listener
?.
adClose
(
vo
)
}
}
InMoneyVideoNoPre
.
getInstance
().
loadAd
(
activity
,
adNoProListener
,
carrierType
)
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/TTAdManagerHolder.java
deleted
100644 → 0
View file @
9185435e
package
com
.
duben
.
heliapp
.
ad
;
import
android.content.Context
;
import
android.util.Log
;
import
com.bytedance.hume.readapk.HumeSDK
;
import
com.bytedance.sdk.openadsdk.TTAdConfig
;
import
com.bytedance.sdk.openadsdk.TTAdManager
;
import
com.bytedance.sdk.openadsdk.TTAdSdk
;
import
com.bytedance.sdk.openadsdk.TTCustomController
;
import
com.bytedance.sdk.openadsdk.mediation.init.MediationConfigUserInfoForSegment
;
import
com.bytedance.sdk.openadsdk.mediation.init.MediationPrivacyConfig
;
import
com.duben.heliapp.BuildConfig
;
import
com.duben.heliapp.MintsApplication
;
import
com.duben.heliapp.common.Constant
;
import
com.duben.heliapp.utils.AppPreferencesManager
;
import
com.duben.heliapp.utils.DeviceUuidFactory
;
import
com.duben.heliapp.utils.LogUtil
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* 可以用一个单例来保存TTAdManager实例,在需要初始化sdk的时候调用
*/
public
class
TTAdManagerHolder
{
private
static
final
String
TT_AD_APPID
=
BuildConfig
.
GROMORE_APP_ID
;
private
static
final
String
TT_AD_NAME
=
Constant
.
MINTS_APP_NAME
;
private
static
final
String
TAG
=
"TTAdManagerHolder"
;
private
static
boolean
sInit
;
public
static
TTAdManager
get
()
{
return
TTAdSdk
.
getAdManager
();
}
public
static
void
init
(
final
Context
context
)
{
//初始化穿山甲SDK
doInit
(
context
);
}
//step1:接入网盟广告sdk的初始化操作,详情见接入文档和穿山甲平台说明
private
static
void
doInit
(
Context
context
)
{
if
(!
sInit
)
{
//TTAdSdk.init(context, buildConfig(context));
//setp1.1:初始化SDK
TTAdSdk
.
init
(
context
,
buildConfig
(
context
));
//setp1.2:启动SDK
TTAdSdk
.
start
(
new
TTAdSdk
.
Callback
()
{
@Override
public
void
success
()
{
Log
.
i
(
TAG
,
"success: "
+
TTAdSdk
.
isInitSuccess
());
}
@Override
public
void
fail
(
int
code
,
String
msg
)
{
Log
.
i
(
TAG
,
"fail: code = "
+
code
+
" msg = "
+
msg
);
}
});
sInit
=
true
;
}
}
private
static
TTAdConfig
buildConfig
(
Context
context
)
{
return
new
TTAdConfig
.
Builder
()
/**
* 注:需要替换成在媒体平台申请的appID ,切勿直接复制
*/
.
appId
(
TT_AD_APPID
)
.
appName
(
TT_AD_NAME
)
/**
* 上线前需要关闭debug开关,否则会影响性能
*/
.
debug
(
BuildConfig
.
DEBUG
)
/**
* 使用聚合功能此开关必须设置为true,默认为false,不会初始化聚合模板,聚合功能会吟唱
*/
.
useMediation
(
true
)
.
customController
(
getTTCustomController
())
//如果您需要设置隐私策略请参考该api
// .setMediationConfig(new MediationConfig.Builder() //可设置聚合特有参数详细设置请参考该api
// .setMediationConfigUserInfoForSegment(getUserInfoForSegment())//如果您需要配置流量分组信息请参考该api
// .build())
.
build
();
}
private
static
MediationConfigUserInfoForSegment
getUserInfoForSegment
(){
MediationConfigUserInfoForSegment
userInfo
=
new
MediationConfigUserInfoForSegment
();
userInfo
.
setUserId
(
new
DeviceUuidFactory
().
getDeviceUuid
().
toString
());
userInfo
.
setGender
(
MediationConfigUserInfoForSegment
.
GENDER_MALE
);
// userInfo.setChannel("msdk-channel");
userInfo
.
setSubChannel
(
HumeSDK
.
getChannel
(
MintsApplication
.
getContext
()));
// userInfo.setAge(999);
// userInfo.setUserValueGroup("msdk-demo-user-value-group");
Map
<
String
,
String
>
customInfos
=
new
HashMap
<>();
// customInfos.put("aaaa", "test111");
// customInfos.put("bbbb", "test222");
userInfo
.
setCustomInfos
(
customInfos
);
return
userInfo
;
}
private
static
TTCustomController
getTTCustomController
(){
return
new
TTCustomController
()
{
@Override
public
boolean
isCanUsePhoneState
()
{
return
false
;
}
@Override
public
boolean
isCanUseWifiState
()
{
return
false
;
}
@Override
public
String
getMacAddress
()
{
return
""
;
}
@Override
public
boolean
isCanUseWriteExternal
()
{
return
false
;
}
@Override
public
String
getDevOaid
()
{
return
""
;
}
@Override
public
boolean
isCanUseAndroidId
()
{
return
false
;
}
@Override
public
String
getAndroidId
()
{
return
""
;
}
@Override
public
MediationPrivacyConfig
getMediationPrivacyConfig
()
{
return
new
MediationPrivacyConfig
()
{
@Override
public
boolean
isCanUseOaid
()
{
return
false
;
}
@Override
public
boolean
isLimitPersonalAds
()
{
if
(
AppPreferencesManager
.
INSTANCE
.
get
()
.
getBoolean
(
Constant
.
LOAN_PERMISSION_FLAG
,
true
))
return
false
;
return
super
.
isLimitPersonalAds
();
}
@Override
public
boolean
isProgrammaticRecommend
()
{
if
(
AppPreferencesManager
.
INSTANCE
.
get
()
.
getBoolean
(
Constant
.
LOAN_PERMISSION_FLAG
,
true
))
return
false
;
return
super
.
isProgrammaticRecommend
();
}
};
}
@Override
public
boolean
isCanUsePermissionRecordAudio
()
{
if
(
AppPreferencesManager
.
INSTANCE
.
get
()
.
getBoolean
(
Constant
.
LOAN_PERMISSION_FLAG
,
true
))
return
false
;
return
super
.
isCanUsePermissionRecordAudio
();
}
};
}
}
video/app/src/main/java/com/duben/heliapp/ad/banner/BannerManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.banner
import
android.app.Activity
import
android.view.View
import
android.widget.FrameLayout
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.ad.IMediationNativeAdInfo
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationNativeToBannerListener
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.UIUtils
import
java.lang.ref.WeakReference
import
com.duben.heliapp.BuildConfig
/**
* banner
*/
object
BannerManager
{
private
val
TAG
=
BannerManager
::
class
.
java
.
simpleName
private
var
weakFrameLayout
:
WeakReference
<
FrameLayout
>?
=
null
private
var
weakActivity
:
WeakReference
<
Activity
>?
=
null
private
var
bannerAd
:
TTNativeExpressAd
?
=
null
fun
loadAd
(
act
:
Activity
?,
view
:
FrameLayout
?)
{
weakActivity
=
WeakReference
<
Activity
>(
act
)
weakFrameLayout
=
WeakReference
<
FrameLayout
>(
view
)
LogUtil
.
d
(
TAG
,
"gromore banner广告-> 1、进入加载"
)
/** 这里是简单的banner请求adSlot设置,如果需要更多的设置,可参考AdUtils.kt中bannerAdSlot函数部分。 */
var
adSlot
:
AdSlot
=
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_BANNER_CODE
)
// .setImageAcceptedSize(UIUtils.dp2px(weakActivity?.get(), 300f), UIUtils.dp2px(weakActivity?.get(), 45f)) // 单位px
// .setImageAcceptedSize(
// UIUtils.getAdWidth2(MintsApplication.getContext()).toInt(),
// 0
// )
// 单位px
.
supportRenderControl
()
//支持模板样式
.
setExpressViewAcceptedSize
(
UIUtils
.
getAdWidth2
(
MintsApplication
.
getContext
()),
0f
)
//设置模板宽高(dp)
.
setUserID
(
"1234"
)
.
setMediationAdSlot
(
MediationAdSlot
.
Builder
()
/**
* banner混出自渲染信息流时,需要提供该转换listener,将信息流自渲染素材转成view。模板类型无需处理
* 如果未使用banner混出信息流功能,则无需设置MediationNativeToBannerListener。
* 如要使用混出功能,可参考AdUtils.kt类中getCSJMBannerViewFromNativeAd函数部分。
*/
.
setMediationNativeToBannerListener
(
object
:
MediationNativeToBannerListener
()
{
override
fun
getMediationBannerViewFromNativeAd
(
adInfo
:
IMediationNativeAdInfo
):
View
?
{
return
null
}
})
.
build
()
)
.
build
()
var
adNativeLoader
:
TTAdNative
=
TTAdSdk
.
getAdManager
().
createAdNative
(
weakActivity
?.
get
())
adNativeLoader
.
loadBannerExpressAd
(
adSlot
,
object
:
TTAdNative
.
NativeExpressAdListener
{
override
fun
onNativeExpressAdLoad
(
ads
:
MutableList
<
TTNativeExpressAd
>?)
{
LogUtil
.
d
(
TAG
,
"banner广告-> 2、 load success: "
+
if
(
ads
==
null
)
"0"
else
ads
?.
size
)
ads
?.
let
{
if
(
it
.
size
>
0
)
{
val
ad
:
TTNativeExpressAd
=
it
[
0
]
bannerAd
=
ad
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
)
{
}
override
fun
onRenderSuccess
(
view
:
View
?,
width
:
Float
,
height
:
Float
)
{
}
})
bannerAd
?.
setDislikeCallback
(
weakActivity
?.
get
(),
object
:
TTAdDislike
.
DislikeInteractionCallback
{
override
fun
onShow
()
{
}
override
fun
onSelected
(
position
:
Int
,
value
:
String
?,
enforce
:
Boolean
)
{
weakFrameLayout
?.
get
()
?.
removeAllViews
()
}
override
fun
onCancel
()
{
}
})
showAd
()
}
}
}
override
fun
onError
(
code
:
Int
,
message
:
String
?)
{
LogUtil
.
e
(
TAG
,
"banner广告-> 2、 load fail: $code, $message"
)
}
})
}
private
fun
showAd
()
{
val
bannerView
:
View
?
=
bannerAd
?.
expressAdView
if
(
bannerView
!=
null
&&
weakFrameLayout
!=
null
)
{
val
bannerContainer
=
weakFrameLayout
!!
.
get
()
bannerContainer
!!
.
removeAllViews
()
bannerContainer
!!
.
addView
(
bannerView
)
}
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/draw/DrawExpressManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.draw
import
android.net.Uri
import
android.text.TextUtils
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
com.bumptech.glide.Glide
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationExpressRenderListener
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationViewBinder
import
com.duben.heliapp.BuildConfig
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.ForegroundOrBackground
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.TimeRender
import
com.duben.heliapp.utils.UIUtils
import
java.lang.Exception
import
java.util.*
private
val
TAG
=
DrawExpressManager
::
class
.
java
.
simpleName
/**
* 信息流
*/
class
DrawExpressManager
{
companion
object
{
val
instance
:
DrawExpressManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
DrawExpressManager
()
}
}
private
var
adShowTime
:
Long
=
0
// 防止预加载超时 2秒
private
var
isShowAd
=
false
// 广告是否展示
private
var
expressId
:
String
=
""
private
val
adLoadTime
:
Long
=
0
// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private
var
adPreingTime
:
Long
=
0
// 防止预加载超时 2分钟
private
var
isLoadSuccess
=
0
//0-加载失败/未加载 1-加载中 2-加载成功
private
var
mExpressAdCallback
:
ExpressAdCallback
?
=
null
private
var
viewCache
=
Stack
<
FrameLayout
>()
private
var
ttFeedAdCache
=
Stack
<
TTFeedAd
>()
// 载体
private
var
adcode
=
""
private
var
ecpm
=
""
private
var
adSource
=
""
fun
getAdIsLoadSuc
():
Boolean
{
isAdDestroy
()
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
return
isLoadSuccess
==
2
&&
!
isOversped
}
private
fun
isAdDestroy
()
{
if
(
isLoadSuccess
==
2
&&
(
viewCache
.
isEmpty
()
||
ttFeedAdCache
.
isEmpty
()))
{
// 重置广告状态
isLoadSuccess
=
0
isShowAd
=
true
adShowTime
=
System
.
currentTimeMillis
()
}
}
fun
preLoadAd
()
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
val
isPreingOversped
=
TimeRender
.
isOverspedMin
(
adPreingTime
,
AdManager
.
AD_REQUEST_TIME_OUT
)
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if
((
isLoadSuccess
==
0
// 加载失败
||
adLoadTime
>
0
&&
isOversped
// 超过45分钟
||
adPreingTime
>
0
&&
isPreingOversped
&&
isLoadSuccess
==
1
)
// 预加载超时
)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 2、执行预加载去了=$isLoadSuccess"
)
adPreingTime
=
System
.
currentTimeMillis
()
isLoadSuccess
=
1
// 销毁及移除事件
loadAd
()
}
}
private
fun
loadAd
()
{
expressId
=
BuildConfig
.
GROMORE_DRAW_CODE
val
activity
=
ForegroundOrBackground
.
getTopActivity
()
val
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
activity
)
val
adslot
=
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_DRAW_CODE
)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.
setImageAcceptedSize
(
UIUtils
.
getScreenWidth
(
MintsApplication
.
getContext
()),
UIUtils
.
getScreenHeight
(
MintsApplication
.
getContext
())
)
.
setMediationAdSlot
(
MediationAdSlot
.
Builder
()
.
setMuted
(
true
)
.
build
()
)
.
setAdCount
(
1
)
//请求广告数量为1到3条 (优先采用平台配置的数量)
.
build
()
adNativeLoader
.
loadDrawFeedAd
(
adslot
,
object
:
TTAdNative
.
DrawFeedAdListener
{
override
fun
onError
(
p0
:
Int
,
p1
:
String
?)
{
LogUtil
.
e
(
TAG
,
"gromore draw信息流--> 3、load feed ad error : $p0, $p1"
)
isLoadSuccess
=
0
}
override
fun
onDrawFeedAdLoad
(
ads
:
MutableList
<
TTDrawFeedAd
>?)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 3、Gromore onAdLoaded expressId=${expressId} "
)
ads
?.
let
{
if
(
it
.
isEmpty
())
{
isLoadSuccess
=
0
return
}
// mTTFeedAd = it[0]
showAd
(
it
[
0
])
}
}
})
}
private
fun
showAd
(
ttFeedAd
:
TTFeedAd
?)
{
ttFeedAd
?.
let
{
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
vo
[
"cpmFen"
]
=
ecpm
TrackManager
.
getInstance
().
cmtEcpm
(
vo
)
}
if
(
it
.
mediationManager
.
isExpress
)
{
//--------------信息流模板广告渲染----------------
showExpressView
(
it
)
}
else
{
//--------------信息流自渲染广告渲染----------------
// val view: View? = when (it.imageMode) {
// TTAdConstant.IMAGE_MODE_SMALL_IMG -> getSmallAdView(frameLayout)//信息流自渲染广告渲染 :小图广告
// TTAdConstant.IMAGE_MODE_LARGE_IMG -> getLargeAdView(frameLayout)//信息流自渲染广告渲染 :大图广告
// TTAdConstant.IMAGE_MODE_GROUP_IMG -> getGroupAdView(frameLayout)//信息流自渲染广告渲染 :组图广告
// TTAdConstant.IMAGE_MODE_VIDEO -> getVideoView(frameLayout)//信息流自渲染广告渲染 :视频广告
// TTAdConstant.IMAGE_MODE_VERTICAL_IMG -> getVerticalAdView(frameLayout)//信息流自渲染广告渲染 :竖图广告
// TTAdConstant.IMAGE_MODE_VIDEO_VERTICAL -> getVideoView(frameLayout)//信息流自渲染广告渲染 :竖版视频广告
// else -> {
// Log.i(TAG, "展示样式错误")
// null
// }
// }
// view?.let { it2 ->
// it2.layoutParams = ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT
// )
// frameLayout?.removeAllViews()
// frameLayout?.addView(it2)
// viewCache.add(frameLayout?.getChildAt(0))
// }
}
}
}
fun
getAdView
(
callback
:
ExpressAdCallback
?)
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
// 若上一个广告还在加载中则返回
if
(
isLoadSuccess
==
1
)
{
this
.
mExpressAdCallback
=
callback
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 3.9、广告加载中 LoadSuccess = $isLoadSuccess"
)
return
}
this
.
mExpressAdCallback
=
null
if
(
isLoadSuccess
==
2
&&
!
isOversped
)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
)
isShowAd
=
true
adShowTime
=
System
.
currentTimeMillis
()
isLoadSuccess
=
0
// callback?.loadSuccess(frameLayout)
if
(
viewCache
.
size
>
0
)
{
callback
?.
loadSuccess
(
viewCache
.
lastElement
())
}
}
else
{
LogUtil
.
e
(
TAG
,
"gromore draw信息流--> 5、展示广告时失败了,广告可能超时45分钟 onError "
)
// 状态重置
isLoadSuccess
=
0
callback
?.
loadFail
()
}
}
private
fun
showExpressView
(
it
:
TTFeedAd
)
{
it
.
setExpressRenderListener
(
object
:
MediationExpressRenderListener
{
override
fun
onRenderSuccess
(
p0
:
View
?,
p1
:
Float
,
p2
:
Float
,
p3
:
Boolean
)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 3、Gromore onRenderSuccess expressId=${expressId} "
)
Log
.
i
(
TAG
,
"onRenderSuccess"
)
isLoadSuccess
=
2
it
.
adView
?.
let
{
view
->
if
(
view
.
parent
!=
null
)
{
(
view
.
parent
as
ViewGroup
).
removeView
(
view
)
}
val
frameLayout
=
FrameLayout
(
MintsApplication
.
getContext
())
frameLayout
.
addView
(
view
)
viewCache
.
add
(
frameLayout
)
ttFeedAdCache
.
add
(
it
)
}
}
override
fun
onRenderFail
(
p0
:
View
?,
p1
:
String
?,
p2
:
Int
)
{
LogUtil
.
e
(
TAG
,
"gromore信息流--> 5、展示广告时失败了,onRenderFail msg=${p1} code=${p2} "
)
}
override
fun
onAdClick
()
{
LogUtil
.
d
(
TAG
,
"onAdClick"
)
}
override
fun
onAdShow
()
{
Log
.
i
(
TAG
,
"onAdShow"
)
Log
.
i
(
TAG
,
"ad mediaExtraInfo ${it.mediaExtraInfo}"
)
}
})
it
.
render
()
//必须要调用render方法进行渲染,在onRenderSuccess中处理模板的view
}
/**
* 销毁
*/
fun
destroy
()
{
// 数据重置
adcode
=
""
ecpm
=
""
adSource
=
""
for
(
frameLayout
in
viewCache
)
{
frameLayout
.
removeAllViews
()
}
viewCache
.
clear
()
for
(
ttFeedAd
in
ttFeedAdCache
)
{
ttFeedAd
.
destroy
()
}
ttFeedAdCache
.
clear
()
isAdDestroy
()
this
.
mExpressAdCallback
=
null
}
// private fun getSmallAdView(parent: ViewGroup?): View? {
// val convertView =
// 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
// 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
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView;
// }
//
// 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
// )
// 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView
// }
//
// 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
// )
// 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.mGroupImage1 =
// convertView.findViewById<View>(R.id.iv_listitem_image1) as ImageView
// adViewHolder.mGroupImage2 =
// convertView.findViewById<View>(R.id.iv_listitem_image2) as ImageView
// adViewHolder.mGroupImage3 =
// convertView.findViewById<View>(R.id.iv_listitem_image3) 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// adViewHolder.viewBinder = viewBinder
//
// bindData(convertView, adViewHolder)
// if (mTTFeedAd?.imageList?.size ?: 0 >= 3) {
// val image1: String? = mTTFeedAd?.imageList?.get(0)?.imageUrl
// val image2: String? = mTTFeedAd?.imageList?.get(1)?.imageUrl
// val image3: String? = mTTFeedAd?.imageList?.get(2)?.imageUrl
// if (image1 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image1)
// .into(adViewHolder.mGroupImage1!!)
// }
// if (image2 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image2)
// .into(adViewHolder.mGroupImage2!!)
// }
// if (image3 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image3)
// .into(adViewHolder.mGroupImage3!!)
// }
// }
// return convertView
// }
//
// private fun getVideoView(parent: ViewGroup?): View? {
// val adViewHolder = VideoAdViewHolder()
// var convertView: View? = null
// try {
// convertView = LayoutInflater.from(ForegroundOrBackground.getTopActivity())
// .inflate(
// R.layout.mediation_listitem_ad_large_video,
// parent,
// false
// )
// 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// adViewHolder.viewBinder = viewBinder
//
// // 如果自己有需求进行视频播放操作,则按如下步骤进行。注意:不是所有adn都支持,因此需要进行判空操作。
//// mTTFeedAd?.csjmAdInfo?.setUseCustomVideo(true) // 注意:要在registerView之前调用
// val videoUrl: String? = mTTFeedAd?.customVideo?.videoUrl // 注意:不是所有adn都支持,这里务必要进行判空操作
// if (!TextUtils.isEmpty(videoUrl)) {
// // 如果通过getVideoUrl返回的url不是空,则自己处理视频播放操作,并通过reporter上报视频状态
// playAdVideo(adViewHolder.videoView as FrameLayout, videoUrl ?: "")
// } else {
// // 注意:即使该adn支持返回url,但某次偶然原因返回的videoUrl为空,则仍然会用adn自己的视频播放作为兜底
// }
//
// //视频广告设置播放状态回调(可选)
// mTTFeedAd?.setVideoAdListener(object : TTFeedAd.VideoAdListener {
// override fun onVideoLoad(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoLoad")
// }
//
// override fun onVideoError(errorCode: Int, extraCode: Int) {
// Log.i(TAG, "onVideoError")
// }
//
// override fun onVideoAdStartPlay(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdStartPlay")
// }
//
// override fun onVideoAdPaused(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdPaused")
// }
//
// override fun onVideoAdContinuePlay(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdContinuePlay")
// }
//
// override fun onProgressUpdate(current: Long, duration: Long) {
// Log.i(TAG, "onProgressUpdate")
// }
//
// override fun onVideoAdComplete(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdComplete")
// }
//
// })
// mTTFeedAd?.setDownloadListener(object : TTAppDownloadListener {
// override fun onIdle() {
// Log.i(TAG, "setDownloadListener")
// }
//
// override fun onDownloadActive(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadActive")
// }
//
// override fun onDownloadPaused(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadPaused")
// }
//
// override fun onDownloadFailed(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadFailed")
// }
//
// override fun onDownloadFinished(
// totalBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadFinished")
// }
//
// override fun onInstalled(fileName: String?, appName: String?) {
// Log.i(TAG, "onInstalled")
// }
//
// })
// //绑定广告数据、设置交互回调
// bindData(convertView, adViewHolder)
// } catch (e: Exception) {
// e.printStackTrace()
// }
//
// return convertView
// }
//
// private var mVideoView: VideoView? = null
// private var customVideoReporter: TTFeedAd.CustomizeVideo? = null
//
// private fun playAdVideo(videoContainer: ViewGroup, videoUrl: String) {
// mVideoView = VideoView(MintsApplication.getContext())
// videoContainer.addView(mVideoView)
// customVideoReporter = mTTFeedAd?.customVideo
// // 开发者根据自己的需求,做相应的视频控制界面,播放暂停等
// mVideoView?.setVideoURI(Uri.parse(videoUrl))
// mVideoView?.setOnErrorListener { mp, what, extra ->
// if (customVideoReporter != null) {
// customVideoReporter?.reportVideoError(
// mVideoView!!.currentPosition.toLong(),
// what,
// extra
// )
// }
// false
// }
// mVideoView?.setOnCompletionListener {
// if (customVideoReporter != null) {
// customVideoReporter?.reportVideoFinish()
// }
// }
// mVideoView?.start()
// customVideoReporter?.reportVideoStart()
// }
//
// 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
// )
// 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.mVerticalImage =
// convertView.findViewById<ImageView>(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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView
// }
//
// private fun bindData(convertView: View, adViewHolder: AdViewHolder) {
// mTTFeedAd?.let {
// if (it.mediationManager?.hasDislike() == true) {
// val ttAdDislike: TTAdDislike =
// it.getDislikeDialog(ForegroundOrBackground.getTopActivity())
// adViewHolder.mDislike?.visibility = View.VISIBLE
// adViewHolder.mDislike?.setOnClickListener(View.OnClickListener {
// //使用接口来展示
// ttAdDislike.showDislikeDialog()
// ttAdDislike.setDislikeInteractionCallback(object :
// TTAdDislike.DislikeInteractionCallback {
// override fun onShow() {
// Log.i(TAG, "dislike 点击show")
// }
//
// override fun onSelected(position: Int, value: String?, enforce: Boolean) {
// Log.i(TAG, "点击 $value")
// //用户选择不喜欢原因后,移除广告展示
//// frameLayout?.removeAllViews()
// }
//
// override fun onCancel() {
// Log.i(TAG, "dislike 点击了取消")
// }
//
// })
// })
// } else {
// if (adViewHolder.mDislike != null) adViewHolder.mDislike?.visibility = View.GONE
// }
//
// setDownLoadAppInfo(it, adViewHolder)
//
// //可以被点击的view, 也可以把convertView放进来意味item可被点击
// val clickViewList: MutableList<View?> = ArrayList()
// clickViewList.add(convertView)
// clickViewList.add(adViewHolder.mSource)
// clickViewList.add(adViewHolder.mTitle)
// clickViewList.add(adViewHolder.mDescription)
// clickViewList.add(adViewHolder.mIcon)
//
// //添加点击区域
// if (adViewHolder is LargeAdViewHolder) {
// clickViewList.add(adViewHolder.mLargeImage)
// } else if (adViewHolder is SmallAdViewHolder) {
// clickViewList.add(adViewHolder.mSmallImage)
// } else if (adViewHolder is VerticalAdViewHolder) {
// clickViewList.add(adViewHolder.mVerticalImage)
// } else if (adViewHolder is VideoAdViewHolder) {
// clickViewList.add(adViewHolder.videoView)
// } else if (adViewHolder is GroupAdViewHolder) {
// clickViewList.add(adViewHolder.mGroupImage1)
// clickViewList.add(adViewHolder.mGroupImage2)
// clickViewList.add(adViewHolder.mGroupImage3)
// }
//
// //触发创意广告的view(点击下载或拨打电话)
// val creativeViewList: MutableList<View?> = ArrayList()
// 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")
// }
//
// override fun onAdCreativeClick(view: View?, ad: TTNativeAd?) {
// Log.i(TAG, "onAdCreativeClick")
// }
//
// override fun onAdShow(ad: TTNativeAd?) {
// Log.i(TAG, "onAdShow")
// ad?.let {
//// PrintUtil.printShowInfo(ad.mediationManager)
// }
// }
// },
// adViewHolder.viewBinder
// )
//
// adViewHolder.mTitle?.text = it.title //title为广告的简单信息提示
//
// adViewHolder.mDescription?.text = it.description //description为广告的较长的说明
//
// adViewHolder.mSource?.text =
// 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!!)
// }
// val adCreativeButton = adViewHolder.mCreativeButton
// when (it.interactionType) {
// TTAdConstant.INTERACTION_TYPE_DOWNLOAD -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText(it.buttonText ?: "立即下载")
// }
// TTAdConstant.INTERACTION_TYPE_DIAL -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText("立即拨打");
// }
// TTAdConstant.INTERACTION_TYPE_LANDING_PAGE,
// TTAdConstant.INTERACTION_TYPE_BROWSER -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText(it.buttonText ?: "查看详情")
// }
// else -> {
// adCreativeButton?.visibility = View.GONE
// Log.i(TAG, "交互类型异常")
// }
// }
// }
// }
//
// private fun setDownLoadAppInfo(ttNativeAd: TTFeedAd, adViewHolder: AdViewHolder) {
// if (ttNativeAd.complianceInfo == null) {
// adViewHolder.app_info?.visibility = View.GONE
// } else {
// adViewHolder.app_info?.visibility = View.VISIBLE
// val appInfo = ttNativeAd.complianceInfo
// adViewHolder.app_name?.text = "应用名称:" + appInfo.appName
// adViewHolder.author_name?.text = "开发者:" + appInfo.developerName
// adViewHolder.package_size?.text = "包大小:不支持"
// adViewHolder.permissions_url?.text = "权限url:不支持"
// adViewHolder.privacy_agreement?.text = "隐私url:" + appInfo.privacyUrl
// adViewHolder.version_name?.text = "版本号:" + appInfo.appVersion
// adViewHolder.permissions_content!!.text =
// "权限内容:" + getPermissionsContent(appInfo.permissionsMap)
// }
// }
//
// private fun getPermissionsContent(permissionsMap: Map<String, String>?): String {
// if (permissionsMap == null) {
// return ""
// }
// val stringBuffer = StringBuffer()
// val keyList = permissionsMap.keys
// for (s in keyList) {
// stringBuffer.append(
// """$s : ${permissionsMap[s]} """
// )
// }
// return stringBuffer.toString()
// }
//
// 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
// }
//
// open private class AdViewHolder {
// var viewBinder: MediationViewBinder? = 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
// var app_info: LinearLayout? = null
// var app_name: TextView? = null
// var author_name: TextView? = null
// var package_size: TextView? = null
// var permissions_url: TextView? = null
// var privacy_agreement: TextView? = null
// var version_name: TextView? = null
// var permissions_content: TextView? = null
// }
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/draw/HomeDrawExpressManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.draw
import
android.net.Uri
import
android.text.TextUtils
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
com.bumptech.glide.Glide
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationExpressRenderListener
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationViewBinder
import
com.duben.heliapp.BuildConfig
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.ForegroundOrBackground
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.TimeRender
import
com.duben.heliapp.utils.UIUtils
import
java.lang.Exception
import
java.util.*
private
val
TAG
=
HomeDrawExpressManager
::
class
.
java
.
simpleName
/**
* 信息流
*/
class
HomeDrawExpressManager
{
companion
object
{
val
instance
:
HomeDrawExpressManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
HomeDrawExpressManager
()
}
}
private
var
adShowTime
:
Long
=
0
// 防止预加载超时 2秒
private
var
isShowAd
=
false
// 广告是否展示
private
var
expressId
:
String
=
""
private
var
isClickScreen
=
true
// 是否点击屏幕跳转广告
private
val
adLoadTime
:
Long
=
0
// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private
var
adPreingTime
:
Long
=
0
// 防止预加载超时 2分钟
private
var
isLoadSuccess
=
0
//0-加载失败/未加载 1-加载中 2-加载成功
private
var
mExpressAdCallback
:
ExpressAdCallback
?
=
null
private
var
viewCache
=
Stack
<
FrameLayout
>()
private
var
ttFeedAdCache
=
Stack
<
TTFeedAd
>()
// 载体
private
var
adcode
=
""
private
var
ecpm
=
""
private
var
adSource
=
""
// private var mTTFeedAd: TTFeedAd? = null
fun
getAdIsLoadSuc
():
Boolean
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
return
isLoadSuccess
==
2
&&
!
isOversped
}
fun
preLoadAd
()
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
val
isPreingOversped
=
TimeRender
.
isOverspedMin
(
adPreingTime
,
AdManager
.
AD_REQUEST_TIME_OUT
)
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if
((
isLoadSuccess
==
0
// 加载失败
||
adLoadTime
>
0
&&
isOversped
// 超过45分钟
||
adPreingTime
>
0
&&
isPreingOversped
&&
isLoadSuccess
==
1
)
// 预加载超时
)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 2、执行预加载去了=$isLoadSuccess"
)
adPreingTime
=
System
.
currentTimeMillis
()
isLoadSuccess
=
1
// 销毁及移除事件
loadAd
()
}
}
private
fun
loadAd
()
{
isClickScreen
=
true
expressId
=
BuildConfig
.
GROMORE_DRAW_CODE
val
activity
=
ForegroundOrBackground
.
getTopActivity
()
val
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
activity
)
val
adslot
=
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_DRAW_CODE
)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.
setImageAcceptedSize
(
UIUtils
.
getScreenWidth
(
MintsApplication
.
getContext
()),
UIUtils
.
getScreenHeight
(
MintsApplication
.
getContext
())
)
.
setMediationAdSlot
(
MediationAdSlot
.
Builder
()
.
setMuted
(
true
)
.
build
()
)
.
setAdCount
(
1
)
//请求广告数量为1到3条 (优先采用平台配置的数量)
.
build
()
adNativeLoader
.
loadDrawFeedAd
(
adslot
,
object
:
TTAdNative
.
DrawFeedAdListener
{
override
fun
onError
(
p0
:
Int
,
p1
:
String
?)
{
LogUtil
.
e
(
TAG
,
"gromore draw信息流--> 3、load feed ad error : $p0, $p1"
)
isLoadSuccess
=
0
}
override
fun
onDrawFeedAdLoad
(
ads
:
MutableList
<
TTDrawFeedAd
>?)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 3、Gromore onAdLoaded expressId=${expressId} "
)
ads
?.
let
{
if
(
it
.
isEmpty
())
{
isLoadSuccess
=
0
return
}
// mTTFeedAd = it[0]
showAd
(
it
[
0
])
}
}
})
}
private
fun
showAd
(
ttFeedAd
:
TTFeedAd
?)
{
ttFeedAd
?.
let
{
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
vo
[
"cpmFen"
]
=
ecpm
TrackManager
.
getInstance
().
cmtEcpm
(
vo
)
}
if
(
it
.
mediationManager
.
isExpress
)
{
//--------------信息流模板广告渲染----------------
showExpressView
(
it
)
}
else
{
//--------------信息流自渲染广告渲染----------------
// val view: View? = when (it.imageMode) {
// TTAdConstant.IMAGE_MODE_SMALL_IMG -> getSmallAdView(frameLayout)//信息流自渲染广告渲染 :小图广告
// TTAdConstant.IMAGE_MODE_LARGE_IMG -> getLargeAdView(frameLayout)//信息流自渲染广告渲染 :大图广告
// TTAdConstant.IMAGE_MODE_GROUP_IMG -> getGroupAdView(frameLayout)//信息流自渲染广告渲染 :组图广告
// TTAdConstant.IMAGE_MODE_VIDEO -> getVideoView(frameLayout)//信息流自渲染广告渲染 :视频广告
// TTAdConstant.IMAGE_MODE_VERTICAL_IMG -> getVerticalAdView(frameLayout)//信息流自渲染广告渲染 :竖图广告
// TTAdConstant.IMAGE_MODE_VIDEO_VERTICAL -> getVideoView(frameLayout)//信息流自渲染广告渲染 :竖版视频广告
// else -> {
// Log.i(TAG, "展示样式错误")
// null
// }
// }
// view?.let { it2 ->
// it2.layoutParams = ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT
// )
// frameLayout?.removeAllViews()
// frameLayout?.addView(it2)
// viewCache.add(frameLayout?.getChildAt(0))
// }
}
}
}
fun
getAdView
(
callback
:
ExpressAdCallback
?)
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
// 若上一个广告还在加载中则返回
if
(
isLoadSuccess
==
1
)
{
this
.
mExpressAdCallback
=
callback
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 3.9、广告加载中 LoadSuccess = $isLoadSuccess"
)
return
}
this
.
mExpressAdCallback
=
null
if
(
isLoadSuccess
==
2
&&
!
isOversped
)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
)
isShowAd
=
true
adShowTime
=
System
.
currentTimeMillis
()
isLoadSuccess
=
0
isClickScreen
=
true
// callback?.loadSuccess(frameLayout)
if
(
viewCache
.
size
>
0
)
{
callback
?.
loadSuccess
(
viewCache
.
lastElement
())
}
}
else
{
LogUtil
.
e
(
TAG
,
"gromore draw信息流--> 5、展示广告时失败了,广告可能超时45分钟 onError "
)
// 状态重置
isLoadSuccess
=
0
callback
?.
loadFail
()
}
}
private
fun
showExpressView
(
it
:
TTFeedAd
)
{
it
.
setExpressRenderListener
(
object
:
MediationExpressRenderListener
{
override
fun
onRenderSuccess
(
p0
:
View
?,
p1
:
Float
,
p2
:
Float
,
p3
:
Boolean
)
{
LogUtil
.
d
(
TAG
,
"gromore draw信息流--> 3、Gromore onRenderSuccess expressId=${expressId} "
)
Log
.
i
(
TAG
,
"onRenderSuccess"
)
isLoadSuccess
=
2
it
.
adView
?.
let
{
view
->
if
(
view
.
parent
!=
null
)
{
(
view
.
parent
as
ViewGroup
).
removeView
(
view
)
}
val
frameLayout
=
FrameLayout
(
MintsApplication
.
getContext
())
frameLayout
.
addView
(
view
)
viewCache
.
add
(
frameLayout
)
ttFeedAdCache
.
add
(
it
)
}
}
override
fun
onRenderFail
(
p0
:
View
?,
p1
:
String
?,
p2
:
Int
)
{
LogUtil
.
e
(
TAG
,
"gromore信息流--> 5、展示广告时失败了,onRenderFail msg=${p1} code=${p2} "
)
}
override
fun
onAdClick
()
{
LogUtil
.
d
(
TAG
,
"onAdClick"
)
}
override
fun
onAdShow
()
{
Log
.
i
(
TAG
,
"onAdShow"
)
Log
.
i
(
TAG
,
"ad mediaExtraInfo ${it.mediaExtraInfo}"
)
}
})
it
.
render
()
//必须要调用render方法进行渲染,在onRenderSuccess中处理模板的view
}
/**
* 销毁
*/
fun
destroy
()
{
// 数据重置
adcode
=
""
ecpm
=
""
adSource
=
""
for
(
frameLayout
in
viewCache
)
{
frameLayout
.
removeAllViews
()
}
viewCache
.
clear
()
for
(
ttFeedAd
in
ttFeedAdCache
)
{
ttFeedAd
.
destroy
()
}
ttFeedAdCache
.
clear
()
this
.
mExpressAdCallback
=
null
}
// private fun getSmallAdView(parent: ViewGroup?): View? {
// val convertView =
// 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
// 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
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView;
// }
//
// 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
// )
// 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView
// }
//
// 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
// )
// 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.mGroupImage1 =
// convertView.findViewById<View>(R.id.iv_listitem_image1) as ImageView
// adViewHolder.mGroupImage2 =
// convertView.findViewById<View>(R.id.iv_listitem_image2) as ImageView
// adViewHolder.mGroupImage3 =
// convertView.findViewById<View>(R.id.iv_listitem_image3) 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// adViewHolder.viewBinder = viewBinder
//
// bindData(convertView, adViewHolder)
// if (mTTFeedAd?.imageList?.size ?: 0 >= 3) {
// val image1: String? = mTTFeedAd?.imageList?.get(0)?.imageUrl
// val image2: String? = mTTFeedAd?.imageList?.get(1)?.imageUrl
// val image3: String? = mTTFeedAd?.imageList?.get(2)?.imageUrl
// if (image1 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image1)
// .into(adViewHolder.mGroupImage1!!)
// }
// if (image2 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image2)
// .into(adViewHolder.mGroupImage2!!)
// }
// if (image3 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image3)
// .into(adViewHolder.mGroupImage3!!)
// }
// }
// return convertView
// }
//
// private fun getVideoView(parent: ViewGroup?): View? {
// val adViewHolder = VideoAdViewHolder()
// var convertView: View? = null
// try {
// convertView = LayoutInflater.from(ForegroundOrBackground.getTopActivity())
// .inflate(
// R.layout.mediation_listitem_ad_large_video,
// parent,
// false
// )
// 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// adViewHolder.viewBinder = viewBinder
//
// // 如果自己有需求进行视频播放操作,则按如下步骤进行。注意:不是所有adn都支持,因此需要进行判空操作。
//// mTTFeedAd?.csjmAdInfo?.setUseCustomVideo(true) // 注意:要在registerView之前调用
// val videoUrl: String? = mTTFeedAd?.customVideo?.videoUrl // 注意:不是所有adn都支持,这里务必要进行判空操作
// if (!TextUtils.isEmpty(videoUrl)) {
// // 如果通过getVideoUrl返回的url不是空,则自己处理视频播放操作,并通过reporter上报视频状态
// playAdVideo(adViewHolder.videoView as FrameLayout, videoUrl ?: "")
// } else {
// // 注意:即使该adn支持返回url,但某次偶然原因返回的videoUrl为空,则仍然会用adn自己的视频播放作为兜底
// }
//
// //视频广告设置播放状态回调(可选)
// mTTFeedAd?.setVideoAdListener(object : TTFeedAd.VideoAdListener {
// override fun onVideoLoad(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoLoad")
// }
//
// override fun onVideoError(errorCode: Int, extraCode: Int) {
// Log.i(TAG, "onVideoError")
// }
//
// override fun onVideoAdStartPlay(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdStartPlay")
// }
//
// override fun onVideoAdPaused(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdPaused")
// }
//
// override fun onVideoAdContinuePlay(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdContinuePlay")
// }
//
// override fun onProgressUpdate(current: Long, duration: Long) {
// Log.i(TAG, "onProgressUpdate")
// }
//
// override fun onVideoAdComplete(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdComplete")
// }
//
// })
// mTTFeedAd?.setDownloadListener(object : TTAppDownloadListener {
// override fun onIdle() {
// Log.i(TAG, "setDownloadListener")
// }
//
// override fun onDownloadActive(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadActive")
// }
//
// override fun onDownloadPaused(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadPaused")
// }
//
// override fun onDownloadFailed(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadFailed")
// }
//
// override fun onDownloadFinished(
// totalBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadFinished")
// }
//
// override fun onInstalled(fileName: String?, appName: String?) {
// Log.i(TAG, "onInstalled")
// }
//
// })
// //绑定广告数据、设置交互回调
// bindData(convertView, adViewHolder)
// } catch (e: Exception) {
// e.printStackTrace()
// }
//
// return convertView
// }
//
// private var mVideoView: VideoView? = null
// private var customVideoReporter: TTFeedAd.CustomizeVideo? = null
//
// private fun playAdVideo(videoContainer: ViewGroup, videoUrl: String) {
// mVideoView = VideoView(MintsApplication.getContext())
// videoContainer.addView(mVideoView)
// customVideoReporter = mTTFeedAd?.customVideo
// // 开发者根据自己的需求,做相应的视频控制界面,播放暂停等
// mVideoView?.setVideoURI(Uri.parse(videoUrl))
// mVideoView?.setOnErrorListener { mp, what, extra ->
// if (customVideoReporter != null) {
// customVideoReporter?.reportVideoError(
// mVideoView!!.currentPosition.toLong(),
// what,
// extra
// )
// }
// false
// }
// mVideoView?.setOnCompletionListener {
// if (customVideoReporter != null) {
// customVideoReporter?.reportVideoFinish()
// }
// }
// mVideoView?.start()
// customVideoReporter?.reportVideoStart()
// }
//
// 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
// )
// 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.mVerticalImage =
// convertView.findViewById<ImageView>(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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView
// }
//
// private fun bindData(convertView: View, adViewHolder: AdViewHolder) {
// mTTFeedAd?.let {
// if (it.mediationManager?.hasDislike() == true) {
// val ttAdDislike: TTAdDislike =
// it.getDislikeDialog(ForegroundOrBackground.getTopActivity())
// adViewHolder.mDislike?.visibility = View.VISIBLE
// adViewHolder.mDislike?.setOnClickListener(View.OnClickListener {
// //使用接口来展示
// ttAdDislike.showDislikeDialog()
// ttAdDislike.setDislikeInteractionCallback(object :
// TTAdDislike.DislikeInteractionCallback {
// override fun onShow() {
// Log.i(TAG, "dislike 点击show")
// }
//
// override fun onSelected(position: Int, value: String?, enforce: Boolean) {
// Log.i(TAG, "点击 $value")
// //用户选择不喜欢原因后,移除广告展示
//// frameLayout?.removeAllViews()
// }
//
// override fun onCancel() {
// Log.i(TAG, "dislike 点击了取消")
// }
//
// })
// })
// } else {
// if (adViewHolder.mDislike != null) adViewHolder.mDislike?.visibility = View.GONE
// }
//
// setDownLoadAppInfo(it, adViewHolder)
//
// //可以被点击的view, 也可以把convertView放进来意味item可被点击
// val clickViewList: MutableList<View?> = ArrayList()
// clickViewList.add(convertView)
// clickViewList.add(adViewHolder.mSource)
// clickViewList.add(adViewHolder.mTitle)
// clickViewList.add(adViewHolder.mDescription)
// clickViewList.add(adViewHolder.mIcon)
//
// //添加点击区域
// if (adViewHolder is LargeAdViewHolder) {
// clickViewList.add(adViewHolder.mLargeImage)
// } else if (adViewHolder is SmallAdViewHolder) {
// clickViewList.add(adViewHolder.mSmallImage)
// } else if (adViewHolder is VerticalAdViewHolder) {
// clickViewList.add(adViewHolder.mVerticalImage)
// } else if (adViewHolder is VideoAdViewHolder) {
// clickViewList.add(adViewHolder.videoView)
// } else if (adViewHolder is GroupAdViewHolder) {
// clickViewList.add(adViewHolder.mGroupImage1)
// clickViewList.add(adViewHolder.mGroupImage2)
// clickViewList.add(adViewHolder.mGroupImage3)
// }
//
// //触发创意广告的view(点击下载或拨打电话)
// val creativeViewList: MutableList<View?> = ArrayList()
// 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")
// }
//
// override fun onAdCreativeClick(view: View?, ad: TTNativeAd?) {
// Log.i(TAG, "onAdCreativeClick")
// }
//
// override fun onAdShow(ad: TTNativeAd?) {
// Log.i(TAG, "onAdShow")
// ad?.let {
//// PrintUtil.printShowInfo(ad.mediationManager)
// }
// }
// },
// adViewHolder.viewBinder
// )
//
// adViewHolder.mTitle?.text = it.title //title为广告的简单信息提示
//
// adViewHolder.mDescription?.text = it.description //description为广告的较长的说明
//
// adViewHolder.mSource?.text =
// 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!!)
// }
// val adCreativeButton = adViewHolder.mCreativeButton
// when (it.interactionType) {
// TTAdConstant.INTERACTION_TYPE_DOWNLOAD -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText(it.buttonText ?: "立即下载")
// }
// TTAdConstant.INTERACTION_TYPE_DIAL -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText("立即拨打");
// }
// TTAdConstant.INTERACTION_TYPE_LANDING_PAGE,
// TTAdConstant.INTERACTION_TYPE_BROWSER -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText(it.buttonText ?: "查看详情")
// }
// else -> {
// adCreativeButton?.visibility = View.GONE
// Log.i(TAG, "交互类型异常")
// }
// }
// }
// }
//
// private fun setDownLoadAppInfo(ttNativeAd: TTFeedAd, adViewHolder: AdViewHolder) {
// if (ttNativeAd.complianceInfo == null) {
// adViewHolder.app_info?.visibility = View.GONE
// } else {
// adViewHolder.app_info?.visibility = View.VISIBLE
// val appInfo = ttNativeAd.complianceInfo
// adViewHolder.app_name?.text = "应用名称:" + appInfo.appName
// adViewHolder.author_name?.text = "开发者:" + appInfo.developerName
// adViewHolder.package_size?.text = "包大小:不支持"
// adViewHolder.permissions_url?.text = "权限url:不支持"
// adViewHolder.privacy_agreement?.text = "隐私url:" + appInfo.privacyUrl
// adViewHolder.version_name?.text = "版本号:" + appInfo.appVersion
// adViewHolder.permissions_content!!.text =
// "权限内容:" + getPermissionsContent(appInfo.permissionsMap)
// }
// }
//
// private fun getPermissionsContent(permissionsMap: Map<String, String>?): String {
// if (permissionsMap == null) {
// return ""
// }
// val stringBuffer = StringBuffer()
// val keyList = permissionsMap.keys
// for (s in keyList) {
// stringBuffer.append(
// """$s : ${permissionsMap[s]} """
// )
// }
// return stringBuffer.toString()
// }
//
// 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
// }
//
// open private class AdViewHolder {
// var viewBinder: MediationViewBinder? = 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
// var app_info: LinearLayout? = null
// var app_name: TextView? = null
// var author_name: TextView? = null
// var package_size: TextView? = null
// var permissions_url: TextView? = null
// var privacy_agreement: TextView? = null
// var version_name: TextView? = null
// var permissions_content: TextView? = null
// }
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/express/ExpressAdCallback.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.express
import
android.widget.FrameLayout
/**
*
* @des 信息流回调
*/
interface
ExpressAdCallback
{
fun
loadSuccess
(
adView
:
FrameLayout
?)
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
fun
loadFail
()
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/express/ExpressManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.express
import
android.net.Uri
import
android.text.TextUtils
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
com.bumptech.glide.Glide
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationExpressRenderListener
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationViewBinder
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.banner.BannerManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.ForegroundOrBackground
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.TimeRender
import
com.duben.heliapp.utils.UIUtils
import
java.lang.Exception
import
java.util.ArrayList
import
com.duben.heliapp.BuildConfig
/**
* 信息流
*/
class
ExpressManager
{
private
val
TAG
=
ExpressManager
::
class
.
java
.
simpleName
companion
object
{
val
instance
:
ExpressManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
ExpressManager
()
}
}
private
var
frameLayout
:
FrameLayout
?
=
null
private
val
adLoadTime
:
Long
=
0
// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private
var
adPreingTime
:
Long
=
0
// 防止预加载超时 2分钟
private
var
isLoadSuccess
=
0
//0-加载失败/未加载 1-加载中 2-加载成功
private
var
mExpressAdCallback
:
ExpressAdCallback
?
=
null
private
var
mTTFeedAd
:
TTFeedAd
?
=
null
fun
preLoadAd
()
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
val
isPreingOversped
=
TimeRender
.
isOverspedMin
(
adPreingTime
,
AdManager
.
AD_REQUEST_TIME_OUT
)
LogUtil
.
d
(
TAG
,
"gromore信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if
((
isLoadSuccess
==
0
// 加载失败
||
adLoadTime
>
0
&&
isOversped
// 超过45分钟
||
adPreingTime
>
0
&&
isPreingOversped
&&
isLoadSuccess
==
1
)
// 预加载超时
)
{
LogUtil
.
d
(
TAG
,
"gromore信息流--> 2、执行预加载去了=$isLoadSuccess"
)
adPreingTime
=
System
.
currentTimeMillis
()
isLoadSuccess
=
1
// 销毁及移除事件
// destroy()
this
.
frameLayout
=
FrameLayout
(
MintsApplication
.
getContext
())
loadAd
()
}
}
private
fun
loadAd
()
{
val
activity
=
ForegroundOrBackground
.
getTopActivity
()
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
()
adNativeLoader
.
loadFeedAd
(
adslot
,
object
:
TTAdNative
.
FeedAdListener
{
override
fun
onError
(
p0
:
Int
,
p1
:
String
?)
{
LogUtil
.
e
(
TAG
,
"gromore信息流--> 3、load feed ad error : $p0, $p1"
)
isLoadSuccess
=
0
}
override
fun
onFeedAdLoad
(
ads
:
MutableList
<
TTFeedAd
>?)
{
ads
?.
let
{
if
(
it
.
isEmpty
())
{
isLoadSuccess
=
0
return
}
if
(
it
.
size
>
0
)
{
mTTFeedAd
=
it
[
0
]
isLoadSuccess
=
2
showAd
()
}
}
}
})
}
private
fun
showAd
()
{
mTTFeedAd
?.
let
{
if
(
it
.
mediationManager
.
isExpress
)
{
//--------------信息流模板广告渲染----------------
showExpressView
(
it
)
}
else
{
//--------------信息流自渲染广告渲染----------------
val
view
:
View
?
=
when
(
it
.
imageMode
)
{
TTAdConstant
.
IMAGE_MODE_SMALL_IMG
->
getSmallAdView
(
frameLayout
)
//信息流自渲染广告渲染 :小图广告
TTAdConstant
.
IMAGE_MODE_LARGE_IMG
->
getLargeAdView
(
frameLayout
)
//信息流自渲染广告渲染 :大图广告
TTAdConstant
.
IMAGE_MODE_GROUP_IMG
->
getGroupAdView
(
frameLayout
)
//信息流自渲染广告渲染 :组图广告
TTAdConstant
.
IMAGE_MODE_VIDEO
->
getVideoView
(
frameLayout
)
//信息流自渲染广告渲染 :视频广告
TTAdConstant
.
IMAGE_MODE_VERTICAL_IMG
->
getVerticalAdView
(
frameLayout
)
//信息流自渲染广告渲染 :竖图广告
TTAdConstant
.
IMAGE_MODE_VIDEO_VERTICAL
->
getVideoView
(
frameLayout
)
//信息流自渲染广告渲染 :竖版视频广告
else
->
{
Log
.
i
(
TAG
,
"展示样式错误"
)
null
}
}
view
?.
let
{
it
.
layoutParams
=
ViewGroup
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
MATCH_PARENT
)
frameLayout
?.
removeAllViews
()
frameLayout
?.
addView
(
it
)
}
}
}
}
fun
getAdView
(
callback
:
ExpressAdCallback
?)
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
// 若上一个广告还在加载中则返回
if
(
isLoadSuccess
==
1
)
{
this
.
mExpressAdCallback
=
callback
LogUtil
.
d
(
TAG
,
"gromore信息流--> 3.9、广告加载中 LoadSuccess = $isLoadSuccess"
)
return
}
this
.
mExpressAdCallback
=
null
if
(
isLoadSuccess
==
2
&&
!
isOversped
)
{
LogUtil
.
d
(
TAG
,
"gromore信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
)
isLoadSuccess
=
0
callback
?.
loadSuccess
(
frameLayout
)
}
else
{
LogUtil
.
e
(
TAG
,
"gromore信息流--> 5、展示广告时失败了,广告可能超时45分钟 onError "
)
// 状态重置
isLoadSuccess
=
0
callback
?.
loadFail
()
}
}
private
fun
showExpressView
(
it
:
TTFeedAd
)
{
it
.
setExpressRenderListener
(
object
:
MediationExpressRenderListener
{
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 点击了取消"
)
}
})
it
.
adView
?.
let
{
view
->
if
(
view
.
parent
!=
null
)
{
(
view
.
parent
as
ViewGroup
).
removeView
(
view
)
}
frameLayout
?.
addView
(
view
)
}
mExpressAdCallback
?.
let
{
if
(
it
.
renderSuccess
(
frameLayout
))
{
isLoadSuccess
=
0
}
}
mExpressAdCallback
=
null
}
override
fun
onRenderFail
(
p0
:
View
?,
p1
:
String
?,
p2
:
Int
)
{
isLoadSuccess
=
0
LogUtil
.
e
(
TAG
,
"gromore信息流--> 5、展示广告时失败了,onRenderFail msg=${p1} code=${p2} "
)
}
override
fun
onAdClick
()
{
Log
.
i
(
TAG
,
"onAdClick"
)
}
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
)
}
}
})
it
.
render
()
//必须要调用render方法进行渲染,在onRenderSuccess中处理模板的view
}
/**
* 销毁
*/
fun
destroy
()
{
// frameLayout?.removeAllViews()
// frameLayout = null
mTTFeedAd
?.
destroy
()
this
.
mExpressAdCallback
=
null
}
fun
getFrameLayout
():
View
?
{
return
frameLayout
}
private
fun
getSmallAdView
(
parent
:
ViewGroup
?):
View
?
{
val
convertView
=
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
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
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
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
!!
)
}
}
}
return
convertView
;
}
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
)
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
<
RelativeLayout
>(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
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
!!
)
}
}
}
return
convertView
}
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
)
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
.
mGroupImage1
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image1
)
as
ImageView
adViewHolder
.
mGroupImage2
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image2
)
as
ImageView
adViewHolder
.
mGroupImage3
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image3
)
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
<
RelativeLayout
>(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
adViewHolder
.
viewBinder
=
viewBinder
bindData
(
convertView
,
adViewHolder
)
if
(
mTTFeedAd
?.
imageList
?.
size
?:
0
>=
3
)
{
val
image1
:
String
?
=
mTTFeedAd
?.
imageList
?.
get
(
0
)
?.
imageUrl
val
image2
:
String
?
=
mTTFeedAd
?.
imageList
?.
get
(
1
)
?.
imageUrl
val
image3
:
String
?
=
mTTFeedAd
?.
imageList
?.
get
(
2
)
?.
imageUrl
if
(
image1
!=
null
)
{
Glide
.
with
(
ForegroundOrBackground
.
getTopActivity
()).
load
(
image1
)
.
into
(
adViewHolder
.
mGroupImage1
!!
)
}
if
(
image2
!=
null
)
{
Glide
.
with
(
ForegroundOrBackground
.
getTopActivity
()).
load
(
image2
)
.
into
(
adViewHolder
.
mGroupImage2
!!
)
}
if
(
image3
!=
null
)
{
Glide
.
with
(
ForegroundOrBackground
.
getTopActivity
()).
load
(
image3
)
.
into
(
adViewHolder
.
mGroupImage3
!!
)
}
}
return
convertView
}
private
fun
getVideoView
(
parent
:
ViewGroup
?):
View
?
{
val
adViewHolder
=
VideoAdViewHolder
()
var
convertView
:
View
?
=
null
try
{
convertView
=
LayoutInflater
.
from
(
ForegroundOrBackground
.
getTopActivity
())
.
inflate
(
R
.
layout
.
mediation_listitem_ad_large_video
,
parent
,
false
)
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
<
RelativeLayout
>(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
adViewHolder
.
viewBinder
=
viewBinder
// 如果自己有需求进行视频播放操作,则按如下步骤进行。注意:不是所有adn都支持,因此需要进行判空操作。
// mTTFeedAd?.csjmAdInfo?.setUseCustomVideo(true) // 注意:要在registerView之前调用
val
videoUrl
:
String
?
=
mTTFeedAd
?.
customVideo
?.
videoUrl
// 注意:不是所有adn都支持,这里务必要进行判空操作
if
(!
TextUtils
.
isEmpty
(
videoUrl
))
{
// 如果通过getVideoUrl返回的url不是空,则自己处理视频播放操作,并通过reporter上报视频状态
playAdVideo
(
adViewHolder
.
videoView
as
FrameLayout
,
videoUrl
?:
""
)
}
else
{
// 注意:即使该adn支持返回url,但某次偶然原因返回的videoUrl为空,则仍然会用adn自己的视频播放作为兜底
}
//视频广告设置播放状态回调(可选)
mTTFeedAd
?.
setVideoAdListener
(
object
:
TTFeedAd
.
VideoAdListener
{
override
fun
onVideoLoad
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoLoad"
)
}
override
fun
onVideoError
(
errorCode
:
Int
,
extraCode
:
Int
)
{
Log
.
i
(
TAG
,
"onVideoError"
)
}
override
fun
onVideoAdStartPlay
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdStartPlay"
)
}
override
fun
onVideoAdPaused
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdPaused"
)
}
override
fun
onVideoAdContinuePlay
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdContinuePlay"
)
}
override
fun
onProgressUpdate
(
current
:
Long
,
duration
:
Long
)
{
Log
.
i
(
TAG
,
"onProgressUpdate"
)
}
override
fun
onVideoAdComplete
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdComplete"
)
}
})
mTTFeedAd
?.
setDownloadListener
(
object
:
TTAppDownloadListener
{
override
fun
onIdle
()
{
Log
.
i
(
TAG
,
"setDownloadListener"
)
}
override
fun
onDownloadActive
(
totalBytes
:
Long
,
currBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadActive"
)
}
override
fun
onDownloadPaused
(
totalBytes
:
Long
,
currBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadPaused"
)
}
override
fun
onDownloadFailed
(
totalBytes
:
Long
,
currBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadFailed"
)
}
override
fun
onDownloadFinished
(
totalBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadFinished"
)
}
override
fun
onInstalled
(
fileName
:
String
?,
appName
:
String
?)
{
Log
.
i
(
TAG
,
"onInstalled"
)
}
})
//绑定广告数据、设置交互回调
bindData
(
convertView
,
adViewHolder
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
convertView
}
private
var
mVideoView
:
VideoView
?
=
null
private
var
customVideoReporter
:
TTFeedAd
.
CustomizeVideo
?
=
null
private
fun
playAdVideo
(
videoContainer
:
ViewGroup
,
videoUrl
:
String
)
{
mVideoView
=
VideoView
(
MintsApplication
.
getContext
())
videoContainer
.
addView
(
mVideoView
)
customVideoReporter
=
mTTFeedAd
?.
customVideo
// 开发者根据自己的需求,做相应的视频控制界面,播放暂停等
mVideoView
?.
setVideoURI
(
Uri
.
parse
(
videoUrl
))
mVideoView
?.
setOnErrorListener
{
mp
,
what
,
extra
->
if
(
customVideoReporter
!=
null
)
{
customVideoReporter
?.
reportVideoError
(
mVideoView
!!
.
currentPosition
.
toLong
(),
what
,
extra
)
}
false
}
mVideoView
?.
setOnCompletionListener
{
if
(
customVideoReporter
!=
null
)
{
customVideoReporter
?.
reportVideoFinish
()
}
}
mVideoView
?.
start
()
customVideoReporter
?.
reportVideoStart
()
}
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
)
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
.
mVerticalImage
=
convertView
.
findViewById
<
ImageView
>(
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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
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
!!
)
}
}
}
return
convertView
}
private
fun
bindData
(
convertView
:
View
,
adViewHolder
:
AdViewHolder
)
{
mTTFeedAd
?.
let
{
if
(
it
.
mediationManager
?.
hasDislike
()
==
true
)
{
val
ttAdDislike
:
TTAdDislike
=
it
.
getDislikeDialog
(
ForegroundOrBackground
.
getTopActivity
())
adViewHolder
.
mDislike
?.
visibility
=
View
.
VISIBLE
adViewHolder
.
mDislike
?.
setOnClickListener
(
View
.
OnClickListener
{
//使用接口来展示
ttAdDislike
.
showDislikeDialog
()
ttAdDislike
.
setDislikeInteractionCallback
(
object
:
TTAdDislike
.
DislikeInteractionCallback
{
override
fun
onShow
()
{
Log
.
i
(
TAG
,
"dislike 点击show"
)
}
override
fun
onSelected
(
position
:
Int
,
value
:
String
?,
enforce
:
Boolean
)
{
Log
.
i
(
TAG
,
"点击 $value"
)
//用户选择不喜欢原因后,移除广告展示
frameLayout
?.
removeAllViews
()
}
override
fun
onCancel
()
{
Log
.
i
(
TAG
,
"dislike 点击了取消"
)
}
})
})
}
else
{
if
(
adViewHolder
.
mDislike
!=
null
)
adViewHolder
.
mDislike
?.
visibility
=
View
.
GONE
}
setDownLoadAppInfo
(
it
,
adViewHolder
)
//可以被点击的view, 也可以把convertView放进来意味item可被点击
val
clickViewList
:
MutableList
<
View
?>
=
ArrayList
()
clickViewList
.
add
(
convertView
)
clickViewList
.
add
(
adViewHolder
.
mSource
)
clickViewList
.
add
(
adViewHolder
.
mTitle
)
clickViewList
.
add
(
adViewHolder
.
mDescription
)
clickViewList
.
add
(
adViewHolder
.
mIcon
)
//添加点击区域
if
(
adViewHolder
is
LargeAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mLargeImage
)
}
else
if
(
adViewHolder
is
SmallAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mSmallImage
)
}
else
if
(
adViewHolder
is
VerticalAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mVerticalImage
)
}
else
if
(
adViewHolder
is
VideoAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
videoView
)
}
else
if
(
adViewHolder
is
GroupAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mGroupImage1
)
clickViewList
.
add
(
adViewHolder
.
mGroupImage2
)
clickViewList
.
add
(
adViewHolder
.
mGroupImage3
)
}
//触发创意广告的view(点击下载或拨打电话)
val
creativeViewList
:
MutableList
<
View
?>
=
ArrayList
()
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"
)
}
override
fun
onAdCreativeClick
(
view
:
View
?,
ad
:
TTNativeAd
?)
{
Log
.
i
(
TAG
,
"onAdCreativeClick"
)
}
override
fun
onAdShow
(
ad
:
TTNativeAd
?)
{
Log
.
i
(
TAG
,
"onAdShow"
)
ad
?.
let
{
// PrintUtil.printShowInfo(ad.mediationManager)
}
}
},
adViewHolder
.
viewBinder
)
adViewHolder
.
mTitle
?.
text
=
it
.
title
//title为广告的简单信息提示
adViewHolder
.
mDescription
?.
text
=
it
.
description
//description为广告的较长的说明
adViewHolder
.
mSource
?.
text
=
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
!!
)
}
val
adCreativeButton
=
adViewHolder
.
mCreativeButton
when
(
it
.
interactionType
)
{
TTAdConstant
.
INTERACTION_TYPE_DOWNLOAD
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
;
adCreativeButton
?.
setText
(
it
.
buttonText
?:
"立即下载"
)
}
TTAdConstant
.
INTERACTION_TYPE_DIAL
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
;
adCreativeButton
?.
setText
(
"立即拨打"
);
}
TTAdConstant
.
INTERACTION_TYPE_LANDING_PAGE
,
TTAdConstant
.
INTERACTION_TYPE_BROWSER
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
;
adCreativeButton
?.
setText
(
it
.
buttonText
?:
"查看详情"
)
}
else
->
{
adCreativeButton
?.
visibility
=
View
.
GONE
Log
.
i
(
TAG
,
"交互类型异常"
)
}
}
}
}
private
fun
setDownLoadAppInfo
(
ttNativeAd
:
TTFeedAd
,
adViewHolder
:
AdViewHolder
)
{
if
(
ttNativeAd
.
complianceInfo
==
null
)
{
adViewHolder
.
app_info
?.
visibility
=
View
.
GONE
}
else
{
adViewHolder
.
app_info
?.
visibility
=
View
.
VISIBLE
val
appInfo
=
ttNativeAd
.
complianceInfo
adViewHolder
.
app_name
?.
text
=
"应用名称:"
+
appInfo
.
appName
adViewHolder
.
author_name
?.
text
=
"开发者:"
+
appInfo
.
developerName
adViewHolder
.
package_size
?.
text
=
"包大小:不支持"
adViewHolder
.
permissions_url
?.
text
=
"权限url:不支持"
adViewHolder
.
privacy_agreement
?.
text
=
"隐私url:"
+
appInfo
.
privacyUrl
adViewHolder
.
version_name
?.
text
=
"版本号:"
+
appInfo
.
appVersion
adViewHolder
.
permissions_content
!!
.
text
=
"权限内容:"
+
getPermissionsContent
(
appInfo
.
permissionsMap
)
}
}
private
fun
getPermissionsContent
(
permissionsMap
:
Map
<
String
,
String
>?):
String
{
if
(
permissionsMap
==
null
)
{
return
""
}
val
stringBuffer
=
StringBuffer
()
val
keyList
=
permissionsMap
.
keys
for
(
s
in
keyList
)
{
stringBuffer
.
append
(
"""$s : ${permissionsMap[s]} """
)
}
return
stringBuffer
.
toString
()
}
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
}
open
private
class
AdViewHolder
{
var
viewBinder
:
MediationViewBinder
?
=
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
var
app_info
:
LinearLayout
?
=
null
var
app_name
:
TextView
?
=
null
var
author_name
:
TextView
?
=
null
var
package_size
:
TextView
?
=
null
var
permissions_url
:
TextView
?
=
null
var
privacy_agreement
:
TextView
?
=
null
var
version_name
:
TextView
?
=
null
var
permissions_content
:
TextView
?
=
null
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/express/MainExpressManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.express
import
android.util.Log
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationExpressRenderListener
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.ForegroundOrBackground
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.UIUtils
import
com.duben.heliapp.BuildConfig
private
val
TAG
=
MainExpressManager
::
class
.
java
.
simpleName
/**
* 信息流
*/
class
MainExpressManager
{
companion
object
{
val
instance
:
MainExpressManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
MainExpressManager
()
}
}
private
var
mTTFeedAdList
=
arrayListOf
<
TTFeedAd
>()
fun
loadAd
(
expressAdCallback
:
ExpressAdCallback
)
{
val
activity
=
ForegroundOrBackground
.
getTopActivity
()
val
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
activity
)
val
adslot
=
AdSlot
.
Builder
()
.
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
()
adNativeLoader
.
loadFeedAd
(
adslot
,
object
:
TTAdNative
.
FeedAdListener
{
override
fun
onError
(
p0
:
Int
,
p1
:
String
?)
{
LogUtil
.
e
(
TAG
,
"gromore首页信息流--> 3、load feed ad error : $p0, $p1"
)
}
override
fun
onFeedAdLoad
(
ads
:
MutableList
<
TTFeedAd
>?)
{
LogUtil
.
d
(
TAG
,
"gromore首页信息流--> 3、Gromore onAdLoaded"
)
ads
?.
let
{
if
(
it
.
isEmpty
())
{
return
}
for
(
ttFeedAd
in
it
)
{
mTTFeedAdList
.
add
(
ttFeedAd
)
showAd
(
ttFeedAd
,
expressAdCallback
)
}
}
}
})
}
private
fun
showAd
(
ttNativeAd
:
TTFeedAd
?,
expressAdCallback
:
ExpressAdCallback
)
{
ttNativeAd
?.
let
{
if
(
it
.
mediationManager
.
isExpress
)
{
//--------------信息流模板广告渲染----------------
showExpressView
(
it
,
expressAdCallback
)
}
else
{
//--------------信息流自渲染广告渲染----------------
// val view: View? = when (it.imageMode) {
// TTAdConstant.IMAGE_MODE_SMALL_IMG -> getSmallAdView(frameLayout)//信息流自渲染广告渲染 :小图广告
// TTAdConstant.IMAGE_MODE_LARGE_IMG -> getLargeAdView(frameLayout)//信息流自渲染广告渲染 :大图广告
// TTAdConstant.IMAGE_MODE_GROUP_IMG -> getGroupAdView(frameLayout)//信息流自渲染广告渲染 :组图广告
// TTAdConstant.IMAGE_MODE_VIDEO -> getVideoView(frameLayout)//信息流自渲染广告渲染 :视频广告
// TTAdConstant.IMAGE_MODE_VERTICAL_IMG -> getVerticalAdView(frameLayout)//信息流自渲染广告渲染 :竖图广告
// TTAdConstant.IMAGE_MODE_VIDEO_VERTICAL -> getVideoView(frameLayout)//信息流自渲染广告渲染 :竖版视频广告
// else -> {
// Log.i(TAG, "展示样式错误")
// null
// }
// }
// view?.let {
// it.layoutParams = ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT,
// ViewGroup.LayoutParams.MATCH_PARENT
// )
// frameLayout?.removeAllViews()
// frameLayout?.addView(it)
// }
}
}
}
private
fun
showExpressView
(
it
:
TTFeedAd
,
expressAdCallback
:
ExpressAdCallback
)
{
it
.
setExpressRenderListener
(
object
:
MediationExpressRenderListener
{
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 点击了取消"
)
}
})
it
.
adView
?.
let
{
view
->
if
(
view
.
parent
!=
null
)
{
(
view
.
parent
as
ViewGroup
).
removeView
(
view
)
}
val
frameLayout
=
FrameLayout
(
MintsApplication
.
getContext
())
frameLayout
.
addView
(
view
)
expressAdCallback
.
renderSuccess
(
frameLayout
)
}
}
override
fun
onRenderFail
(
p0
:
View
?,
p1
:
String
?,
p2
:
Int
)
{
LogUtil
.
e
(
TAG
,
"gromore首页信息流--> 5、展示广告时失败了,onRenderFail msg=${p1} code=${p2} "
)
}
override
fun
onAdClick
()
{
Log
.
i
(
TAG
,
"onAdClick"
)
}
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
)
}
}
})
it
.
render
()
//必须要调用render方法进行渲染,在onRenderSuccess中处理模板的view
}
/**
* 销毁
*/
fun
destroy
()
{
for
(
ttFeedAd
in
mTTFeedAdList
)
{
ttFeedAd
.
destroy
()
}
mTTFeedAdList
.
clear
()
}
// private fun getSmallAdView(parent: ViewGroup?): View? {
// val convertView =
// 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
// 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
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView;
// }
// 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
// )
// 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView
// }
// 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
// )
// 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.mGroupImage1 =
// convertView.findViewById<View>(R.id.iv_listitem_image1) as ImageView
// adViewHolder.mGroupImage2 =
// convertView.findViewById<View>(R.id.iv_listitem_image2) as ImageView
// adViewHolder.mGroupImage3 =
// convertView.findViewById<View>(R.id.iv_listitem_image3) 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// adViewHolder.viewBinder = viewBinder
//
// bindData(convertView, adViewHolder)
// if (mTTFeedAd?.imageList?.size ?: 0 >= 3) {
// val image1: String? = mTTFeedAd?.imageList?.get(0)?.imageUrl
// val image2: String? = mTTFeedAd?.imageList?.get(1)?.imageUrl
// val image3: String? = mTTFeedAd?.imageList?.get(2)?.imageUrl
// if (image1 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image1)
// .into(adViewHolder.mGroupImage1!!)
// }
// if (image2 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image2)
// .into(adViewHolder.mGroupImage2!!)
// }
// if (image3 != null) {
// Glide.with(ForegroundOrBackground.getTopActivity()).load(image3)
// .into(adViewHolder.mGroupImage3!!)
// }
// }
// return convertView
// }
// private fun getVideoView(parent: ViewGroup?): View? {
// val adViewHolder = VideoAdViewHolder()
// var convertView: View? = null
// try {
// convertView = LayoutInflater.from(ForegroundOrBackground.getTopActivity())
// .inflate(
// R.layout.mediation_listitem_ad_large_video,
// parent,
// false
// )
// 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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// adViewHolder.viewBinder = viewBinder
//
// // 如果自己有需求进行视频播放操作,则按如下步骤进行。注意:不是所有adn都支持,因此需要进行判空操作。
//// mTTFeedAd?.csjmAdInfo?.setUseCustomVideo(true) // 注意:要在registerView之前调用
// val videoUrl: String? = mTTFeedAd?.customVideo?.videoUrl // 注意:不是所有adn都支持,这里务必要进行判空操作
// if (!TextUtils.isEmpty(videoUrl)) {
// // 如果通过getVideoUrl返回的url不是空,则自己处理视频播放操作,并通过reporter上报视频状态
// playAdVideo(adViewHolder.videoView as FrameLayout, videoUrl ?: "")
// } else {
// // 注意:即使该adn支持返回url,但某次偶然原因返回的videoUrl为空,则仍然会用adn自己的视频播放作为兜底
// }
//
// //视频广告设置播放状态回调(可选)
// mTTFeedAd?.setVideoAdListener(object : TTFeedAd.VideoAdListener {
// override fun onVideoLoad(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoLoad")
// }
//
// override fun onVideoError(errorCode: Int, extraCode: Int) {
// Log.i(TAG, "onVideoError")
// }
//
// override fun onVideoAdStartPlay(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdStartPlay")
// }
//
// override fun onVideoAdPaused(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdPaused")
// }
//
// override fun onVideoAdContinuePlay(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdContinuePlay")
// }
//
// override fun onProgressUpdate(current: Long, duration: Long) {
// Log.i(TAG, "onProgressUpdate")
// }
//
// override fun onVideoAdComplete(ad: TTFeedAd?) {
// Log.i(TAG, "onVideoAdComplete")
// }
//
// })
// mTTFeedAd?.setDownloadListener(object : TTAppDownloadListener {
// override fun onIdle() {
// Log.i(TAG, "setDownloadListener")
// }
//
// override fun onDownloadActive(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadActive")
// }
//
// override fun onDownloadPaused(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadPaused")
// }
//
// override fun onDownloadFailed(
// totalBytes: Long,
// currBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadFailed")
// }
//
// override fun onDownloadFinished(
// totalBytes: Long,
// fileName: String?,
// appName: String?
// ) {
// Log.i(TAG, "onDownloadFinished")
// }
//
// override fun onInstalled(fileName: String?, appName: String?) {
// Log.i(TAG, "onInstalled")
// }
//
// })
// //绑定广告数据、设置交互回调
// bindData(convertView, adViewHolder)
// } catch (e: Exception) {
// e.printStackTrace()
// }
//
// return convertView
// }
// private var mVideoView: VideoView? = null
// private var customVideoReporter: TTFeedAd.CustomizeVideo? = null
// private fun playAdVideo(videoContainer: ViewGroup, videoUrl: String) {
// mVideoView = VideoView(MintsApplication.getContext())
// videoContainer.addView(mVideoView)
// customVideoReporter = mTTFeedAd?.customVideo
// // 开发者根据自己的需求,做相应的视频控制界面,播放暂停等
// mVideoView?.setVideoURI(Uri.parse(videoUrl))
// mVideoView?.setOnErrorListener { mp, what, extra ->
// if (customVideoReporter != null) {
// customVideoReporter?.reportVideoError(
// mVideoView!!.currentPosition.toLong(),
// what,
// extra
// )
// }
// false
// }
// mVideoView?.setOnCompletionListener {
// if (customVideoReporter != null) {
// customVideoReporter?.reportVideoFinish()
// }
// }
// mVideoView?.start()
// customVideoReporter?.reportVideoStart()
// }
// 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
// )
// 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.mVerticalImage =
// convertView.findViewById<ImageView>(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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
//
//
// adViewHolder.app_info =
// convertView.findViewById<LinearLayout>(R.id.app_info)
// adViewHolder.app_name =
// convertView.findViewById<TextView>(R.id.app_name)
// adViewHolder.author_name =
// convertView.findViewById<TextView>(R.id.author_name)
// adViewHolder.package_size =
// convertView.findViewById<TextView>(R.id.package_size)
// adViewHolder.permissions_url =
// convertView.findViewById<TextView>(R.id.permissions_url)
// adViewHolder.permissions_content =
// convertView.findViewById<TextView>(R.id.permissions_content)
// adViewHolder.privacy_agreement =
// convertView.findViewById<TextView>(R.id.privacy_agreement)
// adViewHolder.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()
// 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!!)
// }
// }
// }
// return convertView
// }
// private fun bindData(convertView: View, adViewHolder: AdViewHolder) {
// mTTFeedAd?.let {
// if (it.mediationManager?.hasDislike() == true) {
// val ttAdDislike: TTAdDislike =
// it.getDislikeDialog(ForegroundOrBackground.getTopActivity())
// adViewHolder.mDislike?.visibility = View.VISIBLE
// adViewHolder.mDislike?.setOnClickListener(View.OnClickListener {
// //使用接口来展示
// ttAdDislike.showDislikeDialog()
// ttAdDislike.setDislikeInteractionCallback(object :
// TTAdDislike.DislikeInteractionCallback {
// override fun onShow() {
// Log.i(TAG, "dislike 点击show")
// }
//
// override fun onSelected(position: Int, value: String?, enforce: Boolean) {
// Log.i(TAG, "点击 $value")
// //用户选择不喜欢原因后,移除广告展示
//// frameLayout?.removeAllViews()
// }
//
// override fun onCancel() {
// Log.i(TAG, "dislike 点击了取消")
// }
//
// })
// })
// } else {
// if (adViewHolder.mDislike != null) adViewHolder.mDislike?.visibility = View.GONE
// }
//
// setDownLoadAppInfo(it, adViewHolder)
//
// //可以被点击的view, 也可以把convertView放进来意味item可被点击
// val clickViewList: MutableList<View?> = ArrayList()
// clickViewList.add(convertView)
// clickViewList.add(adViewHolder.mSource)
// clickViewList.add(adViewHolder.mTitle)
// clickViewList.add(adViewHolder.mDescription)
// clickViewList.add(adViewHolder.mIcon)
//
// //添加点击区域
// if (adViewHolder is LargeAdViewHolder) {
// clickViewList.add(adViewHolder.mLargeImage)
// } else if (adViewHolder is SmallAdViewHolder) {
// clickViewList.add(adViewHolder.mSmallImage)
// } else if (adViewHolder is VerticalAdViewHolder) {
// clickViewList.add(adViewHolder.mVerticalImage)
// } else if (adViewHolder is VideoAdViewHolder) {
// clickViewList.add(adViewHolder.videoView)
// } else if (adViewHolder is GroupAdViewHolder) {
// clickViewList.add(adViewHolder.mGroupImage1)
// clickViewList.add(adViewHolder.mGroupImage2)
// clickViewList.add(adViewHolder.mGroupImage3)
// }
//
// //触发创意广告的view(点击下载或拨打电话)
// val creativeViewList: MutableList<View?> = ArrayList()
// 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")
// }
//
// override fun onAdCreativeClick(view: View?, ad: TTNativeAd?) {
// Log.i(TAG, "onAdCreativeClick")
// }
//
// override fun onAdShow(ad: TTNativeAd?) {
// Log.i(TAG, "onAdShow")
// ad?.let {
//// PrintUtil.printShowInfo(ad.mediationManager)
// }
// }
// },
// adViewHolder.viewBinder
// )
//
// adViewHolder.mTitle?.text = it.title //title为广告的简单信息提示
//
// adViewHolder.mDescription?.text = it.description //description为广告的较长的说明
//
// adViewHolder.mSource?.text =
// 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!!)
// }
// val adCreativeButton = adViewHolder.mCreativeButton
// when (it.interactionType) {
// TTAdConstant.INTERACTION_TYPE_DOWNLOAD -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText(it.buttonText ?: "立即下载")
// }
// TTAdConstant.INTERACTION_TYPE_DIAL -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText("立即拨打");
// }
// TTAdConstant.INTERACTION_TYPE_LANDING_PAGE,
// TTAdConstant.INTERACTION_TYPE_BROWSER -> {
// adCreativeButton?.visibility = View.VISIBLE;
// adCreativeButton?.setText(it.buttonText ?: "查看详情")
// }
// else -> {
// adCreativeButton?.visibility = View.GONE
// Log.i(TAG, "交互类型异常")
// }
// }
// }
// }
// private fun setDownLoadAppInfo(ttNativeAd: TTFeedAd, adViewHolder: AdViewHolder) {
// if (ttNativeAd.complianceInfo == null) {
// adViewHolder.app_info?.visibility = View.GONE
// } else {
// adViewHolder.app_info?.visibility = View.VISIBLE
// val appInfo = ttNativeAd.complianceInfo
// adViewHolder.app_name?.text = "应用名称:" + appInfo.appName
// adViewHolder.author_name?.text = "开发者:" + appInfo.developerName
// adViewHolder.package_size?.text = "包大小:不支持"
// adViewHolder.permissions_url?.text = "权限url:不支持"
// adViewHolder.privacy_agreement?.text = "隐私url:" + appInfo.privacyUrl
// adViewHolder.version_name?.text = "版本号:" + appInfo.appVersion
// adViewHolder.permissions_content!!.text =
// "权限内容:" + getPermissionsContent(appInfo.permissionsMap)
// }
// }
//
// private fun getPermissionsContent(permissionsMap: Map<String, String>?): String {
// if (permissionsMap == null) {
// return ""
// }
// val stringBuffer = StringBuffer()
// val keyList = permissionsMap.keys
// for (s in keyList) {
// stringBuffer.append(
// """$s : ${permissionsMap[s]} """
// )
// }
// return stringBuffer.toString()
// }
//
// 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
// }
//
// open private class AdViewHolder {
// var viewBinder: MediationViewBinder? = 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
// var app_info: LinearLayout? = null
// var app_name: TextView? = null
// var author_name: TextView? = null
// var package_size: TextView? = null
// var permissions_url: TextView? = null
// var privacy_agreement: TextView? = null
// var version_name: TextView? = null
// var permissions_content: TextView? = null
// }
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/express/MyExpressManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.express
import
android.net.Uri
import
android.text.TextUtils
import
android.util.Log
import
android.view.LayoutInflater
import
android.view.View
import
android.view.ViewGroup
import
android.widget.*
import
com.bumptech.glide.Glide
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationExpressRenderListener
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationViewBinder
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.ForegroundOrBackground
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.TimeRender
import
com.duben.heliapp.utils.UIUtils
import
java.lang.Exception
import
java.util.ArrayList
import
com.duben.heliapp.BuildConfig
/**
* 信息流
*/
class
MyExpressManager
{
private
val
TAG
=
MyExpressManager
::
class
.
java
.
simpleName
companion
object
{
val
instance
:
MyExpressManager
by
lazy
(
mode
=
LazyThreadSafetyMode
.
SYNCHRONIZED
)
{
MyExpressManager
()
}
}
private
var
frameLayout
:
FrameLayout
?
=
null
private
val
adLoadTime
:
Long
=
0
// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private
var
adPreingTime
:
Long
=
0
// 防止预加载超时 2分钟
private
var
isLoadSuccess
=
0
//0-加载失败/未加载 1-加载中 2-加载成功
private
var
mExpressAdCallback
:
ExpressAdCallback
?
=
null
private
var
mTTFeedAd
:
TTFeedAd
?
=
null
fun
preLoadAd
()
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
val
isPreingOversped
=
TimeRender
.
isOverspedMin
(
adPreingTime
,
AdManager
.
AD_REQUEST_TIME_OUT
)
LogUtil
.
d
(
TAG
,
"gromore我的信息流--> 1、进入预加载 isLoadSuccess=$isLoadSuccess isOversped=$isOversped isPreingOversped=$isPreingOversped"
)
if
((
isLoadSuccess
==
0
// 加载失败
||
adLoadTime
>
0
&&
isOversped
// 超过45分钟
||
adPreingTime
>
0
&&
isPreingOversped
&&
isLoadSuccess
==
1
)
// 预加载超时
)
{
LogUtil
.
d
(
TAG
,
"gromore我的信息流--> 2、执行预加载去了=$isLoadSuccess"
)
adPreingTime
=
System
.
currentTimeMillis
()
isLoadSuccess
=
1
// 销毁及移除事件
// destroy()
this
.
frameLayout
=
FrameLayout
(
MintsApplication
.
getContext
())
loadAd
()
}
}
private
fun
loadAd
()
{
val
activity
=
ForegroundOrBackground
.
getTopActivity
()
val
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
activity
)
val
adslot
=
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_MY_EXPRESS_CODE
)
/**
* 注:
* 1:单位为px
* 2:如果是信息流自渲染广告,设置广告图片期望的图片宽高 ,不能为0
* 2:如果是信息流模板广告,宽度设置为希望的宽度,高度设置为0(0为高度选择自适应参数)
*/
.
setImageAcceptedSize
(
UIUtils
.
getScreenWidth
(
activity
),
UIUtils
.
dp2px
(
activity
,
340f
))
// .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
?)
{
LogUtil
.
e
(
TAG
,
"gromore我的信息流--> 3、load feed ad error : $p0, $p1"
)
isLoadSuccess
=
0
}
override
fun
onFeedAdLoad
(
ads
:
MutableList
<
TTFeedAd
>?)
{
ads
?.
let
{
if
(
it
.
isEmpty
())
{
isLoadSuccess
=
0
return
}
if
(
it
.
size
>
0
)
{
mTTFeedAd
=
it
[
0
]
isLoadSuccess
=
2
showAd
()
}
}
}
})
}
private
fun
showAd
()
{
mTTFeedAd
?.
let
{
if
(
it
.
mediationManager
.
isExpress
)
{
//--------------信息流模板广告渲染----------------
showExpressView
(
it
)
}
else
{
//--------------信息流自渲染广告渲染----------------
val
view
:
View
?
=
when
(
it
.
imageMode
)
{
TTAdConstant
.
IMAGE_MODE_SMALL_IMG
->
getSmallAdView
(
frameLayout
)
//信息流自渲染广告渲染 :小图广告
TTAdConstant
.
IMAGE_MODE_LARGE_IMG
->
getLargeAdView
(
frameLayout
)
//信息流自渲染广告渲染 :大图广告
TTAdConstant
.
IMAGE_MODE_GROUP_IMG
->
getGroupAdView
(
frameLayout
)
//信息流自渲染广告渲染 :组图广告
TTAdConstant
.
IMAGE_MODE_VIDEO
->
getVideoView
(
frameLayout
)
//信息流自渲染广告渲染 :视频广告
TTAdConstant
.
IMAGE_MODE_VERTICAL_IMG
->
getVerticalAdView
(
frameLayout
)
//信息流自渲染广告渲染 :竖图广告
TTAdConstant
.
IMAGE_MODE_VIDEO_VERTICAL
->
getVideoView
(
frameLayout
)
//信息流自渲染广告渲染 :竖版视频广告
else
->
{
Log
.
i
(
TAG
,
"展示样式错误"
)
null
}
}
view
?.
let
{
it
.
layoutParams
=
ViewGroup
.
LayoutParams
(
ViewGroup
.
LayoutParams
.
MATCH_PARENT
,
ViewGroup
.
LayoutParams
.
MATCH_PARENT
)
frameLayout
?.
removeAllViews
()
frameLayout
?.
addView
(
it
)
}
}
}
}
fun
getAdView
(
callback
:
ExpressAdCallback
?)
{
val
isOversped
=
TimeRender
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
)
// 若上一个广告还在加载中则返回
if
(
isLoadSuccess
==
1
)
{
this
.
mExpressAdCallback
=
callback
LogUtil
.
d
(
TAG
,
"gromore我的信息流--> 3.9、广告加载中 LoadSuccess = $isLoadSuccess"
)
return
}
this
.
mExpressAdCallback
=
null
if
(
isLoadSuccess
==
2
&&
!
isOversped
)
{
LogUtil
.
d
(
TAG
,
"gromore我的信息流--> 4、展示广告 LoadSuccess=$isLoadSuccess isOversped=$isOversped"
)
isLoadSuccess
=
0
callback
?.
loadSuccess
(
frameLayout
)
}
else
{
LogUtil
.
e
(
TAG
,
"gromore我的信息流--> 5、展示广告时失败了,广告可能超时45分钟 onError "
)
// 状态重置
isLoadSuccess
=
0
callback
?.
loadFail
()
}
}
private
fun
showExpressView
(
it
:
TTFeedAd
)
{
it
.
setExpressRenderListener
(
object
:
MediationExpressRenderListener
{
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 点击了取消"
)
}
})
it
.
adView
?.
let
{
view
->
if
(
view
.
parent
!=
null
)
{
(
view
.
parent
as
ViewGroup
).
removeView
(
view
)
}
frameLayout
?.
addView
(
view
)
}
mExpressAdCallback
?.
let
{
if
(
it
.
renderSuccess
(
frameLayout
))
{
isLoadSuccess
=
0
}
}
mExpressAdCallback
=
null
}
override
fun
onRenderFail
(
p0
:
View
?,
p1
:
String
?,
p2
:
Int
)
{
isLoadSuccess
=
0
LogUtil
.
e
(
TAG
,
"gromore我的信息流--> 5、展示广告时失败了,onRenderFail msg=${p1} code=${p2} "
)
}
override
fun
onAdClick
()
{
Log
.
i
(
TAG
,
"onAdClick"
)
}
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
)
}
}
})
it
.
render
()
//必须要调用render方法进行渲染,在onRenderSuccess中处理模板的view
}
/**
* 销毁
*/
fun
destroy
()
{
// frameLayout?.removeAllViews()
// frameLayout = null
mTTFeedAd
?.
destroy
()
this
.
mExpressAdCallback
=
null
}
fun
getFrameLayout
():
View
?
{
return
frameLayout
}
private
fun
getSmallAdView
(
parent
:
ViewGroup
?):
View
?
{
val
convertView
=
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
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
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
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
!!
)
}
}
}
return
convertView
;
}
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
)
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
<
RelativeLayout
>(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
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
!!
)
}
}
}
return
convertView
}
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
)
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
.
mGroupImage1
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image1
)
as
ImageView
adViewHolder
.
mGroupImage2
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image2
)
as
ImageView
adViewHolder
.
mGroupImage3
=
convertView
.
findViewById
<
View
>(
R
.
id
.
iv_listitem_image3
)
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
<
RelativeLayout
>(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
adViewHolder
.
viewBinder
=
viewBinder
bindData
(
convertView
,
adViewHolder
)
if
(
mTTFeedAd
?.
imageList
?.
size
?:
0
>=
3
)
{
val
image1
:
String
?
=
mTTFeedAd
?.
imageList
?.
get
(
0
)
?.
imageUrl
val
image2
:
String
?
=
mTTFeedAd
?.
imageList
?.
get
(
1
)
?.
imageUrl
val
image3
:
String
?
=
mTTFeedAd
?.
imageList
?.
get
(
2
)
?.
imageUrl
if
(
image1
!=
null
)
{
Glide
.
with
(
ForegroundOrBackground
.
getTopActivity
()).
load
(
image1
)
.
into
(
adViewHolder
.
mGroupImage1
!!
)
}
if
(
image2
!=
null
)
{
Glide
.
with
(
ForegroundOrBackground
.
getTopActivity
()).
load
(
image2
)
.
into
(
adViewHolder
.
mGroupImage2
!!
)
}
if
(
image3
!=
null
)
{
Glide
.
with
(
ForegroundOrBackground
.
getTopActivity
()).
load
(
image3
)
.
into
(
adViewHolder
.
mGroupImage3
!!
)
}
}
return
convertView
}
private
fun
getVideoView
(
parent
:
ViewGroup
?):
View
?
{
val
adViewHolder
=
VideoAdViewHolder
()
var
convertView
:
View
?
=
null
try
{
convertView
=
LayoutInflater
.
from
(
ForegroundOrBackground
.
getTopActivity
())
.
inflate
(
R
.
layout
.
mediation_listitem_ad_large_video
,
parent
,
false
)
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
<
RelativeLayout
>(
R
.
id
.
tt_ad_logo
)
//logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
adViewHolder
.
viewBinder
=
viewBinder
// 如果自己有需求进行视频播放操作,则按如下步骤进行。注意:不是所有adn都支持,因此需要进行判空操作。
// mTTFeedAd?.csjmAdInfo?.setUseCustomVideo(true) // 注意:要在registerView之前调用
val
videoUrl
:
String
?
=
mTTFeedAd
?.
customVideo
?.
videoUrl
// 注意:不是所有adn都支持,这里务必要进行判空操作
if
(!
TextUtils
.
isEmpty
(
videoUrl
))
{
// 如果通过getVideoUrl返回的url不是空,则自己处理视频播放操作,并通过reporter上报视频状态
playAdVideo
(
adViewHolder
.
videoView
as
FrameLayout
,
videoUrl
?:
""
)
}
else
{
// 注意:即使该adn支持返回url,但某次偶然原因返回的videoUrl为空,则仍然会用adn自己的视频播放作为兜底
}
//视频广告设置播放状态回调(可选)
mTTFeedAd
?.
setVideoAdListener
(
object
:
TTFeedAd
.
VideoAdListener
{
override
fun
onVideoLoad
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoLoad"
)
}
override
fun
onVideoError
(
errorCode
:
Int
,
extraCode
:
Int
)
{
Log
.
i
(
TAG
,
"onVideoError"
)
}
override
fun
onVideoAdStartPlay
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdStartPlay"
)
}
override
fun
onVideoAdPaused
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdPaused"
)
}
override
fun
onVideoAdContinuePlay
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdContinuePlay"
)
}
override
fun
onProgressUpdate
(
current
:
Long
,
duration
:
Long
)
{
Log
.
i
(
TAG
,
"onProgressUpdate"
)
}
override
fun
onVideoAdComplete
(
ad
:
TTFeedAd
?)
{
Log
.
i
(
TAG
,
"onVideoAdComplete"
)
}
})
mTTFeedAd
?.
setDownloadListener
(
object
:
TTAppDownloadListener
{
override
fun
onIdle
()
{
Log
.
i
(
TAG
,
"setDownloadListener"
)
}
override
fun
onDownloadActive
(
totalBytes
:
Long
,
currBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadActive"
)
}
override
fun
onDownloadPaused
(
totalBytes
:
Long
,
currBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadPaused"
)
}
override
fun
onDownloadFailed
(
totalBytes
:
Long
,
currBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadFailed"
)
}
override
fun
onDownloadFinished
(
totalBytes
:
Long
,
fileName
:
String
?,
appName
:
String
?
)
{
Log
.
i
(
TAG
,
"onDownloadFinished"
)
}
override
fun
onInstalled
(
fileName
:
String
?,
appName
:
String
?)
{
Log
.
i
(
TAG
,
"onInstalled"
)
}
})
//绑定广告数据、设置交互回调
bindData
(
convertView
,
adViewHolder
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
convertView
}
private
var
mVideoView
:
VideoView
?
=
null
private
var
customVideoReporter
:
TTFeedAd
.
CustomizeVideo
?
=
null
private
fun
playAdVideo
(
videoContainer
:
ViewGroup
,
videoUrl
:
String
)
{
mVideoView
=
VideoView
(
MintsApplication
.
getContext
())
videoContainer
.
addView
(
mVideoView
)
customVideoReporter
=
mTTFeedAd
?.
customVideo
// 开发者根据自己的需求,做相应的视频控制界面,播放暂停等
mVideoView
?.
setVideoURI
(
Uri
.
parse
(
videoUrl
))
mVideoView
?.
setOnErrorListener
{
mp
,
what
,
extra
->
if
(
customVideoReporter
!=
null
)
{
customVideoReporter
?.
reportVideoError
(
mVideoView
!!
.
currentPosition
.
toLong
(),
what
,
extra
)
}
false
}
mVideoView
?.
setOnCompletionListener
{
if
(
customVideoReporter
!=
null
)
{
customVideoReporter
?.
reportVideoFinish
()
}
}
mVideoView
?.
start
()
customVideoReporter
?.
reportVideoStart
()
}
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
)
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
.
mVerticalImage
=
convertView
.
findViewById
<
ImageView
>(
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<RelativeLayout>(R.id.tt_ad_logo) //logoView 建议传入GroupView类型
adViewHolder
.
app_info
=
convertView
.
findViewById
<
LinearLayout
>(
R
.
id
.
app_info
)
adViewHolder
.
app_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
app_name
)
adViewHolder
.
author_name
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
author_name
)
adViewHolder
.
package_size
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
package_size
)
adViewHolder
.
permissions_url
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_url
)
adViewHolder
.
permissions_content
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
permissions_content
)
adViewHolder
.
privacy_agreement
=
convertView
.
findViewById
<
TextView
>(
R
.
id
.
privacy_agreement
)
adViewHolder
.
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
()
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
!!
)
}
}
}
return
convertView
}
private
fun
bindData
(
convertView
:
View
,
adViewHolder
:
AdViewHolder
)
{
mTTFeedAd
?.
let
{
if
(
it
.
mediationManager
?.
hasDislike
()
==
true
)
{
val
ttAdDislike
:
TTAdDislike
=
it
.
getDislikeDialog
(
ForegroundOrBackground
.
getTopActivity
())
adViewHolder
.
mDislike
?.
visibility
=
View
.
VISIBLE
adViewHolder
.
mDislike
?.
setOnClickListener
(
View
.
OnClickListener
{
//使用接口来展示
ttAdDislike
.
showDislikeDialog
()
ttAdDislike
.
setDislikeInteractionCallback
(
object
:
TTAdDislike
.
DislikeInteractionCallback
{
override
fun
onShow
()
{
Log
.
i
(
TAG
,
"dislike 点击show"
)
}
override
fun
onSelected
(
position
:
Int
,
value
:
String
?,
enforce
:
Boolean
)
{
Log
.
i
(
TAG
,
"点击 $value"
)
//用户选择不喜欢原因后,移除广告展示
frameLayout
?.
removeAllViews
()
}
override
fun
onCancel
()
{
Log
.
i
(
TAG
,
"dislike 点击了取消"
)
}
})
})
}
else
{
if
(
adViewHolder
.
mDislike
!=
null
)
adViewHolder
.
mDislike
?.
visibility
=
View
.
GONE
}
setDownLoadAppInfo
(
it
,
adViewHolder
)
//可以被点击的view, 也可以把convertView放进来意味item可被点击
val
clickViewList
:
MutableList
<
View
?>
=
ArrayList
()
clickViewList
.
add
(
convertView
)
clickViewList
.
add
(
adViewHolder
.
mSource
)
clickViewList
.
add
(
adViewHolder
.
mTitle
)
clickViewList
.
add
(
adViewHolder
.
mDescription
)
clickViewList
.
add
(
adViewHolder
.
mIcon
)
//添加点击区域
if
(
adViewHolder
is
LargeAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mLargeImage
)
}
else
if
(
adViewHolder
is
SmallAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mSmallImage
)
}
else
if
(
adViewHolder
is
VerticalAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mVerticalImage
)
}
else
if
(
adViewHolder
is
VideoAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
videoView
)
}
else
if
(
adViewHolder
is
GroupAdViewHolder
)
{
clickViewList
.
add
(
adViewHolder
.
mGroupImage1
)
clickViewList
.
add
(
adViewHolder
.
mGroupImage2
)
clickViewList
.
add
(
adViewHolder
.
mGroupImage3
)
}
//触发创意广告的view(点击下载或拨打电话)
val
creativeViewList
:
MutableList
<
View
?>
=
ArrayList
()
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"
)
}
override
fun
onAdCreativeClick
(
view
:
View
?,
ad
:
TTNativeAd
?)
{
Log
.
i
(
TAG
,
"onAdCreativeClick"
)
}
override
fun
onAdShow
(
ad
:
TTNativeAd
?)
{
Log
.
i
(
TAG
,
"onAdShow"
)
ad
?.
let
{
// PrintUtil.printShowInfo(ad.mediationManager)
}
}
},
adViewHolder
.
viewBinder
)
adViewHolder
.
mTitle
?.
text
=
it
.
title
//title为广告的简单信息提示
adViewHolder
.
mDescription
?.
text
=
it
.
description
//description为广告的较长的说明
adViewHolder
.
mSource
?.
text
=
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
!!
)
}
val
adCreativeButton
=
adViewHolder
.
mCreativeButton
when
(
it
.
interactionType
)
{
TTAdConstant
.
INTERACTION_TYPE_DOWNLOAD
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
;
adCreativeButton
?.
setText
(
it
.
buttonText
?:
"立即下载"
)
}
TTAdConstant
.
INTERACTION_TYPE_DIAL
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
;
adCreativeButton
?.
setText
(
"立即拨打"
);
}
TTAdConstant
.
INTERACTION_TYPE_LANDING_PAGE
,
TTAdConstant
.
INTERACTION_TYPE_BROWSER
->
{
adCreativeButton
?.
visibility
=
View
.
VISIBLE
;
adCreativeButton
?.
setText
(
it
.
buttonText
?:
"查看详情"
)
}
else
->
{
adCreativeButton
?.
visibility
=
View
.
GONE
Log
.
i
(
TAG
,
"交互类型异常"
)
}
}
}
}
private
fun
setDownLoadAppInfo
(
ttNativeAd
:
TTFeedAd
,
adViewHolder
:
AdViewHolder
)
{
if
(
ttNativeAd
.
complianceInfo
==
null
)
{
adViewHolder
.
app_info
?.
visibility
=
View
.
GONE
}
else
{
adViewHolder
.
app_info
?.
visibility
=
View
.
VISIBLE
val
appInfo
=
ttNativeAd
.
complianceInfo
adViewHolder
.
app_name
?.
text
=
"应用名称:"
+
appInfo
.
appName
adViewHolder
.
author_name
?.
text
=
"开发者:"
+
appInfo
.
developerName
adViewHolder
.
package_size
?.
text
=
"包大小:不支持"
adViewHolder
.
permissions_url
?.
text
=
"权限url:不支持"
adViewHolder
.
privacy_agreement
?.
text
=
"隐私url:"
+
appInfo
.
privacyUrl
adViewHolder
.
version_name
?.
text
=
"版本号:"
+
appInfo
.
appVersion
adViewHolder
.
permissions_content
!!
.
text
=
"权限内容:"
+
getPermissionsContent
(
appInfo
.
permissionsMap
)
}
}
private
fun
getPermissionsContent
(
permissionsMap
:
Map
<
String
,
String
>?):
String
{
if
(
permissionsMap
==
null
)
{
return
""
}
val
stringBuffer
=
StringBuffer
()
val
keyList
=
permissionsMap
.
keys
for
(
s
in
keyList
)
{
stringBuffer
.
append
(
"""$s : ${permissionsMap[s]} """
)
}
return
stringBuffer
.
toString
()
}
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
}
open
private
class
AdViewHolder
{
var
viewBinder
:
MediationViewBinder
?
=
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
var
app_info
:
LinearLayout
?
=
null
var
app_name
:
TextView
?
=
null
var
author_name
:
TextView
?
=
null
var
package_size
:
TextView
?
=
null
var
permissions_url
:
TextView
?
=
null
var
privacy_agreement
:
TextView
?
=
null
var
version_name
:
TextView
?
=
null
var
permissions_content
:
TextView
?
=
null
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/splash/SplashManager.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ad.splash
import
android.app.Activity
import
android.view.View
import
android.widget.FrameLayout
import
com.bytedance.sdk.openadsdk.*
import
com.bytedance.sdk.openadsdk.mediation.MediationConstant
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationSplashRequestInfo
import
com.duben.heliapp.BuildConfig
import
com.duben.heliapp.MintsApplication
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.utils.LogUtil
import
com.duben.heliapp.utils.UIUtils
import
java.lang.ref.WeakReference
/**
* 应用内-网赚开屏
*/
object
SplashManager
{
// 兜底配置
val
pangleSplashBottom
=
object
:
MediationSplashRequestInfo
(
MediationConstant
.
ADN_PANGLE
,
"889457860"
,
BuildConfig
.
GROMORE_APP_ID
,
""
)
{}
//ok
private
val
TAG
=
SplashManager
::
class
.
java
.
simpleName
private
var
mTTSplashAd
:
CSJSplashAd
?
=
null
private
const
val
AD_TIME_OUT
=
5000
//开屏广告加载超时时间
private
var
isLoadSuccess
=
0
//0-加载失败/未加载 1-加载中 2-加载成功
private
var
isShowAd
=
false
// 是否显示广告
private
var
adStatusListener
:
AdStatusListener
?
=
null
/**
* 预加载开屏广告
*/
fun
preLoadAd
(
activity
:
Activity
)
{
val
weakActivity
=
WeakReference
<
Activity
>(
activity
)
LogUtil
.
d
(
TAG
,
"gromore 开屏广告-> 1、进入预加载"
)
if
(
isLoadSuccess
==
1
)
{
return
}
val
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
weakActivity
.
get
())
val
adslot
=
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_SPLASH_CODE
)
.
setImageAcceptedSize
(
UIUtils
.
getScreenWidth
(
MintsApplication
.
getContext
()),
UIUtils
.
getScreenHeight
(
MintsApplication
.
getContext
())
)
.
setMediationAdSlot
(
MediationAdSlot
.
Builder
()
.
setMediationSplashRequestInfo
(
pangleSplashBottom
)
.
build
()
)
.
build
()
adNativeLoader
.
loadSplashAd
(
adslot
,
object
:
TTAdNative
.
CSJSplashAdListener
{
override
fun
onSplashLoadSuccess
(
p0
:
CSJSplashAd
?)
{
}
override
fun
onSplashLoadFail
(
p0
:
CSJAdError
?)
{
LogUtil
.
e
(
TAG
,
"gromore 开屏广告--> 3、Gromore onSplashLoadFail adErrorCode=${p0?.code} "
)
isLoadSuccess
=
0
}
override
fun
onSplashRenderSuccess
(
p0
:
CSJSplashAd
?)
{
LogUtil
.
d
(
TAG
,
"gromore 开屏广告--> 3、Gromore onSplashAdLoadSuccess"
)
LogUtil
.
d
(
"SplashNewActivity-->"
,
"333333--> ad show"
)
isLoadSuccess
=
2
mTTSplashAd
=
p0
}
override
fun
onSplashRenderFail
(
p0
:
CSJSplashAd
?,
p1
:
CSJAdError
?)
{
LogUtil
.
e
(
TAG
,
"gromore 开屏广告--> 3、Gromore onSplashRenderFail adErrorCode=${p1?.code} "
)
isLoadSuccess
=
0
}
},
AD_TIME_OUT
)
}
/**
* 展示开屏广告
*/
fun
showAd
(
activity
:
Activity
,
view
:
FrameLayout
,
adStatusListener
:
AdStatusListener
?)
{
this
.
adStatusListener
=
adStatusListener
isShowAd
=
false
if
(
mTTSplashAd
!=
null
&&
isLoadSuccess
==
2
)
{
LogUtil
.
d
(
TAG
,
"gromore 开屏广告--> 准备调用show"
)
mTTSplashAd
?.
let
{
it
.
setSplashAdListener
(
adInteractionListener
)
view
.
addView
(
it
.
splashView
)
}
}
else
{
LogUtil
.
d
(
TAG
,
"gromore 开屏广告--> 准备调用show 失败 mTTSplashAd=${mTTSplashAd} isLoadSuccess=${isLoadSuccess}"
)
adStatusListener
?.
adFail
()
}
// 状态重置
isLoadSuccess
=
0
}
/**
* 广告是否加载成功
*/
fun
isSuccessStatus
()
=
isLoadSuccess
==
2
val
adInteractionListener
=
object
:
CSJSplashAd
.
SplashAdListener
{
override
fun
onSplashAdShow
(
p0
:
CSJSplashAd
?)
{
isShowAd
=
true
LogUtil
.
d
(
TAG
,
"gromore 开屏广告--> 6、onAdShow "
)
mTTSplashAd
?.
let
{
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
TrackManager
.
getInstance
().
cmtEcpm
(
vo
)
}
}
}
override
fun
onSplashAdClick
(
p0
:
CSJSplashAd
?)
{
LogUtil
.
d
(
TAG
,
"gromore 开屏广告--> 7、onAdDismiss "
)
// adStatusListener?.adClose(null)
}
override
fun
onSplashAdClose
(
p0
:
CSJSplashAd
?,
p1
:
Int
)
{
LogUtil
.
d
(
TAG
,
"gromore 开屏广告--> 7、onAdDismiss "
)
adStatusListener
?.
adClose
(
null
)
}
}
/**
* 是否展示广告
*/
fun
getAdStatus
()
=
isShowAd
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ad/video/InMoneyVideo.java
deleted
100644 → 0
View file @
9185435e
package
com
.
duben
.
heliapp
.
ad
.
video
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
com.bytedance.sdk.openadsdk.AdSlot
;
import
com.bytedance.sdk.openadsdk.TTAdConstant
;
import
com.bytedance.sdk.openadsdk.TTAdNative
;
import
com.bytedance.sdk.openadsdk.TTAdSdk
;
import
com.bytedance.sdk.openadsdk.TTRewardVideoAd
;
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
;
import
com.duben.heliapp.BuildConfig
;
import
com.duben.heliapp.ad.AdManager
;
import
com.duben.heliapp.ad.AdStatusListener
;
import
com.duben.heliapp.common.Constant
;
import
com.duben.heliapp.manager.TrackManager
;
import
com.duben.heliapp.utils.AppPreferencesManager
;
import
com.duben.heliapp.utils.LogUtil
;
import
com.duben.heliapp.utils.TimeRender
;
import
java.lang.ref.WeakReference
;
import
java.util.HashMap
;
/**
* GroMore激励视频广告
* <p>
* 注意*****这个类有预加载逻辑,不能复用
*/
public
class
InMoneyVideo
{
private
static
final
String
TAG
=
InMoneyVideo
.
class
.
getSimpleName
();
private
static
InMoneyVideo
_inst
;
public
static
InMoneyVideo
getInstance
()
{
if
(
_inst
==
null
)
{
_inst
=
new
InMoneyVideo
();
}
return
_inst
;
}
private
InMoneyVideo
()
{
}
private
String
carrierType
=
""
;
// 当前播放的广告
private
String
nowAdcode
=
""
;
private
String
nowEcpm
=
""
;
private
String
nowAdSource
=
""
;
private
int
isLoadSuccess
=
0
;
// 0-加载失败/未加载 1-加载中 2-加载成功
private
long
adLoadTime
=
0
;
// 广告展示时间,45分钟后当前广告失效,重新预加载广告
private
long
adPreingTime
=
0
;
// 防止预加载超时 2分钟
private
TTRewardVideoAd
mttRewardAd
;
private
WeakReference
<
Activity
>
weakActivity
;
private
boolean
isPreLoad
=
false
;
//是否是预加载调用,需要躲避监听
private
AdStatusListener
adStatusListener
;
/**
* 激励视频
*/
public
void
preLoadAd
(
Activity
activity
,
boolean
isPreLoad
)
{
this
.
isPreLoad
=
isPreLoad
;
boolean
isOversped
=
TimeRender
.
INSTANCE
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
);
boolean
isPreingOversped
=
TimeRender
.
INSTANCE
.
isOverspedMin
(
adPreingTime
,
AdManager
.
AD_REQUEST_TIME_OUT
);
this
.
weakActivity
=
new
WeakReference
(
activity
);
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告-> 1、进入预加载 isPreLoad[为true是预加载调用]="
+
isPreLoad
);
if
((
isLoadSuccess
==
0
// 加载失败
||
(
adLoadTime
>
0
&&
isOversped
)
// 超过45分钟
||
(
adPreingTime
>
0
&&
isPreingOversped
&&
isLoadSuccess
==
1
))
// 预加载超时
&&
this
.
weakActivity
.
get
()
!=
null
)
{
adPreingTime
=
System
.
currentTimeMillis
();
isLoadSuccess
=
1
;
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告-> 2、执行预加载去了="
+
isLoadSuccess
);
preLoadAd
(
activity
);
}
}
public
void
showRewardAd
(
Activity
_activity
,
AdStatusListener
adStatusListener
,
String
carrier
)
{
this
.
carrierType
=
carrier
;
this
.
adStatusListener
=
adStatusListener
;
this
.
weakActivity
=
new
WeakReference
(
_activity
);
if
(
isLoadSuccess
==
0
)
{
LogUtil
.
e
(
TAG
,
"gromore预加载 激励视频广告--> showRewardAd isLoadSuccess="
+
isLoadSuccess
);
if
(
this
.
adStatusListener
!=
null
)
this
.
adStatusListener
.
adFail
();
return
;
}
// 请求未超过1分钟且上一个广告还在异步加载中,这次触发展示广告回调还没回来则返回
boolean
isPreingOversped
=
TimeRender
.
INSTANCE
.
isOverspedMin
(
adPreingTime
,
AdManager
.
AD_REQUEST_TIME_OUT
);
if
(
isLoadSuccess
==
1
&&
isPreingOversped
)
{
LogUtil
.
e
(
TAG
,
"gromore预加载 激励视频广告-->请求未超过1分钟且上一个广告还在异步加载中 isLoadSuccess="
+
isLoadSuccess
+
" isPreingOversped="
+
isPreingOversped
);
if
(
this
.
adStatusListener
!=
null
)
this
.
adStatusListener
.
adFail
();
return
;
}
// 预加载广告成功 且 预加载广告时长未超过45分钟
boolean
isOversped
=
TimeRender
.
INSTANCE
.
isOverspedMin
(
adLoadTime
,
AdManager
.
AD_NO_SHOWTIME_OUT
);
if
(
isLoadSuccess
==
2
&&
!
isOversped
&&
mttRewardAd
!=
null
&&
mttRewardAd
.
getMediationManager
().
isReady
()
&&
this
.
weakActivity
.
get
()
!=
null
)
{
mttRewardAd
.
showRewardVideoAd
(
weakActivity
.
get
());
mttRewardAd
.
setRewardAdInteractionListener
(
mTTRewardedAdListener
);
}
else
{
if
(
this
.
adStatusListener
!=
null
)
this
.
adStatusListener
.
adFail
();
LogUtil
.
e
(
TAG
,
"gromore预加载 激励视频广告--> 5、展示广告时失败了,广告可能超时45分钟 onError "
);
}
// 广告加载完成状态重置
isLoadSuccess
=
0
;
}
private
void
preLoadAd
(
Activity
activity
)
{
TTAdNative
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
activity
);
AdSlot
adSlot
=
new
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_VIDEO_CODE
)
.
setUserID
(
""
)
.
setOrientation
(
TTAdConstant
.
VERTICAL
)
.
setMediationAdSlot
(
new
MediationAdSlot
.
Builder
()
.
setRewardAmount
(
2000
)
.
setRewardName
(
""
)
.
build
()
).
build
();
adNativeLoader
.
loadRewardVideoAd
(
adSlot
,
new
TTAdNative
.
RewardVideoAdListener
()
{
@Override
public
void
onError
(
int
i
,
String
s
)
{
isLoadSuccess
=
0
;
LogUtil
.
e
(
TAG
,
"gromore预加载 激励视频广告-->onError "
+
i
+
s
+
"isPreLoad[为true是预加载调用]="
+
isPreLoad
);
// isPreLoad=true 表示是预加载调用 不需要调用监听回调
if
(!
isPreLoad
)
{
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adFail
();
}
}
isPreLoad
=
false
;
}
@Override
public
void
onRewardVideoAdLoad
(
TTRewardVideoAd
ttRewardVideoAd
)
{
}
@Override
public
void
onRewardVideoCached
()
{
}
@Override
public
void
onRewardVideoCached
(
TTRewardVideoAd
ttRewardVideoAd
)
{
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告--> 4、onRewardVideoCached "
);
isLoadSuccess
=
2
;
adLoadTime
=
System
.
currentTimeMillis
();
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adSuccess
();
}
mttRewardAd
=
ttRewardVideoAd
;
}
});
}
private
final
TTRewardVideoAd
.
RewardAdInteractionListener
mTTRewardedAdListener
=
new
TTRewardVideoAd
.
RewardAdInteractionListener
()
{
@Override
public
void
onAdShow
()
{
if
(
mttRewardAd
!=
null
)
{
if
(
mttRewardAd
.
getMediationManager
()
!=
null
&&
mttRewardAd
.
getMediationManager
().
getShowEcpm
()
!=
null
)
{
nowAdcode
=
mttRewardAd
.
getMediationManager
().
getShowEcpm
().
getSlotId
();
nowEcpm
=
mttRewardAd
.
getMediationManager
().
getShowEcpm
().
getEcpm
();
nowAdSource
=
mttRewardAd
.
getMediationManager
().
getShowEcpm
().
getSdkName
();
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"adType"
,
Constant
.
GRO_MORE_ADTYPE2
);
vo
.
put
(
"ecpm"
,
nowEcpm
);
TrackManager
.
getInstance
().
cmtEcpm
(
vo
);
}
}
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告-->onAdShow"
);
if
(
weakActivity
.
get
()
!=
null
)
{
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告->onAdShow 触发预加载下次广告"
);
AdManager
.
Companion
.
getInstance
().
preLoadAd
(
weakActivity
.
get
(),
true
);
}
}
@Override
public
void
onAdVideoBarClick
()
{
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告-->onAdVideoBarClick"
);
}
@Override
public
void
onAdClose
()
{
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告-->onAdClose"
);
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"adcode"
,
nowAdcode
);
vo
.
put
(
"ecpm"
,
nowEcpm
);
vo
.
put
(
"adSource"
,
nowAdSource
);
vo
.
put
(
"carrierType"
,
carrierType
);
vo
.
put
(
"adid"
,
BuildConfig
.
GROMORE_VIDEO_CODE
);
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adClose
(
vo
);
}
adStatusListener
=
null
;
}
@Override
public
void
onVideoComplete
()
{
LogUtil
.
d
(
TAG
,
"gromore预加载 激励视频广告-->onVideoComplete"
);
}
@Override
public
void
onVideoError
()
{
isLoadSuccess
=
0
;
LogUtil
.
e
(
TAG
,
"gromore预加载 激励视频广告-->onVideoError"
);
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adFail
();
}
}
@Override
public
void
onRewardVerify
(
boolean
b
,
int
i
,
String
s
,
int
i1
,
String
s1
)
{
}
@Override
public
void
onRewardArrived
(
boolean
b
,
int
i
,
Bundle
bundle
)
{
}
@Override
public
void
onSkippedVideo
()
{
}
};
}
video/app/src/main/java/com/duben/heliapp/ad/video/InMoneyVideoNoPre.java
deleted
100644 → 0
View file @
9185435e
package
com
.
duben
.
heliapp
.
ad
.
video
;
import
android.app.Activity
;
import
android.os.Bundle
;
import
com.bytedance.sdk.openadsdk.AdSlot
;
import
com.bytedance.sdk.openadsdk.TTAdConstant
;
import
com.bytedance.sdk.openadsdk.TTAdNative
;
import
com.bytedance.sdk.openadsdk.TTAdSdk
;
import
com.bytedance.sdk.openadsdk.TTRewardVideoAd
;
import
com.bytedance.sdk.openadsdk.mediation.ad.MediationAdSlot
;
import
com.duben.heliapp.BuildConfig
;
import
com.duben.heliapp.ad.AdManager
;
import
com.duben.heliapp.ad.AdStatusListener
;
import
com.duben.heliapp.common.Constant
;
import
com.duben.heliapp.manager.TrackManager
;
import
com.duben.heliapp.utils.AppPreferencesManager
;
import
com.duben.heliapp.utils.LogUtil
;
import
java.lang.ref.WeakReference
;
import
java.util.HashMap
;
/**
* **实时加载
* <p>
* 应用内-GroMore激励视频广告
*/
public
class
InMoneyVideoNoPre
{
private
static
final
String
TAG
=
InMoneyVideoNoPre
.
class
.
getSimpleName
();
private
static
InMoneyVideoNoPre
_inst
;
public
static
InMoneyVideoNoPre
getInstance
()
{
if
(
_inst
==
null
)
{
_inst
=
new
InMoneyVideoNoPre
();
}
return
_inst
;
}
private
InMoneyVideoNoPre
()
{
}
private
String
carrierType
=
""
;
// 当前播放的广告
private
String
nowAdcode
=
""
;
private
String
nowEcpm
=
""
;
private
String
nowAdSource
=
""
;
private
TTRewardVideoAd
mttRewardAd
;
private
WeakReference
<
Activity
>
weakActivity
;
private
AdStatusListener
adStatusListener
;
/**
* 激励视频
*/
public
void
loadAd
(
Activity
_activity
,
AdStatusListener
adStatusListener
,
String
carrier
)
{
this
.
carrierType
=
carrier
;
this
.
adStatusListener
=
adStatusListener
;
this
.
weakActivity
=
new
WeakReference
(
_activity
);
preLoadAd
(
_activity
);
}
private
void
preLoadAd
(
Activity
activity
)
{
TTAdNative
adNativeLoader
=
TTAdSdk
.
getAdManager
().
createAdNative
(
activity
);
AdSlot
adSlot
=
new
AdSlot
.
Builder
()
.
setCodeId
(
BuildConfig
.
GROMORE_VIDEO_CODE
)
.
setUserID
(
""
)
.
setOrientation
(
TTAdConstant
.
VERTICAL
)
.
setMediationAdSlot
(
new
MediationAdSlot
.
Builder
()
.
setRewardAmount
(
2000
)
.
setRewardName
(
""
)
.
build
()
).
build
();
adNativeLoader
.
loadRewardVideoAd
(
adSlot
,
new
TTAdNative
.
RewardVideoAdListener
()
{
@Override
public
void
onError
(
int
i
,
String
s
)
{
LogUtil
.
e
(
TAG
,
"gromore实时加载 激励视频广告-->onError "
+
i
+
s
);
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adFail
();
}
}
@Override
public
void
onRewardVideoAdLoad
(
TTRewardVideoAd
ttRewardVideoAd
)
{
}
@Override
public
void
onRewardVideoCached
()
{
}
@Override
public
void
onRewardVideoCached
(
TTRewardVideoAd
ttRewardVideoAd
)
{
LogUtil
.
d
(
TAG
,
"gromore实时加载 激励视频广告--> 4、onRewardVideoCached"
);
mttRewardAd
=
ttRewardVideoAd
;
if
(
mttRewardAd
!=
null
&&
weakActivity
!=
null
&&
mttRewardAd
.
getMediationManager
().
isReady
())
{
mttRewardAd
.
setRewardAdInteractionListener
(
mTTRewardedAdListener
);
mttRewardAd
.
showRewardVideoAd
(
weakActivity
.
get
());
}
else
{
LogUtil
.
e
(
TAG
,
"gromore实时加载 onRewardVideoCached onError "
);
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adFail
();
}
}
}
});
}
private
final
TTRewardVideoAd
.
RewardAdInteractionListener
mTTRewardedAdListener
=
new
TTRewardVideoAd
.
RewardAdInteractionListener
()
{
@Override
public
void
onAdShow
()
{
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adSuccess
();
}
if
(
mttRewardAd
!=
null
)
{
if
(
mttRewardAd
.
getMediationManager
()
!=
null
&&
mttRewardAd
.
getMediationManager
().
getShowEcpm
()
!=
null
)
{
nowAdcode
=
mttRewardAd
.
getMediationManager
().
getShowEcpm
().
getSlotId
();
nowEcpm
=
mttRewardAd
.
getMediationManager
().
getShowEcpm
().
getEcpm
();
nowAdSource
=
mttRewardAd
.
getMediationManager
().
getShowEcpm
().
getSdkName
();
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"adType"
,
Constant
.
GRO_MORE_ADTYPE2
);
vo
.
put
(
"ecpm"
,
nowEcpm
);
TrackManager
.
getInstance
().
cmtEcpm
(
vo
);
}
}
LogUtil
.
d
(
TAG
,
"gromore实时加载 激励视频广告-->onAdShow"
);
// 预加载
if
(
weakActivity
.
get
()
!=
null
)
{
LogUtil
.
d
(
TAG
,
"gromore实时加载 激励视频广告->onAdShow 触发预加载下次广告"
);
AdManager
.
Companion
.
getInstance
().
preLoadAd
(
weakActivity
.
get
(),
true
);
}
}
@Override
public
void
onAdVideoBarClick
()
{
}
@Override
public
void
onAdClose
()
{
LogUtil
.
d
(
TAG
,
"gromore实时加载 激励视频广告-->onAdClose nowAdcode="
+
nowAdcode
);
HashMap
<
String
,
Object
>
vo
=
new
HashMap
<>();
vo
.
put
(
"adcode"
,
nowAdcode
);
vo
.
put
(
"ecpm"
,
nowEcpm
);
vo
.
put
(
"adSource"
,
nowAdSource
);
vo
.
put
(
"carrierType"
,
carrierType
);
vo
.
put
(
"adid"
,
BuildConfig
.
GROMORE_VIDEO_CODE
);
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adClose
(
vo
);
}
adStatusListener
=
null
;
}
@Override
public
void
onVideoComplete
()
{
LogUtil
.
d
(
TAG
,
"gromore实时加载 激励视频广告-->onVideoComplete"
);
}
@Override
public
void
onVideoError
()
{
if
(
adStatusListener
!=
null
)
{
adStatusListener
.
adFail
();
}
LogUtil
.
e
(
TAG
,
"gromore实时加载 激励视频广告-->onVideoError"
);
}
@Override
public
void
onRewardVerify
(
boolean
b
,
int
i
,
String
s
,
int
i1
,
String
s1
)
{
}
@Override
public
void
onRewardArrived
(
boolean
b
,
int
i
,
Bundle
bundle
)
{
}
@Override
public
void
onSkippedVideo
()
{
}
};
}
video/app/src/main/java/com/duben/heliapp/manager/LocalVedioManager.kt
View file @
3b5ddb43
...
...
@@ -4,7 +4,6 @@ import android.app.Activity
import
android.content.Intent
import
android.os.Bundle
import
android.text.TextUtils
import
com.duben.heliapp.ad.express.ExpressManager
import
com.duben.library.utils.json.JsonUtil
import
com.duben.heliapp.common.AppConfig
import
com.duben.heliapp.common.Constant
...
...
@@ -113,9 +112,6 @@ object LocalVedioManager {
readyGo
(
activity
,
NewTxVideoActivity
::
class
.
java
,
bundle
)
}
if
(!
UserManager
.
getInstance
().
vipFlag
)
{
ExpressManager
.
instance
.
preLoadAd
()
}
}
fun
readyGo
(
activity
:
Activity
,
clazz
:
Class
<
*
>,
bundle
:
Bundle
)
{
...
...
video/app/src/main/java/com/duben/heliapp/ui/activitys/NineActivity.kt
View file @
3b5ddb43
...
...
@@ -9,9 +9,6 @@ import android.view.View
import
com.daimajia.androidanimations.library.Techniques
import
com.daimajia.androidanimations.library.YoYo
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.ad.NoPreAdManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.mvp.model.NineListBean
import
com.duben.heliapp.mvp.model.NineShowBean
...
...
@@ -192,43 +189,6 @@ class NineActivity : BaseActivity(), View.OnClickListener, NineView {
carrierType
=
Constant
.
CARRIERTYPE_NINE3
}
}
AdManager
.
instance
.
showAd
(
this
,
carrierType
,
object
:
AdStatusListener
{
var
canFail
=
false
override
fun
adSuccess
()
{
canFail
=
true
}
override
fun
adFail
()
{
if
(
canFail
)
return
NoPreAdManager
.
loadVideoAd
(
this
@NineActivity
,
carrierType
,
object
:
AdStatusListener
{
override
fun
adFail
()
{
carrierType
=
Constant
.
CARRIERTYPE_NINE
showToast
(
"广告太火爆了,请稍候再试"
)
}
override
fun
adSuccess
()
{
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
vo
?.
let
{
ninePresenter
.
unlock
(
vo
)
}
}
})
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
vo
?.
let
{
ninePresenter
.
unlock
(
vo
)
}
}
})
}
fun
startNine
(
data
:
NineListBean
.
NineBean
)
{
...
...
video/app/src/main/java/com/duben/heliapp/ui/activitys/SplashActivity.kt
View file @
3b5ddb43
...
...
@@ -2,18 +2,13 @@ package com.duben.heliapp.ui.activitys
import
android.annotation.SuppressLint
import
android.os.Bundle
import
android.text.TextUtils
import
android.view.KeyEvent
import
android.view.View
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.splash.SplashManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.common.Constant.PRIVACY_URL
import
com.duben.heliapp.common.Constant.REGISTER_URL
import
com.duben.heliapp.manager.LocalVedioManager
import
com.duben.heliapp.manager.TrackManager
import
com.duben.heliapp.manager.UserManager
import
com.duben.heliapp.ui.activitys.base.BaseActivity
import
com.duben.heliapp.ui.widgets.CycleProgress
import
com.duben.heliapp.ui.widgets.DialogListener
...
...
@@ -21,7 +16,6 @@ import com.duben.heliapp.ui.widgets.PowerDialog
import
com.duben.heliapp.ui.widgets.PowerDialog2
import
com.duben.heliapp.ui.widgets.countdowntimer.CountDownTimerSupport
import
com.duben.heliapp.ui.widgets.countdowntimer.OnCountDownTimerListener
import
com.duben.heliapp.utils.AppPreferencesManager
import
com.duben.heliapp.utils.AppPreferencesManager.get
import
com.duben.heliapp.utils.LogUtil
import
java.util.*
...
...
@@ -36,7 +30,7 @@ class SplashActivity : BaseActivity() {
var
powerDialog
:
PowerDialog
?
=
null
var
powerDialog2
:
PowerDialog2
?
=
null
private
var
mProgressBar
:
CycleProgress
?
=
null
private
val
AD_TIME_OUT
=
5
000
private
val
AD_TIME_OUT
=
2
000
var
timer
:
CountDownTimerSupport
?
=
null
private
var
isAdSuc
=
false
...
...
@@ -74,10 +68,6 @@ class SplashActivity : BaseActivity() {
// TrackManager.getInstance().firstShowVedio()
// }
val
firstSplash
=
get
().
getBoolean
(
Constant
.
FIRST_SPLASH
,
true
)
if
(!
firstSplash
)
{
SplashManager
.
preLoadAd
(
this
@SplashActivity
)
}
mProgressBar
!!
.
startOneAnim
()
try
{
startTimer
()
...
...
@@ -99,22 +89,12 @@ class SplashActivity : BaseActivity() {
val
firstSplash
=
get
().
getBoolean
(
Constant
.
FIRST_SPLASH
,
true
)
if
(
firstSplash
&&
millisUntilFinished
==
(
AD_TIME_OUT
-
1000
).
toLong
())
{
LogUtil
.
d
(
"SplashNewActivity-->"
,
"222-->"
+
millisUntilFinished
)
SplashManager
.
preLoadAd
(
this
@SplashActivity
)
get
().
put
(
Constant
.
FIRST_SPLASH
,
false
)
}
if
(!
isFinishing
)
{
if
(
isAdSuc
)
return
if
(
SplashManager
.
isSuccessStatus
())
{
LogUtil
.
d
(
"SplashNewActivity-->"
,
"SplashNewActivity--> ad show"
)
isAdSuc
=
true
if
(
mProgressBar
!=
null
)
{
mProgressBar
!!
.
setCompleteNoAnim
()
}
// 跳转广告
readyGoThenKill
(
SplashAdActivity
::
class
.
java
)
}
}
}
...
...
video/app/src/main/java/com/duben/heliapp/ui/activitys/SplashAdActivity.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ui.activitys
import
android.os.Bundle
import
android.os.Handler
import
android.os.Looper
import
android.view.KeyEvent
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.ad.splash.SplashManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.LocalVedioManager
import
com.duben.heliapp.manager.UserManager
import
com.duben.heliapp.ui.activitys.base.BaseActivity
import
com.duben.heliapp.ui.widgets.countdowntimer.CountDownTimerSupport
import
com.duben.heliapp.ui.widgets.countdowntimer.OnCountDownTimerListener
import
com.duben.heliapp.utils.AppPreferencesManager
import
com.duben.heliapp.utils.LogUtil
import
kotlinx.android.synthetic.main.activity_gromore.*
import
java.util.HashMap
/**
* 描述:gromore广告
* 作者:孟崔广
* 时间:2021/11/08 13:52
*/
class
SplashAdActivity
:
BaseActivity
()
{
//是否强制跳转到主页面
private
var
onPaused
=
false
var
mTimer
:
CountDownTimerSupport
?
=
null
private
val
mMainHandler
=
Handler
(
Looper
.
getMainLooper
())
override
fun
getContentViewLayoutID
()
=
R
.
layout
.
activity_gromore
override
fun
isApplyKitKatTranslucency
()
=
false
override
fun
initViewsAndEvents
()
{
var
timeout
=
200L
if
(!
AppPreferencesManager
.
get
().
getBoolean
(
Constant
.
IS_FIRST_AGREE_BTN
,
false
))
{
AppPreferencesManager
.
get
().
put
(
Constant
.
IS_FIRST_AGREE_BTN
,
true
);
// 第一次 点击权限弹窗同意按钮
timeout
=
400L
}
LogUtil
.
d
(
"gromore应用内开屏广告-->"
,
"gromore应用内开屏广告-->1111initViewsAndEvents "
)
mMainHandler
.
postDelayed
({
SplashManager
.
showAd
(
this
@SplashAdActivity
,
fl_gromore_root
,
object
:
AdStatusListener
{
override
fun
adSuccess
()
{
}
override
fun
adFail
()
{
goToMainActivity
()
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
goToMainActivity
()
}
})
// 防止广告展示异常,界面卡住
startTime
()
},
timeout
)
}
override
fun
onResume
()
{
super
.
onResume
()
//判断是否该跳转到主页面
if
(
onPaused
)
{
goToMainActivity
()
}
}
override
fun
onPause
()
{
super
.
onPause
()
onPaused
=
true
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
onDestroyTimer
()
}
override
fun
onKeyDown
(
keyCode
:
Int
,
event
:
KeyEvent
?):
Boolean
{
return
if
(
keyCode
==
KeyEvent
.
KEYCODE_BACK
)
{
true
}
else
super
.
onKeyDown
(
keyCode
,
event
)
}
/**
* 跳转到主页面
*/
private
fun
goToMainActivity
()
{
readyGoThenKill
(
MainActivity
::
class
.
java
)
}
/**
* 防止广告展示异常,界面卡住
*/
private
fun
startTime
()
{
onDestroyTimer
()
mTimer
=
CountDownTimerSupport
(
3000L
,
1000L
)
mTimer
?.
setOnCountDownTimerListener
(
object
:
OnCountDownTimerListener
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
LogUtil
.
d
(
"gromore应用内开屏广告-->"
,
"gromore应用内开屏广告-->1111 onTick millisUntilFinished=${millisUntilFinished} "
)
}
override
fun
onFinish
()
{
if
(!
isFinishing
)
{
// 5秒广告都没有展示 则进入首页
if
(!
SplashManager
.
getAdStatus
())
{
onDestroyTimer
()
goToMainActivity
()
}
}
}
})
mTimer
?.
start
()
}
private
fun
onDestroyTimer
()
{
mTimer
?.
stop
()
mTimer
=
null
}
}
video/app/src/main/java/com/duben/heliapp/ui/activitys/SplashForeAdActivity.kt
deleted
100644 → 0
View file @
9185435e
package
com.duben.heliapp.ui.activitys
import
android.os.Handler
import
android.os.Looper
import
android.view.KeyEvent
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.ad.splash.SplashManager
import
com.duben.heliapp.ui.activitys.base.BaseActivity
import
com.duben.heliapp.ui.widgets.countdowntimer.CountDownTimerSupport
import
com.duben.heliapp.ui.widgets.countdowntimer.OnCountDownTimerListener
import
kotlinx.android.synthetic.main.activity_gromore.*
/**
* 描述:gromore后台返回广告
* 作者:孟崔广
* 时间:2023/8/04 13:52
*/
class
SplashForeAdActivity
:
BaseActivity
()
{
//是否强制跳转到主页面
private
var
onPaused
=
false
var
mTimer
:
CountDownTimerSupport
?
=
null
private
val
mMainHandler
=
Handler
(
Looper
.
getMainLooper
())
override
fun
getContentViewLayoutID
()
=
R
.
layout
.
activity_gromore_fore
override
fun
isApplyKitKatTranslucency
()
=
false
override
fun
initViewsAndEvents
()
{
var
timeout
=
200L
mMainHandler
.
postDelayed
({
SplashManager
.
showAd
(
this
@SplashForeAdActivity
,
fl_gromore_root
,
object
:
AdStatusListener
{
override
fun
adSuccess
()
{
}
override
fun
adFail
()
{
goToMainActivity
()
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
goToMainActivity
()
}
})
// 防止广告展示异常,界面卡住
startTime
()
},
timeout
)
}
override
fun
onResume
()
{
super
.
onResume
()
//判断是否该跳转到主页面
if
(
onPaused
)
{
goToMainActivity
()
}
}
override
fun
onPause
()
{
super
.
onPause
()
onPaused
=
true
}
override
fun
onDestroy
()
{
super
.
onDestroy
()
onDestroyTimer
()
}
override
fun
onKeyDown
(
keyCode
:
Int
,
event
:
KeyEvent
?):
Boolean
{
return
if
(
keyCode
==
KeyEvent
.
KEYCODE_BACK
)
{
true
}
else
super
.
onKeyDown
(
keyCode
,
event
)
}
/**
* 跳转到主页面
*/
private
fun
goToMainActivity
()
{
finish
()
}
/**
* 防止广告展示异常,界面卡住
*/
private
fun
startTime
()
{
onDestroyTimer
()
mTimer
=
CountDownTimerSupport
(
3000L
,
1000L
)
mTimer
?.
setOnCountDownTimerListener
(
object
:
OnCountDownTimerListener
{
override
fun
onTick
(
millisUntilFinished
:
Long
)
{
}
override
fun
onFinish
()
{
if
(!
isFinishing
)
{
// 3秒广告都没有展示 则进入首页
if
(!
SplashManager
.
getAdStatus
())
{
onDestroyTimer
()
goToMainActivity
()
}
}
}
})
mTimer
?.
start
()
}
private
fun
onDestroyTimer
()
{
mTimer
?.
stop
()
mTimer
=
null
}
}
video/app/src/main/java/com/duben/heliapp/ui/fragment/MainFragment.kt
View file @
3b5ddb43
...
...
@@ -21,8 +21,6 @@ import com.google.android.material.tabs.TabLayoutMediator
import
com.scwang.smartrefresh.layout.api.RefreshLayout
import
com.scwang.smartrefresh.layout.listener.OnRefreshListener
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.banner.BannerManager
import
com.duben.heliapp.common.AppConfig
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.LocalVedioManager
...
...
@@ -90,10 +88,6 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
AppPreferencesManager
.
get
().
put
(
Constant
.
VEDIO_MAIN_COUNT
,
0
)
if
(!
UserManager
.
getInstance
().
vipFlag
)
{
AdManager
.
instance
.
preLoadAd
(
requireActivity
())
}
Handler
(
Looper
.
getMainLooper
()).
postDelayed
({
goToMainActivity
()
},
300
)
...
...
@@ -131,9 +125,7 @@ class MainFragment : LazyLoadBaseFragment(), HomeView, View.OnClickListener, OnR
if
(
AntiShake
.
check
(
banner
?.
id
))
return
// if (!UserManager.getInstance().vipFlag) {
// BannerManager.loadAd(requireActivity(), fl_main_banner)
// }
BannerManager
.
loadAd
(
requireActivity
(),
fl_main_banner
)
if
(
AppConfig
.
exitLoginMainRefresh
)
{
AppConfig
.
exitLoginMainRefresh
=
false
...
...
video/app/src/main/java/com/duben/heliapp/ui/fragment/MovieFragment.kt
View file @
3b5ddb43
...
...
@@ -7,8 +7,6 @@ import android.widget.FrameLayout
import
androidx.fragment.app.Fragment
import
androidx.recyclerview.widget.LinearLayoutManager
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.ad.express.MainExpressManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.LocalVedioManager
import
com.duben.heliapp.mvp.model.*
...
...
@@ -79,7 +77,6 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
println
(
"mcg _______"
)
hotPage
=
1
srlMainPage
.
resetNoMoreData
()
MainExpressManager
.
instance
.
destroy
()
loadAd
()
picContentPresenter
.
getHomePageImageList
(
mType
,
hotPage
,
hotPageSize
)
}
...
...
@@ -149,19 +146,6 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
}
private
fun
loadAd
()
{
MainExpressManager
.
instance
.
loadAd
(
object
:
ExpressAdCallback
{
override
fun
loadSuccess
(
adView
:
FrameLayout
?)
{
}
override
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
{
adView
?.
let
{
addAdView
(
it
)
}
return
false
}
override
fun
loadFail
()
{
}
})
}
private
fun
addAdView
(
adView
:
FrameLayout
)
{
...
...
@@ -188,7 +172,6 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
MainExpressManager
.
instance
.
destroy
()
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ui/fragment/MyFragment.kt
View file @
3b5ddb43
...
...
@@ -10,11 +10,6 @@ import android.widget.FrameLayout
import
com.daimajia.androidanimations.library.Techniques
import
com.daimajia.androidanimations.library.YoYo
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.ad.NoPreAdManager
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.ad.express.MyExpressManager
import
com.duben.heliapp.common.AppConfig
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.UserManager
...
...
@@ -89,10 +84,6 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
if
(
AppConfig
.
fragmentClickFlag
==
Constant
.
FRAGMENT_CLICK_FOUR
)
{
if
(
AntiShake
.
check
(
ll_my_record
?.
id
))
return
if
(
userManager
.
vipFlag
){
MyExpressManager
.
instance
.
preLoadAd
()
showAd
()
}
if
(
isTurnLuckyPage
){
isTurnLuckyPage
=
false
...
...
@@ -273,43 +264,6 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
carrierType
=
Constant
.
CARRIERTYPE_NINE3
}
}
AdManager
.
instance
.
showAd
(
requireActivity
(),
carrierType
,
object
:
AdStatusListener
{
var
canFail
=
false
override
fun
adSuccess
()
{
canFail
=
true
}
override
fun
adFail
()
{
if
(
canFail
)
return
NoPreAdManager
.
loadVideoAd
(
requireActivity
(),
carrierType
,
object
:
AdStatusListener
{
override
fun
adFail
()
{
carrierType
=
Constant
.
CARRIERTYPE_NINE
showToast
(
"广告太火爆了,请稍候再试"
)
}
override
fun
adSuccess
()
{
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
vo
?.
let
{
myPresenter
.
unlock
(
vo
)
}
}
})
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
vo
?.
let
{
myPresenter
.
unlock
(
vo
)
}
}
})
}
private
fun
startNine
(
data
:
NineListBean
.
NineBean
)
{
...
...
@@ -396,32 +350,4 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
}
}
//----9宫格逻辑--结束--//
private
fun
showAd
()
{
MyExpressManager
.
instance
.
getAdView
(
object
:
ExpressAdCallback
{
override
fun
loadSuccess
(
adView
:
FrameLayout
?)
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
fl_ad
.
removeAllViews
()
fl_ad
.
addView
(
it
)
}
MyExpressManager
.
instance
.
preLoadAd
()
}
override
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
fl_ad
.
removeAllViews
()
fl_ad
.
addView
(
it
)
}
MyExpressManager
.
instance
.
preLoadAd
()
return
false
}
override
fun
loadFail
()
{
}
})
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/ui/widgets/VipCountDialog.kt
View file @
3b5ddb43
...
...
@@ -11,8 +11,6 @@ import android.view.WindowManager
import
android.widget.FrameLayout
import
android.widget.TextView
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.ad.express.ExpressManager
import
com.duben.heliapp.mvp.model.VedioBean
import
com.duben.heliapp.ui.activitys.VipActivity
import
com.duben.heliapp.ui.widgets.countdowntimer.CountDownTimerSupport
...
...
@@ -112,31 +110,6 @@ class VipCountDialog(val activity: Activity, vedioBean: VedioBean, tipList: Arra
}
private
fun
showAd
()
{
ExpressManager
.
instance
.
getAdView
(
object
:
ExpressAdCallback
{
override
fun
loadSuccess
(
adView
:
FrameLayout
?)
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
flAd
.
removeAllViews
()
flAd
.
addView
(
it
)
}
ExpressManager
.
instance
.
preLoadAd
()
}
override
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
flAd
.
removeAllViews
()
flAd
.
addView
(
it
)
}
ExpressManager
.
instance
.
preLoadAd
()
return
false
}
override
fun
loadFail
()
{
}
})
}
}
\ No newline at end of file
video/app/src/main/java/com/duben/heliapp/utils/ForegroundOrBackground.java
View file @
3b5ddb43
...
...
@@ -6,12 +6,10 @@ import android.content.Intent;
import
android.os.Bundle
;
import
android.text.TextUtils
;
import
com.duben.heliapp.ad.splash.SplashManager
;
import
com.duben.heliapp.common.AppConfig
;
import
com.duben.heliapp.manager.ActivityPageManager
;
import
com.duben.heliapp.manager.TrackManager
;
import
com.duben.heliapp.mvp.presenters.VersionUpdatePresenter
;
import
com.duben.heliapp.ui.activitys.SplashForeAdActivity
;
import
java.lang.ref.WeakReference
;
...
...
@@ -75,7 +73,6 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
String
simpleName
=
activity
.
getClass
().
getSimpleName
();
if
(
TextUtils
.
equals
(
simpleName
,
"SplashActivity"
)
||
TextUtils
.
equals
(
simpleName
,
"SplashAdActivity"
)
||
TextUtils
.
equals
(
simpleName
,
"SplashForeAdActivity"
)
||
TextUtils
.
equals
(
simpleName
,
"VipActivity"
))
{
count
++;
System
.
out
.
println
(
"mcg __>>>>>>>:: onActivityStarted simpleName="
+
simpleName
+
" 进入 count="
+
count
);
...
...
@@ -84,13 +81,6 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
}
if
(
count
==
0
)
{
long
currentTimeMillis
=
System
.
currentTimeMillis
();
long
diff
=
currentTimeMillis
-
activityStoppedTime
;
long
diffInSeconds
=
diff
/
1000
;
System
.
out
.
println
(
"mcg -->>>>>:: diffInSeconds="
+
diffInSeconds
+
" adSuccessStatus="
+
SplashManager
.
INSTANCE
.
isSuccessStatus
());
if
(
diffInSeconds
>=
30
&&
SplashManager
.
INSTANCE
.
isSuccessStatus
())
{
activity
.
startActivity
(
new
Intent
(
activity
,
SplashForeAdActivity
.
class
));
}
}
count
++;
...
...
@@ -109,7 +99,6 @@ public class ForegroundOrBackground implements Application.ActivityLifecycleCall
if
(
count
==
0
)
{
System
.
out
.
println
(
"mcg -->>>>>:: onActivityStopped"
);
activityStoppedTime
=
System
.
currentTimeMillis
();
SplashManager
.
INSTANCE
.
preLoadAd
(
activity
);
}
}
...
...
video/app/src/main/java/com/duben/heliapp/video/tx/RecommendVideoView.java
View file @
3b5ddb43
...
...
@@ -16,7 +16,6 @@ import androidx.recyclerview.widget.PagerSnapHelper;
import
androidx.recyclerview.widget.RecyclerView
;
import
androidx.recyclerview.widget.SimpleItemAnimator
;
import
com.duben.heliapp.ad.draw.HomeDrawExpressManager
;
import
com.duben.heliapp.manager.UserManager
;
import
com.duben.heliapp.mvp.model.VideoMultiItemEntity2
;
import
com.duben.heliapp.video.tx.adapter.TxRecommendVideoAdapter
;
...
...
@@ -283,12 +282,6 @@ public class RecommendVideoView extends RelativeLayout {
// 每隔3个视频出现一个广告
if
(
position
+
1
<
2
||
(
position
+
1
)
%
3
!=
0
||
lastAddAdPosition
>
position
)
return
;
if
(
HomeDrawExpressManager
.
Companion
.
getInstance
().
getAdIsLoadSuc
())
{
VideoMultiItemEntity2
itemAD
=
new
VideoMultiItemEntity2
(
MULTI_ITEM_3
,
null
,
new
VideoModel
(
""
));
mList
.
add
(
position
+
1
,
itemAD
);
mAdapter
.
notifyItemInserted
(
position
+
1
);
lastAddAdPosition
=
position
+
1
;
}
}
}
video/app/src/main/java/com/duben/heliapp/video/tx/SuperShortVideoView.java
View file @
3b5ddb43
...
...
@@ -16,7 +16,6 @@ import androidx.recyclerview.widget.PagerSnapHelper;
import
androidx.recyclerview.widget.RecyclerView
;
import
com.duben.heliapp.R
;
import
com.duben.heliapp.ad.draw.DrawExpressManager
;
import
com.duben.heliapp.manager.UserManager
;
import
com.duben.heliapp.mvp.model.VedioBean
;
import
com.duben.heliapp.mvp.model.VideoMultiItemEntity
;
...
...
@@ -322,12 +321,5 @@ public class SuperShortVideoView extends RelativeLayout {
if
(
addAdPosition
>=
mList
.
size
())
{
addAdPosition
=
position
;
}
if
(
DrawExpressManager
.
Companion
.
getInstance
().
getAdIsLoadSuc
())
{
VideoMultiItemEntity
itemAD
=
new
VideoMultiItemEntity
(
MULTI_ITEM_3
,
null
,
new
VideoModel
(
""
));
mList
.
add
(
addAdPosition
,
itemAD
);
mAdapter
.
notifyItemInserted
(
addAdPosition
);
lastAddAdPosition
=
addAdPosition
;
}
}
}
video/app/src/main/java/com/duben/heliapp/video/tx/TxVideoActivity.kt
View file @
3b5ddb43
...
...
@@ -7,11 +7,6 @@ import android.os.Looper
import
android.view.View
import
com.google.gson.Gson
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.ad.NoPreAdManager
import
com.duben.heliapp.ad.draw.DrawExpressManager
import
com.duben.heliapp.ad.express.ExpressManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.LocalVedioManager
import
com.duben.heliapp.manager.UserManager
...
...
@@ -113,17 +108,10 @@ class TxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
super
.
onDestroy
()
super_short_video_view
.
releasePlayer
()
DrawExpressManager
.
instance
.
destroy
()
ExpressManager
.
instance
.
destroy
()
videoPresenter
.
detachView
()
}
private
fun
initView
()
{
if
(!
UserManager
.
getInstance
().
vipFlag
)
{
ExpressManager
.
instance
.
preLoadAd
()
// DrawExpressManager.instance.preLoadAd()
}
episode_tv
.
text
=
String
.
format
(
"共%d集 %s"
,
mVedioBean
?.
vedioTotal
,
...
...
@@ -357,44 +345,6 @@ class TxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
private
fun
showAd
()
{
val
carrierType
=
Constant
.
CARRIERTYPE_TX_VEDIO
AdManager
.
instance
.
showAd
(
this
,
carrierType
,
object
:
AdStatusListener
{
var
canFail
=
false
override
fun
adSuccess
()
{
canFail
=
true
}
override
fun
adFail
()
{
if
(
canFail
)
return
NoPreAdManager
.
loadVideoAd
(
this
@TxVideoActivity
,
carrierType
,
object
:
AdStatusListener
{
override
fun
adFail
()
{
showToast
(
"广告太火爆了,请稍候再试"
)
}
override
fun
adSuccess
()
{
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
vo
?.
let
{
vo
[
"vedioId"
]
=
mVedioBean
!!
.
vedioId
videoPresenter
.
unlock
(
vo
)
}
}
})
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
vo
?.
let
{
vo
[
"vedioId"
]
=
mVedioBean
!!
.
vedioId
vo
[
"num"
]
=
tempNumIndex
videoPresenter
.
unlock
(
vo
)
}
}
})
}
/**
...
...
video/app/src/main/java/com/duben/heliapp/video/tx/TxVideoFragment.kt
View file @
3b5ddb43
...
...
@@ -4,7 +4,6 @@ import android.os.Bundle
import
android.view.View
import
androidx.fragment.app.Fragment
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.draw.HomeDrawExpressManager
import
com.duben.heliapp.common.AppConfig
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.LocalVedioManager
...
...
@@ -94,7 +93,6 @@ class TxVideoFragment : BaseFragment(), RecommendView {
if
(
AppConfig
.
fragmentClickFlag
!=
Constant
.
FRAGMENT_CLICK_TWO
)
return
// if (!UserManager.getInstance().vipFlag) {
// HomeDrawExpressManager.instance.preLoadAd()
// }
recommend_view
.
resume
()
...
...
@@ -110,7 +108,6 @@ class TxVideoFragment : BaseFragment(), RecommendView {
super
.
onDestroyView
()
recommend_view
.
releasePlayer
()
HomeDrawExpressManager
.
instance
.
destroy
()
}
override
fun
onDetach
()
{
...
...
video/app/src/main/java/com/duben/heliapp/video/tx/adapter/TxRecommendVideoAdapter.kt
View file @
3b5ddb43
...
...
@@ -11,8 +11,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import
com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import
com.chad.library.adapter.base.viewholder.BaseViewHolder
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.draw.HomeDrawExpressManager
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.mvp.model.*
import
com.duben.heliapp.utils.UIUtils
import
com.duben.heliapp.video.tx.TXVideoBaseView
...
...
@@ -78,24 +76,6 @@ class TxRecommendVideoAdapter :
}
private
fun
initAdHolder
(
holder
:
BaseViewHolder
)
{
HomeDrawExpressManager
.
instance
.
getAdView
(
object
:
ExpressAdCallback
{
override
fun
loadSuccess
(
adView
:
FrameLayout
?)
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
val
fmAd
=
holder
.
getView
<
FrameLayout
>(
R
.
id
.
fl_ad
)
fmAd
.
removeAllViews
()
fmAd
.
addView
(
it
)
}
// HomeDrawExpressManager.instance.preLoadAd()
}
override
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
{
return
false
}
override
fun
loadFail
()
{
}
})
}
override
fun
onViewDetachedFromWindow
(
holder
:
BaseViewHolder
)
{
...
...
video/app/src/main/java/com/duben/heliapp/video/tx/adapter/TxVideoAdapter.kt
View file @
3b5ddb43
...
...
@@ -13,9 +13,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import
com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import
com.chad.library.adapter.base.viewholder.BaseViewHolder
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.draw.DrawExpressManager
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.ad.express.ExpressManager
import
com.duben.heliapp.common.AppConfig
import
com.duben.heliapp.manager.UserManager
import
com.duben.heliapp.mvp.model.*
...
...
@@ -47,25 +44,6 @@ class TxVideoAdapter : BaseMultiItemQuickAdapter<VideoMultiItemEntity, BaseViewH
}
private
fun
initAdHolder
(
holder
:
BaseViewHolder
)
{
DrawExpressManager
.
instance
.
getAdView
(
object
:
ExpressAdCallback
{
override
fun
loadSuccess
(
adView
:
FrameLayout
?)
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
val
fmAd
=
holder
.
getView
<
FrameLayout
>(
R
.
id
.
fl_ad
)
fmAd
.
removeAllViews
()
fmAd
.
addView
(
it
)
}
// DrawExpressManager.instance.preLoadAd()
}
override
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
{
return
false
}
override
fun
loadFail
()
{
}
})
}
private
fun
initLockHolder
(
holder
:
BaseViewHolder
)
{
...
...
video/app/src/main/java/com/duben/heliapp/video/tx/newrecommend/NewTxVideoActivity.kt
View file @
3b5ddb43
...
...
@@ -8,10 +8,6 @@ import android.view.View
import
androidx.core.content.ContextCompat
import
com.google.gson.Gson
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.AdManager
import
com.duben.heliapp.ad.AdStatusListener
import
com.duben.heliapp.ad.NoPreAdManager
import
com.duben.heliapp.ad.express.ExpressManager
import
com.duben.heliapp.common.Constant
import
com.duben.heliapp.manager.LocalVedioManager
import
com.duben.heliapp.manager.UserManager
...
...
@@ -106,15 +102,10 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
super
.
onDestroy
()
new_super_short_video_view
.
releasePlayer
()
ExpressManager
.
instance
.
destroy
()
videoPresenter
.
detachView
()
}
private
fun
initView
()
{
if
(!
UserManager
.
getInstance
().
vipFlag
)
{
ExpressManager
.
instance
.
preLoadAd
()
}
episode_tv
.
text
=
String
.
format
(
"共%d集 %s"
,
mVedioBean
?.
vedioTotal
,
...
...
@@ -321,36 +312,6 @@ class NewTxVideoActivity : BaseActivity(), View.OnClickListener, VideoView,
private
fun
showAd
()
{
val
carrierType
=
Constant
.
CARRIERTYPE_TX_VEDIO
AdManager
.
instance
.
showAd
(
this
,
carrierType
,
object
:
AdStatusListener
{
var
canFail
=
false
override
fun
adSuccess
()
{
canFail
=
true
}
override
fun
adFail
()
{
if
(
canFail
)
return
NoPreAdManager
.
loadVideoAd
(
this
@NewTxVideoActivity
,
carrierType
,
object
:
AdStatusListener
{
override
fun
adFail
()
{
showToast
(
"广告太火爆了,请稍候再试"
)
}
override
fun
adSuccess
()
{
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
updateEpisodeData
(
vedioAdPosition
,
vo
)
}
})
}
override
fun
adClose
(
vo
:
HashMap
<
String
,
Any
>?)
{
updateEpisodeData
(
vedioAdPosition
,
vo
)
}
})
}
private
fun
updateEpisodeData
(
position
:
Int
,
vo
:
HashMap
<
String
,
Any
>?)
{
...
...
video/app/src/main/java/com/duben/heliapp/video/tx/newrecommend/NewTxVideoAdapter.kt
View file @
3b5ddb43
...
...
@@ -13,8 +13,6 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy
import
com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import
com.chad.library.adapter.base.viewholder.BaseViewHolder
import
com.duben.heliapp.R
import
com.duben.heliapp.ad.express.ExpressAdCallback
import
com.duben.heliapp.ad.express.ExpressManager
import
com.duben.heliapp.common.AppConfig
import
com.duben.heliapp.manager.UserManager
import
com.duben.heliapp.mvp.model.*
...
...
@@ -106,34 +104,6 @@ class NewTxVideoAdapter : BaseMultiItemQuickAdapter<VideoMultiItemEntity4, BaseV
}
}
ExpressManager
.
instance
.
getAdView
(
object
:
ExpressAdCallback
{
override
fun
loadSuccess
(
adView
:
FrameLayout
?)
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
val
fmAd
=
holder
.
getView
<
FrameLayout
>(
R
.
id
.
fl_ad
)
fmAd
.
removeAllViews
()
fmAd
.
addView
(
it
)
}
ExpressManager
.
instance
.
preLoadAd
()
}
override
fun
renderSuccess
(
adView
:
FrameLayout
?):
Boolean
{
adView
?.
let
{
UIUtils
.
removeFromParent
(
it
)
val
fmAd
=
holder
.
getView
<
FrameLayout
>(
R
.
id
.
fl_ad
)
fmAd
.
removeAllViews
()
fmAd
.
addView
(
it
)
}
ExpressManager
.
instance
.
preLoadAd
()
return
false
}
override
fun
loadFail
()
{
}
})
}
private
fun
initVideoHolder
(
holder
:
BaseViewHolder
,
item
:
IndexList
.
VedioEpisodeBean
?)
{
...
...
video/build.gradle
View file @
3b5ddb43
...
...
@@ -11,12 +11,6 @@ buildscript {
maven
{
url
'https://artifact.bytedance.com/repository/Volcengine/'
}
//GroMore SDK依赖
maven
{
url
"https://artifact.bytedance.com/repository/pangle"
}
}
dependencies
{
classpath
'com.android.tools.build:gradle:7.1.1'
...
...
@@ -35,11 +29,6 @@ allprojects {
maven
{
url
'https://artifact.bytedance.com/repository/Volcengine/'
}
//GroMore SDK依赖
maven
{
url
"https://artifact.bytedance.com/repository/pangle"
}
}
}
...
...
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