Commit 0b3c14cf authored by songjianyu's avatar songjianyu

[修改] 广告bug修复

parent b4d554ee
...@@ -42,7 +42,9 @@ class AdBannerMgr { ...@@ -42,7 +42,9 @@ class AdBannerMgr {
adView = AdView(parent.context) adView = AdView(parent.context)
parent.addView(adView) parent.addView(adView)
adView?.onPaidEventListener = AdmobOnPaidEventListener(adView, admobEvent.scope) adView?.let{
it.onPaidEventListener = AdmobOnPaidEventListener(it, admobEvent.scope)
}
listener = ViewTreeObserver.OnGlobalLayoutListener { listener = ViewTreeObserver.OnGlobalLayoutListener {
val screenPixelDensity = parent.context.resources.displayMetrics.density val screenPixelDensity = parent.context.resources.displayMetrics.density
......
...@@ -76,12 +76,15 @@ class AdInterMgr { ...@@ -76,12 +76,15 @@ class AdInterMgr {
private fun showReadyAd(adEvent: AdEvent) { private fun showReadyAd(adEvent: AdEvent) {
val ac = adState.activityRef?.get()
if (ac==null || ac.isDestroyed || ac.isFinishing){
return
}
adState.currentAd?.run { adState.currentAd?.run {
fullScreenContentCallback = object : FullScreenContentCallback() { fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() { override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent() super.onAdShowedFullScreenContent()
val ac = adState.activityRef?.get()
(adEvent as AdmobEvent).showAd(responseInfo, ac) (adEvent as AdmobEvent).showAd(responseInfo, ac)
adState.onAdDisplayed() adState.onAdDisplayed()
...@@ -153,7 +156,7 @@ class AdInterMgr { ...@@ -153,7 +156,7 @@ class AdInterMgr {
} }
(adEvent as AdmobEvent).pullAd(ad.responseInfo) (adEvent as AdmobEvent).pullAd(ad.responseInfo)
LimitUtils.addRequestNum() LimitUtils.addRequestNum()
ad.onPaidEventListener = AdmobOnPaidEventListener(adEvent.scope) ad.onPaidEventListener = AdmobOnPaidEventListener(ad,adEvent.scope)
} }
override fun onAdFailedToLoad(loadAdError: LoadAdError) { override fun onAdFailedToLoad(loadAdError: LoadAdError) {
......
...@@ -144,12 +144,11 @@ class AdmobEvent : AdEvent { ...@@ -144,12 +144,11 @@ class AdmobEvent : AdEvent {
class AdmobOnPaidEventListener( class AdmobOnPaidEventListener(
private val ad: Any?, private val ad: Any,
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO) private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
) : OnPaidEventListener { ) : OnPaidEventListener {
override fun onPaidEvent(adValue: AdValue) { override fun onPaidEvent(adValue: AdValue) {
ad ?: return
onPaidEvent2(ad, adValue) onPaidEvent2(ad, adValue)
} }
......
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