Commit a8dabff6 authored by wanglei's avatar wanglei

...

parent 5eba597d
...@@ -138,7 +138,7 @@ object AdmobNativeUtils { ...@@ -138,7 +138,7 @@ object AdmobNativeUtils {
} }
} }
var readyNative = arrayListOf<NativeAd>() private var readyNative = arrayListOf<NewsBean>()
fun loadNativeList(count: Int) { fun loadNativeList(count: Int) {
readyNative.clear() readyNative.clear()
repeat(count) { repeat(count) {
...@@ -146,7 +146,12 @@ object AdmobNativeUtils { ...@@ -146,7 +146,12 @@ object AdmobNativeUtils {
MyApplication.context, MyApplication.context,
if (BuildConfig.DEBUG) ConfigHelper.nativeAdmobIdTest else ConfigHelper.nativeAdmobId if (BuildConfig.DEBUG) ConfigHelper.nativeAdmobIdTest else ConfigHelper.nativeAdmobId
).forNativeAd { ).forNativeAd {
readyNative.add(it) val newsBean = NewsBean().apply {
uiType = 1
nativeAd = it
nativeAdLoadTime = System.currentTimeMillis()
}
readyNative.add(newsBean)
}.withAdListener(object : AdListener() { }.withAdListener(object : AdListener() {
override fun onAdLoaded() { override fun onAdLoaded() {
super.onAdLoaded() super.onAdLoaded()
...@@ -154,6 +159,7 @@ object AdmobNativeUtils { ...@@ -154,6 +159,7 @@ object AdmobNativeUtils {
} }
override fun onAdClicked() { override fun onAdClicked() {
LogEx.logDebug(TAG, "loadNativeList onAdClicked")
} }
override fun onAdFailedToLoad(p0: LoadAdError) { override fun onAdFailedToLoad(p0: LoadAdError) {
...@@ -170,42 +176,30 @@ object AdmobNativeUtils { ...@@ -170,42 +176,30 @@ object AdmobNativeUtils {
list.add(newsBean) list.add(newsBean)
if (index == 0) { if (index == 0) {
runCatching { runCatching {
val ad = AdmobNativeUtils.readyNative[0] val ad = readyNative[0]
list.add(NewsBean().apply { list.add(ad)
uiType = 1
nativeAd = ad
})
} }
} }
if (index == 4) { if (index == 4) {
runCatching { runCatching {
val ad = AdmobNativeUtils.readyNative[1] val ad = readyNative[1]
list.add(NewsBean().apply { list.add(ad)
uiType = 1
nativeAd = ad
})
} }
} }
if (index == 8) { if (index == 8) {
runCatching { runCatching {
val ad = AdmobNativeUtils.readyNative[2] val ad = readyNative[2]
list.add(NewsBean().apply { list.add(ad)
uiType = 1
nativeAd = ad
})
} }
} }
if (index == 12) { if (index == 12) {
runCatching { runCatching {
val ad = AdmobNativeUtils.readyNative[3] val ad = readyNative[3]
list.add(NewsBean().apply { list.add(ad)
uiType = 1
nativeAd = ad
})
} }
} }
} }
AdmobNativeUtils.loadNativeList(4) loadNativeList(4)
return list return list
} }
} }
\ No newline at end of file
package com.base.browserwhite.bean package com.base.browserwhite.bean
import com.base.browserwhite.utils.LogEx
import com.google.android.gms.ads.nativead.NativeAd import com.google.android.gms.ads.nativead.NativeAd
import java.util.concurrent.TimeUnit
class NewsBean( class NewsBean(
val newsId: Long = 0, val newsId: Long = 0,
...@@ -15,7 +17,13 @@ class NewsBean( ...@@ -15,7 +17,13 @@ class NewsBean(
) { ) {
var uiType: Int = 0//0新闻 1广告 var uiType: Int = 0//0新闻 1广告
var nativeAd: NativeAd? = null var nativeAd: NativeAd? = null
var nativeAdLoadTime: Long = 0
fun isNativeAdTimeout(): Boolean {
val outTime = System.currentTimeMillis() - nativeAdLoadTime
LogEx.logDebug("NewsBean", "outTime=$outTime")
return outTime > 30 * 60 * 1000L
}
} }
// 栏目类别 0:最新 , 101 :政治, 301:体育 ,娱乐:501 , // 栏目类别 0:最新 , 101 :政治, 301:体育 ,娱乐:501 ,
......
...@@ -95,7 +95,7 @@ class NewsAdapter( ...@@ -95,7 +95,7 @@ class NewsAdapter(
1 -> { 1 -> {
val binding = ItemNewsAdBinding.bind(holder.itemView) val binding = ItemNewsAdBinding.bind(holder.itemView)
if (item.nativeAd != null) { if (item.nativeAd != null && !item.isNativeAdTimeout()) {
AdmobNativeUtils.showReadyNativeAd(null, item.nativeAd, binding.flAd, R.layout.layout_admob_native_news) AdmobNativeUtils.showReadyNativeAd(null, item.nativeAd, binding.flAd, R.layout.layout_admob_native_news)
} }
} }
......
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