Commit fc5034df authored by 周文华's avatar 周文华

【新增&调整】1.新增开屏和插屏的间隔时间逻辑。 2.调整部分逻辑

parent f69c5e44
......@@ -48,8 +48,8 @@ object AdsMgr {
* @param context 这里最好是appContext,因为是耗时操作,等它初始化完毕马上加载开屏和插屏广告
*/
fun init(context: Context, adsConfigBean: AdsConfigBean) {
this.adsConfigBean = adsConfigBean
if (adsConfigBean.isInBlackList) return
this.adsConfigBean = adsConfigBean
MobileAds.initialize(context) {
val readyAdapter = it.adapterStatusMap.entries.find { entry ->
entry.value.initializationState == AdapterStatus.State.READY
......
......@@ -19,6 +19,8 @@ import java.lang.ref.WeakReference
*/
class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
private var lastOpenDate: Long = 0
private val adLoadCallback = object : InterstitialAdLoadCallback() {
override fun onAdLoaded(ad: InterstitialAd) {
super.onAdLoaded(ad)
......@@ -60,7 +62,9 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
}
override fun show(activity: Activity, showCallBack: AdsShowCallBack?) {
if (activity.isFinishing || activity.isDestroyed || !LimitUtils.isAdShow()) {
if (activity.isFinishing || activity.isDestroyed || !LimitUtils.isAdShow()|| LimitUtils.isIntervalLimited(
lastOpenDate
)) {
showCallBack?.failed()
return
}
......@@ -88,6 +92,7 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent()
lastOpenDate = System.currentTimeMillis()
// 广告展示
currentAd = null
activityRef = null
......@@ -128,7 +133,5 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
}
}
override fun adAvailable(): Boolean {
return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
override fun adAvailable()=((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
\ No newline at end of file
......@@ -18,6 +18,8 @@ import java.lang.ref.WeakReference
*/
class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
private var lastOpenDate: Long = 0
private val adLoadCallback = object : AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(appOpenAd: AppOpenAd) {
super.onAdLoaded(appOpenAd)
......@@ -59,7 +61,10 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
}
override fun show(activity: Activity, showCallBack: AdsShowCallBack?) {
if (activity.isFinishing || activity.isDestroyed || !LimitUtils.isAdShow()) {
if (activity.isFinishing || activity.isDestroyed || !LimitUtils.isAdShow() || LimitUtils.isIntervalLimited(
lastOpenDate
)
) {
showCallBack?.failed()
return
}
......@@ -87,6 +92,7 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent()
lastOpenDate = System.currentTimeMillis()
// 广告展示
currentAd = null
activityRef = null
......@@ -126,7 +132,5 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
}
}
override fun adAvailable(): Boolean {
return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
override fun adAvailable() = ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
\ No newline at end of file
......@@ -95,5 +95,12 @@ object LimitUtils {
addNum(NUM_CLICK)
}
/**
* 开屏和插页广告的显示间隔限制
*
* @param lastTime 上一次显示的时间
*/
fun isIntervalLimited(lastTime: Long) =
((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < (AdsMgr.adsConfigBean?.timeInterval
?: 1)
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment