Commit e29f36db authored by wanglei's avatar wanglei

...

parent be80a446
......@@ -15,16 +15,38 @@ import com.applovin.mediation.nativeAds.MaxNativeAdLoader
import com.applovin.mediation.nativeAds.MaxNativeAdView
import com.applovin.mediation.nativeAds.MaxNativeAdViewBinder
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.NativeAdView
@SuppressLint("ViewConstructor")
class NativeParentView(context: Context, attrs: AttributeSet? = null) :
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(
nativeAd: NativeAd,
@LayoutRes resource: Int? = null
@LayoutRes resource: Int? = null,
) {
val layout = resource ?: R.layout.layout_admob_native_custom
val adView =
......@@ -58,7 +80,10 @@ class NativeParentView(context: Context, attrs: AttributeSet? = null) :
}
adView.setNativeAd(nativeAd)
setBackgroundResource(0)
removeAllViews()
LogEx.logDebug(TAG, "removeAll=$removeAll")
if (removeAll) {
removeAllViews()
}
addView(adView)
}
......
package com.base.scanqr.ads.admob
import com.base.scanqr.GlobalConfig
import com.base.scanqr.ads.AdsType
import com.base.scanqr.ads.LimitUtils
......
......@@ -47,6 +47,7 @@ class HistoryAdapter : BaseQuickAdapter<ScanBean, CommonViewHolder>() {
if (ad is NativeAd) {
LogEx.logDebug(TAG, "ad is NativeAd")
item.ad = ad
binding.shimmerLayout.visibility = View.INVISIBLE
}
})
} else {
......
......@@ -7,7 +7,9 @@ object CollectionEx {
val newList = mutableListOf<T>()
chunkedList.forEach {
newList.addAll(it)
newList.add(newElement())
if (it.size == beanStep) {
newList.add(newElement())
}
}
return newList
}
......
......@@ -8,7 +8,8 @@
android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp"
android:background="@drawable/bg_ecf6ff_20"
android:minHeight="133dp">
android:minHeight="133dp"
app:removeAll="false">
<io.supercharge.shimmerlayout.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