Commit e29f36db authored by wanglei's avatar wanglei

...

parent be80a446
...@@ -15,16 +15,38 @@ import com.applovin.mediation.nativeAds.MaxNativeAdLoader ...@@ -15,16 +15,38 @@ import com.applovin.mediation.nativeAds.MaxNativeAdLoader
import com.applovin.mediation.nativeAds.MaxNativeAdView import com.applovin.mediation.nativeAds.MaxNativeAdView
import com.applovin.mediation.nativeAds.MaxNativeAdViewBinder import com.applovin.mediation.nativeAds.MaxNativeAdViewBinder
import com.base.scanqr.R import com.base.scanqr.R
import com.base.scanqr.utils.LogEx
import com.google.android.gms.ads.nativead.NativeAd import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.nativead.NativeAdView import com.google.android.gms.ads.nativead.NativeAdView
@SuppressLint("ViewConstructor") @SuppressLint("ViewConstructor")
class NativeParentView(context: Context, attrs: AttributeSet? = null) : class NativeParentView(context: Context, attrs: AttributeSet? = null) :
FrameLayout(context, attrs) { FrameLayout(context, attrs) {
private val TAG = "NativeParentView"
private var removeAll = true
init {
// 获取XML属性
val a = context.obtainStyledAttributes(
attrs,
R.styleable.NativeParentView,
0,
0
)
// 从XML中读取属性值
// 例如,如果你的XML中有自定义属性 `app:customAttribute="value"`
removeAll = a.getBoolean(R.styleable.NativeParentView_removeAll, true)
// 回收TypedArray
a.recycle()
}
fun setNativeAd( fun setNativeAd(
nativeAd: NativeAd, nativeAd: NativeAd,
@LayoutRes resource: Int? = null @LayoutRes resource: Int? = null,
) { ) {
val layout = resource ?: R.layout.layout_admob_native_custom val layout = resource ?: R.layout.layout_admob_native_custom
val adView = val adView =
...@@ -58,7 +80,10 @@ class NativeParentView(context: Context, attrs: AttributeSet? = null) : ...@@ -58,7 +80,10 @@ class NativeParentView(context: Context, attrs: AttributeSet? = null) :
} }
adView.setNativeAd(nativeAd) adView.setNativeAd(nativeAd)
setBackgroundResource(0) setBackgroundResource(0)
removeAllViews() LogEx.logDebug(TAG, "removeAll=$removeAll")
if (removeAll) {
removeAllViews()
}
addView(adView) addView(adView)
} }
......
package com.base.scanqr.ads.admob package com.base.scanqr.ads.admob
import com.base.scanqr.GlobalConfig import com.base.scanqr.GlobalConfig
import com.base.scanqr.ads.AdsType import com.base.scanqr.ads.AdsType
import com.base.scanqr.ads.LimitUtils import com.base.scanqr.ads.LimitUtils
......
...@@ -47,6 +47,7 @@ class HistoryAdapter : BaseQuickAdapter<ScanBean, CommonViewHolder>() { ...@@ -47,6 +47,7 @@ class HistoryAdapter : BaseQuickAdapter<ScanBean, CommonViewHolder>() {
if (ad is NativeAd) { if (ad is NativeAd) {
LogEx.logDebug(TAG, "ad is NativeAd") LogEx.logDebug(TAG, "ad is NativeAd")
item.ad = ad item.ad = ad
binding.shimmerLayout.visibility = View.INVISIBLE
} }
}) })
} else { } else {
......
...@@ -7,7 +7,9 @@ object CollectionEx { ...@@ -7,7 +7,9 @@ object CollectionEx {
val newList = mutableListOf<T>() val newList = mutableListOf<T>()
chunkedList.forEach { chunkedList.forEach {
newList.addAll(it) newList.addAll(it)
newList.add(newElement()) if (it.size == beanStep) {
newList.add(newElement())
}
} }
return newList return newList
} }
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp" android:layout_marginVertical="8dp"
android:background="@drawable/bg_ecf6ff_20" android:background="@drawable/bg_ecf6ff_20"
android:minHeight="133dp"> android:minHeight="133dp"
app:removeAll="false">
<io.supercharge.shimmerlayout.ShimmerLayout <io.supercharge.shimmerlayout.ShimmerLayout
android:id="@+id/shimmerLayout" android:id="@+id/shimmerLayout"
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="NativeParentView">
<attr name="removeAll" format="boolean" />
</declare-styleable>
</resources>
\ 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