Commit 77f632a6 authored by wanglei's avatar wanglei

...

parent 0f1ded04
...@@ -25,7 +25,7 @@ object AdmobMaxHelper { ...@@ -25,7 +25,7 @@ object AdmobMaxHelper {
var isBlack: Boolean = false var isBlack: Boolean = false
var isInterOpenShowing: Boolean = false var isInterOpenShowing: Boolean = false
// if (System.currentTimeMillis() - lastShowInter > 10 * 1000 * 1000 || lastShowInter == 0L) { // if (System.currentTimeMillis() - lastShowInter > 10 * 1000 * 1000 || lastShowInter == 0L) {
// AdmobMaxHelper.admobMaxShowInterstitialAd(this@WebBrowserActivity, false) { // AdmobMaxHelper.admobMaxShowInterstitialAd(this@WebBrowserActivity, false) {
// if (it) { // if (it) {
// lastShowInter = System.currentTimeMillis() // lastShowInter = System.currentTimeMillis()
...@@ -163,6 +163,7 @@ object AdmobMaxHelper { ...@@ -163,6 +163,7 @@ object AdmobMaxHelper {
if (getSpAdmobTrueMaxFalse()) { if (getSpAdmobTrueMaxFalse()) {
// com.base.browserwhite.ads.admob.AdmobOpenUtils.loadAppOpenAd() // com.base.browserwhite.ads.admob.AdmobOpenUtils.loadAppOpenAd()
AdmobInterstitialUtils.loadInterstitialAd(activity) AdmobInterstitialUtils.loadInterstitialAd(activity)
AdmobNativeUtils.loadNativeList(3)
} else { } else {
if (isAdInit.get()) { if (isAdInit.get()) {
// com.base.browserwhite.ads.max.AdMaxOpenUtils.loadAppOpenAd(activity) // com.base.browserwhite.ads.max.AdMaxOpenUtils.loadAppOpenAd(activity)
......
...@@ -116,5 +116,50 @@ object AdmobNativeUtils { ...@@ -116,5 +116,50 @@ object AdmobNativeUtils {
} else { } else {
loadingListener?.invoke() loadingListener?.invoke()
} }
}
fun showReadyNativeAd(
activity: Activity?,
readyNativeAd: NativeAd?,
parent: ViewGroup,
layout: Int = R.layout.layout_admob_native_news
) {
readyNativeAd?.let {
NativeView(parent.context, layout).run {
parent.removeAllViews()
setNativeAd(it)
parent.addView(this)
parent.isVisible = true
showAd(nativeAd?.responseInfo, "nativeAd", activity)
}
}
}
var readyNative = arrayListOf<NativeAd>()
fun loadNativeList(count: Int) {
readyNative.clear()
repeat(count) {
val adLoader = AdLoader.Builder(
MyApplication.context,
if (BuildConfig.DEBUG) ConfigHelper.nativeAdmobIdTest else ConfigHelper.nativeAdmobId
).forNativeAd {
readyNative.add(it)
}.withAdListener(object : AdListener() {
override fun onAdLoaded() {
super.onAdLoaded()
LogEx.logDebug(TAG, "loadNativeList onAdLoaded")
}
override fun onAdClicked() {
}
override fun onAdFailedToLoad(p0: LoadAdError) {
LogEx.logDebug(TAG, "loadNativeList onAdFailedToLoad")
}
}).build()
adLoader.loadAd(mRequest)
}
} }
} }
\ No newline at end of file
package com.base.browserwhite.bean package com.base.browserwhite.bean
import com.google.android.gms.ads.nativead.NativeAd
class NewsBean( class NewsBean(
val newsId: Long = 0, val newsId: Long = 0,
val publishTime: Long = 0, val publishTime: Long = 0,
...@@ -12,6 +14,7 @@ class NewsBean( ...@@ -12,6 +14,7 @@ class NewsBean(
val linkPath: String = "",//网站链接 val linkPath: String = "",//网站链接
) { ) {
var uiType: Int = 0//0新闻 1广告 var uiType: Int = 0//0新闻 1广告
var nativeAd: NativeAd? = null
} }
......
...@@ -92,7 +92,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() { ...@@ -92,7 +92,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
} }
addDeskShortCut() addDeskShortCut()
} }
......
...@@ -6,7 +6,10 @@ import android.view.View ...@@ -6,7 +6,10 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.ads.AdmobMaxHelper
import com.base.browserwhite.ads.admob.AdmobNativeUtils
import com.base.browserwhite.bean.NewsBean import com.base.browserwhite.bean.NewsBean
import com.base.browserwhite.databinding.ItemNewsAdBinding
import com.base.browserwhite.databinding.ItemNewsBinding import com.base.browserwhite.databinding.ItemNewsBinding
import com.base.browserwhite.utils.KotlinExt.toFormatTime import com.base.browserwhite.utils.KotlinExt.toFormatTime
import com.base.browserwhite.utils.XmlEx.inflate import com.base.browserwhite.utils.XmlEx.inflate
...@@ -33,7 +36,7 @@ class NewsAdapter( ...@@ -33,7 +36,7 @@ class NewsAdapter(
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): NewsViewHolder { override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): NewsViewHolder {
var layout = R.layout.item_news var layout = R.layout.item_news
if (viewType==1) layout = R.layout.item_news_ad if (viewType == 1) layout = R.layout.item_news_ad
return NewsViewHolder(layout.inflate(parent)) return NewsViewHolder(layout.inflate(parent))
} }
...@@ -42,50 +45,63 @@ class NewsAdapter( ...@@ -42,50 +45,63 @@ class NewsAdapter(
if (item == null) { if (item == null) {
return return
} }
val binding = ItemNewsBinding.bind(holder.itemView)
if (items.first() == item && showMore) { when (item.uiType) {
binding.ll.visibility = View.VISIBLE 0 -> {
} else { val binding = ItemNewsBinding.bind(holder.itemView)
binding.ll.visibility = View.GONE if (items.first() == item && showMore) {
} binding.ll.visibility = View.VISIBLE
} else {
binding.ll.visibility = View.GONE
}
// val bean = beanList[position] // val bean = beanList[position]
val context = holder.itemView.context val context = holder.itemView.context
Glide.with(context).load(item.orgImgPath).listener(object : RequestListener<Drawable> { Glide.with(context).load(item.orgImgPath).listener(object : RequestListener<Drawable> {
override fun onLoadFailed( override fun onLoadFailed(
e: GlideException?, e: GlideException?,
model: Any?, model: Any?,
target: Target<Drawable>, target: Target<Drawable>,
isFirstResource: Boolean isFirstResource: Boolean
): Boolean { ): Boolean {
return true return true
} }
override fun onResourceReady( override fun onResourceReady(
resource: Drawable, resource: Drawable,
model: Any, model: Any,
target: Target<Drawable>?, target: Target<Drawable>?,
dataSource: DataSource, dataSource: DataSource,
isFirstResource: Boolean isFirstResource: Boolean
): Boolean { ): Boolean {
return false return false
}
}).centerCrop().into(binding.ivMedia)
binding.tvTittle.text = item.headline
runCatching {
Glide.with(context).load(item.mediaIcon).into(binding.ivIcon)
}
binding.tvMediaName.text = item.mediaName
binding.tvPublishTime.text = item.publishTime.toFormatTime()
binding.ivMedia.setOnClickListener {
clickAction.invoke(item.linkPath)
}
binding.tvMore.setOnClickListener {
moreAction?.invoke()
}
} }
}).centerCrop().into(binding.ivMedia) 1 -> {
binding.tvTittle.text = item.headline val binding = ItemNewsAdBinding.bind(holder.itemView)
runCatching { if (item.nativeAd != null) {
Glide.with(context).load(item.mediaIcon).into(binding.ivIcon) AdmobNativeUtils.showReadyNativeAd(null, item.nativeAd, binding.flAd, R.layout.layout_admob_native_news)
} }
binding.tvMediaName.text = item.mediaName }
binding.tvPublishTime.text = item.publishTime.toFormatTime()
binding.ivMedia.setOnClickListener {
clickAction.invoke(item.linkPath)
}
binding.tvMore.setOnClickListener {
moreAction?.invoke()
} }
} }
fun getLastPageNumber(): Long? { fun getLastPageNumber(): Long? {
......
...@@ -6,6 +6,7 @@ import android.content.Intent ...@@ -6,6 +6,7 @@ import android.content.Intent
import android.view.View import android.view.View
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import com.base.browserwhite.BuildConfig import com.base.browserwhite.BuildConfig
import com.base.browserwhite.ads.admob.AdmobNativeUtils
import com.base.browserwhite.bean.MediaBean import com.base.browserwhite.bean.MediaBean
import com.base.browserwhite.databinding.FragmentFileBinding import com.base.browserwhite.databinding.FragmentFileBinding
import com.base.browserwhite.ui.activity.MainActivity import com.base.browserwhite.ui.activity.MainActivity
...@@ -59,6 +60,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() { ...@@ -59,6 +60,7 @@ class FileFragment : BaseFragment<FragmentFileBinding>() {
moreAction(requireContext(), view, bean, adapter) moreAction(requireContext(), view, bean, adapter)
}) })
binding.rvRecent.adapter = adapter binding.rvRecent.adapter = adapter
} }
companion object { companion object {
......
...@@ -12,6 +12,7 @@ import android.widget.Toast ...@@ -12,6 +12,7 @@ import android.widget.Toast
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.base.browserwhite.R import com.base.browserwhite.R
import com.base.browserwhite.ads.admob.AdmobNativeUtils
import com.base.browserwhite.bean.BookmarkBean import com.base.browserwhite.bean.BookmarkBean
import com.base.browserwhite.bean.ConstObject.APP_PROCESS import com.base.browserwhite.bean.ConstObject.APP_PROCESS
import com.base.browserwhite.bean.ConstObject.BAIDU import com.base.browserwhite.bean.ConstObject.BAIDU
...@@ -219,12 +220,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -219,12 +220,13 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
LogEx.logDebug(TAG, "errorCallBack") LogEx.logDebug(TAG, "errorCallBack")
}, beanCallBack = { }, beanCallBack = {
isLoading = false isLoading = false
val newsAdList = addNativeAdNewsBean(it)
binding.root.post { binding.root.post {
LogEx.logDebug(TAG, "beanCallBack") LogEx.logDebug(TAG, "beanCallBack")
if (lastNewsId == null) { if (lastNewsId == null) {
newsAdapter.submitList(it) newsAdapter.submitList(newsAdList)
} else { } else {
newsAdapter.addAll(it) newsAdapter.addAll(newsAdList)
} }
helper.trailingLoadState = LoadState.NotLoading(false) helper.trailingLoadState = LoadState.NotLoading(false)
} }
...@@ -232,9 +234,40 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -232,9 +234,40 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
}) })
} }
fun addNativeAdNewsBean(it: List<NewsBean>) { private fun addNativeAdNewsBean(it: List<NewsBean>): ArrayList<NewsBean> {
val list = arrayListOf<NewsBean>() val list = arrayListOf<NewsBean>()
it.forEachIndexed { index, newsBean ->
list.add(newsBean)
if (index == 1) {
runCatching {
val ad = AdmobNativeUtils.readyNative[0]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
}
}
if (index == 6) {
runCatching {
val ad = AdmobNativeUtils.readyNative[1]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
}
}
if (index == 1) {
runCatching {
val ad = AdmobNativeUtils.readyNative[3]
list.add(NewsBean().apply {
uiType = 1
nativeAd = ad
})
}
}
}
AdmobNativeUtils.loadNativeList(3)
return list
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1.5dp" android:color="#9d9d9d"/>
<corners android:radius="7.5dp"/>
</shape>
\ No newline at end of file
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/fl_ad"
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginVertical="8dp" android:layout_marginVertical="8dp"
android:orientation="vertical"> android:orientation="vertical">
<include layout="@layout/layout_admob_native_download" /> <include layout="@layout/layout_admob_native_news" />
</FrameLayout> </FrameLayout>
\ No newline at end of file
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:baselineAligned="false"
android:orientation="vertical"
android:padding="10dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp"
app:cardElevation="0dp">
<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="match_parent"
android:layout_height="191dp"
android:layout_gravity="center_vertical" />
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/ad_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="19sp"
android:textStyle="bold"
tools:text="All You Can Wish For" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/ad_app_icon"
android:layout_width="17dp"
android:layout_height="17dp"
android:layout_gravity="center_vertical"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/ad_body"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="2dp"
android:layout_weight="1"
android:ellipsize="end"
android:includeFontPadding="false"
android:textColor="@color/black"
android:textSize="12sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dp"
android:text="Ad"
android:textColor="#868686"
android:textSize="12sp"
tools:ignore="HardcodedText" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/ad_call_to_action"
android:layout_width="150dp"
android:layout_height="29dp"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_storke_9d9d9d_7_5"
android:gravity="center"
android:textAllCaps="false"
android:textColor="@color/black"
android:textSize="14sp"
tools:text="Install" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="11dp"
android:background="#E5E6EB" />
</LinearLayout>
</com.google.android.gms.ads.nativead.NativeAdView>
\ 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