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

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

parent f69c5e44
...@@ -48,8 +48,8 @@ object AdsMgr { ...@@ -48,8 +48,8 @@ object AdsMgr {
* @param context 这里最好是appContext,因为是耗时操作,等它初始化完毕马上加载开屏和插屏广告 * @param context 这里最好是appContext,因为是耗时操作,等它初始化完毕马上加载开屏和插屏广告
*/ */
fun init(context: Context, adsConfigBean: AdsConfigBean) { fun init(context: Context, adsConfigBean: AdsConfigBean) {
this.adsConfigBean = adsConfigBean
if (adsConfigBean.isInBlackList) return if (adsConfigBean.isInBlackList) return
this.adsConfigBean = adsConfigBean
MobileAds.initialize(context) { MobileAds.initialize(context) {
val readyAdapter = it.adapterStatusMap.entries.find { entry -> val readyAdapter = it.adapterStatusMap.entries.find { entry ->
entry.value.initializationState == AdapterStatus.State.READY entry.value.initializationState == AdapterStatus.State.READY
......
...@@ -19,6 +19,8 @@ import java.lang.ref.WeakReference ...@@ -19,6 +19,8 @@ import java.lang.ref.WeakReference
*/ */
class AdInsertMgr : BaseAdMgr<InterstitialAd>() { class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
private var lastOpenDate: Long = 0
private val adLoadCallback = object : InterstitialAdLoadCallback() { private val adLoadCallback = object : InterstitialAdLoadCallback() {
override fun onAdLoaded(ad: InterstitialAd) { override fun onAdLoaded(ad: InterstitialAd) {
super.onAdLoaded(ad) super.onAdLoaded(ad)
...@@ -60,7 +62,9 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() { ...@@ -60,7 +62,9 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
} }
override fun show(activity: Activity, showCallBack: AdsShowCallBack?) { 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() showCallBack?.failed()
return return
} }
...@@ -88,6 +92,7 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() { ...@@ -88,6 +92,7 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
fullScreenContentCallback = object : FullScreenContentCallback() { fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() { override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent() super.onAdShowedFullScreenContent()
lastOpenDate = System.currentTimeMillis()
// 广告展示 // 广告展示
currentAd = null currentAd = null
activityRef = null activityRef = null
...@@ -128,7 +133,5 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() { ...@@ -128,7 +133,5 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
} }
} }
override fun adAvailable(): Boolean { override fun adAvailable()=((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
} }
\ No newline at end of file
...@@ -18,6 +18,8 @@ import java.lang.ref.WeakReference ...@@ -18,6 +18,8 @@ import java.lang.ref.WeakReference
*/ */
class AdOpenMgr : BaseAdMgr<AppOpenAd>() { class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
private var lastOpenDate: Long = 0
private val adLoadCallback = object : AppOpenAd.AppOpenAdLoadCallback() { private val adLoadCallback = object : AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(appOpenAd: AppOpenAd) { override fun onAdLoaded(appOpenAd: AppOpenAd) {
super.onAdLoaded(appOpenAd) super.onAdLoaded(appOpenAd)
...@@ -59,7 +61,10 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() { ...@@ -59,7 +61,10 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
} }
override fun show(activity: Activity, showCallBack: AdsShowCallBack?) { 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() showCallBack?.failed()
return return
} }
...@@ -87,6 +92,7 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() { ...@@ -87,6 +92,7 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
fullScreenContentCallback = object : FullScreenContentCallback() { fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() { override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent() super.onAdShowedFullScreenContent()
lastOpenDate = System.currentTimeMillis()
// 广告展示 // 广告展示
currentAd = null currentAd = null
activityRef = null activityRef = null
...@@ -126,7 +132,5 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() { ...@@ -126,7 +132,5 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
} }
} }
override fun adAvailable(): Boolean { override fun adAvailable() = ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
} }
\ No newline at end of file
...@@ -95,5 +95,12 @@ object LimitUtils { ...@@ -95,5 +95,12 @@ object LimitUtils {
addNum(NUM_CLICK) 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