Commit 49bc8ed4 authored by wanglei's avatar wanglei Committed by songjianyu

[修改]将开屏和插页共用上次展示时间字段,避免开屏和插页连弹

parent ab87117d
......@@ -11,7 +11,7 @@ class AdConfigBean(
var numDisplayLimit: Int = -1,//展示次数限制
var numRequestLimit: Int = -1,//请求次数限制
var numClickLimit: Int = -1,//点击次数限制
var timeInterval: Int = 1,//广告间隔
var timeInterval: Int = 10,//广告间隔秒
var openAdLoading: Int = 15,//开屏广告拉取时间
var fullNativeShow: Boolean = true,//显示全屏原生
......
......@@ -2,6 +2,8 @@ package com.base.appzxhy.business.ads
import android.app.Activity
import android.app.Dialog
import com.base.appzxhy.business.ads.LimitUtils.openInterLastShowTime
import com.base.appzxhy.utils.AppPreferences
import java.lang.ref.WeakReference
......@@ -34,7 +36,7 @@ class AdState<T>() {
/**
* 上次展示时间
*/
var lastShowTime: Long = 0
// var lastShowTime: Long = 0
/**
......@@ -47,13 +49,13 @@ class AdState<T>() {
adDialog?.dismiss()
adDialog = null
lastShowTime = System.currentTimeMillis()
openInterLastShowTime = System.currentTimeMillis()
}
fun onAdHidden() {
//重置下上次展示的时间,避免看广告的时间算入间隔
lastShowTime = System.currentTimeMillis()
openInterLastShowTime = System.currentTimeMillis()
}
......
......@@ -145,14 +145,22 @@ object LimitUtils {
/**
* 开屏和插页广告的显示间隔限制
*
* @param lastTime 上一次显示的时间
*/
fun isIntervalLimited(lastTime: Long, adEvent: AdEvent): Boolean {
val flag = ((System.currentTimeMillis() - lastTime) / 1000).toInt() < (AdConfigBean.adsConfigBean.timeInterval)
fun isIntervalLimited(adEvent: AdEvent): Boolean {
val flag = ((System.currentTimeMillis() - openInterLastShowTime) / 1000).toInt() < (AdConfigBean.adsConfigBean.timeInterval)
if (flag) {
adEvent.adShowError("ad in timeInterval")
}
return flag
}
//开屏和插页上一次展示时间共用,避免开屏插页连弹
var openInterLastShowTime = 0L
get() {
return AppPreferences.getInstance().getLong("openInterLastShowTime", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("openInterLastShowTime", value, true)
}
}
\ No newline at end of file
......@@ -45,7 +45,7 @@ class AdInterMgr {
showCallBack?.failed(2)
return
}
if (LimitUtils.isIntervalLimited(adState.lastShowTime, adEvent)) {
if (LimitUtils.isIntervalLimited( adEvent)) {
showCallBack?.failed(3)
return
}
......
......@@ -36,7 +36,7 @@ class AdOpenMgr {
showCallBack?.failed()
return
}
if (LimitUtils.isIntervalLimited(adState.lastShowTime, adEvent)) {
if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed()
return
}
......
......@@ -50,7 +50,7 @@ class MaxInsertMgr {
showCallBack?.failed(3)
return
}
if (LimitUtils.isIntervalLimited(adState.lastShowTime, adEvent)) {
if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed(4)
return
}
......
......@@ -40,7 +40,7 @@ class MaxOpenMgr {
showCallBack?.failed()
return
}
if (LimitUtils.isIntervalLimited(adState.lastShowTime, adEvent)) {
if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed()
return
}
......
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