Commit a8dabff6 authored by wanglei's avatar wanglei

...

parent 5eba597d
......@@ -138,7 +138,7 @@ object AdmobNativeUtils {
}
}
var readyNative = arrayListOf<NativeAd>()
private var readyNative = arrayListOf<NewsBean>()
fun loadNativeList(count: Int) {
readyNative.clear()
repeat(count) {
......@@ -146,7 +146,12 @@ object AdmobNativeUtils {
MyApplication.context,
if (BuildConfig.DEBUG) ConfigHelper.nativeAdmobIdTest else ConfigHelper.nativeAdmobId
).forNativeAd {
readyNative.add(it)
val newsBean = NewsBean().apply {
uiType = 1
nativeAd = it
nativeAdLoadTime = System.currentTimeMillis()
}
readyNative.add(newsBean)
}.withAdListener(object : AdListener() {
override fun onAdLoaded() {
super.onAdLoaded()
......@@ -154,6 +159,7 @@ object AdmobNativeUtils {
}
override fun onAdClicked() {
LogEx.logDebug(TAG, "loadNativeList onAdClicked")
}
override fun onAdFailedToLoad(p0: LoadAdError) {
......@@ -170,42 +176,30 @@ object AdmobNativeUtils {
list.add(newsBean)
if (index == 0) {
runCatching {
val ad = AdmobNativeUtils.readyNative[0]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
val ad = readyNative[0]
list.add(ad)
}
}
if (index == 4) {
runCatching {
val ad = AdmobNativeUtils.readyNative[1]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
val ad = readyNative[1]
list.add(ad)
}
}
if (index == 8) {
runCatching {
val ad = AdmobNativeUtils.readyNative[2]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
val ad = readyNative[2]
list.add(ad)
}
}
if (index == 12) {
runCatching {
val ad = AdmobNativeUtils.readyNative[3]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
val ad = readyNative[3]
list.add(ad)
}
}
}
AdmobNativeUtils.loadNativeList(4)
loadNativeList(4)
return list
}
}
\ No newline at end of file
package com.base.browserwhite.bean
import com.base.browserwhite.utils.LogEx
import com.google.android.gms.ads.nativead.NativeAd
import java.util.concurrent.TimeUnit
class NewsBean(
val newsId: Long = 0,
......@@ -15,7 +17,13 @@ class NewsBean(
) {
var uiType: Int = 0//0新闻 1广告
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 ,
......
......@@ -95,7 +95,7 @@ class NewsAdapter(
1 -> {
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)
}
}
......
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