Commit 28bc1b76 authored by wanglei's avatar wanglei

...

parent af399264
...@@ -27,7 +27,7 @@ object AdMaxEvent { ...@@ -27,7 +27,7 @@ object AdMaxEvent {
obj.put("networkname", ad?.networkName) obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement) obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement) obj.put("networkplacement", ad?.networkPlacement)
obj.put("requestLatencyMillis", ad?.requestLatencyMillis) obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue) obj.put("valueMicros", ad?.revenue)
if (error == null) { if (error == null) {
obj.put("status", "1") obj.put("status", "1")
...@@ -50,7 +50,7 @@ object AdMaxEvent { ...@@ -50,7 +50,7 @@ object AdMaxEvent {
obj.put("networkname", ad?.networkName) obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement) obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement) obj.put("networkplacement", ad?.networkPlacement)
obj.put("requestLatencyMillis", ad?.requestLatencyMillis) obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue) obj.put("valueMicros", ad?.revenue)
if(!adUnit.equals("nativeAd")){ if(!adUnit.equals("nativeAd")){
EventUtils.event("ad_click", ext = obj) EventUtils.event("ad_click", ext = obj)
...@@ -71,7 +71,7 @@ object AdMaxEvent { ...@@ -71,7 +71,7 @@ object AdMaxEvent {
obj.put("networkname", ad?.networkName) obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement) obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement) obj.put("networkplacement", ad?.networkPlacement)
obj.put("requestLatencyMillis", ad?.requestLatencyMillis) obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue) obj.put("valueMicros", ad?.revenue)
if(!adUnit.equals("nativeAd")){ if(!adUnit.equals("nativeAd")){
EventUtils.event("ad_show", ext = obj) EventUtils.event("ad_show", ext = obj)
......
...@@ -31,8 +31,9 @@ object AdMaxNativeUtils { ...@@ -31,8 +31,9 @@ object AdMaxNativeUtils {
//加载展示监听 //加载展示监听
nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() { nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() {
override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView?, ad: MaxAd) { override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView?, ad: MaxAd) {
LogEx.logDebug(TAG,"onNativeAdLoaded")
// Cleanup any pre-existing native ad to prevent memory leaks. // Cleanup any pre-existing native ad to prevent memory leaks.
if (nativeAd != null) { if (nativeAd?.nativeAd?.isExpired == true) {
nativeAdLoader.destroy(nativeAd) nativeAdLoader.destroy(nativeAd)
} }
...@@ -44,6 +45,7 @@ object AdMaxNativeUtils { ...@@ -44,6 +45,7 @@ object AdMaxNativeUtils {
override fun onNativeAdLoadFailed(p0: String, p1: MaxError) { override fun onNativeAdLoadFailed(p0: String, p1: MaxError) {
super.onNativeAdLoadFailed(p0, p1) super.onNativeAdLoadFailed(p0, p1)
LogEx.logDebug(TAG,"onNativeAdLoadFailed")
AdDisplayUtils.getInstance().incrementAdRequestFailCount() AdDisplayUtils.getInstance().incrementAdRequestFailCount()
val obj2 = JSONObject() val obj2 = JSONObject()
obj2.put("reason", "no_ad") obj2.put("reason", "no_ad")
...@@ -53,6 +55,7 @@ object AdMaxNativeUtils { ...@@ -53,6 +55,7 @@ object AdMaxNativeUtils {
override fun onNativeAdClicked(p0: MaxAd) { override fun onNativeAdClicked(p0: MaxAd) {
super.onNativeAdClicked(p0) super.onNativeAdClicked(p0)
LogEx.logDebug(TAG,"onNativeAdClicked")
AdDisplayUtils.getInstance().incrementAdClickCount() AdDisplayUtils.getInstance().incrementAdClickCount()
nativeAd?.let { AdMaxEvent.clickAd(it, "nativeAd") } nativeAd?.let { AdMaxEvent.clickAd(it, "nativeAd") }
AdmobCommonUtils.isMultiClick(nativeAd) AdmobCommonUtils.isMultiClick(nativeAd)
...@@ -77,15 +80,28 @@ object AdMaxNativeUtils { ...@@ -77,15 +80,28 @@ object AdMaxNativeUtils {
} }
private fun createNativeAdView(context: Context): MaxNativeAdView { private fun createNativeAdView(context: Context): MaxNativeAdView {
val binder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.layout_max_native_custom)
.setTitleTextViewId(R.id.title_text_view) // val binder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.layout_max_native_custom)
.setBodyTextViewId(R.id.body_text_view) // .setTitleTextViewId(R.id.title_text_view)
.setAdvertiserTextViewId(R.id.advertiser_text_view) // .setBodyTextViewId(R.id.body_text_view)
.setIconImageViewId(R.id.icon_image_view) // .setAdvertiserTextViewId(R.id.advertiser_text_view)
.setMediaContentViewGroupId(R.id.media_view_container) // .setIconImageViewId(R.id.icon_image_view)
.setOptionsContentViewGroupId(R.id.options_view) // .setMediaContentViewGroupId(R.id.media_view_container)
.setStarRatingContentViewGroupId(R.id.star_rating_view) // .setOptionsContentViewGroupId(R.id.options_view)
.setCallToActionButtonId(R.id.cta_button) // .setStarRatingContentViewGroupId(R.id.star_rating_view)
// .setCallToActionButtonId(R.id.cta_button)
// .build()
// return MaxNativeAdView(binder, context)
val binder: MaxNativeAdViewBinder = MaxNativeAdViewBinder.Builder(R.layout.layout_max_native_small)
.setTitleTextViewId(R.id.ad_headline)
.setBodyTextViewId(R.id.ad_body)
// .setAdvertiserTextViewId(R.id.advertiser_text_view)
.setIconImageViewId(R.id.ad_app_icon)
.setMediaContentViewGroupId(R.id.ad_media)
// .setOptionsContentViewGroupId(R.id.options_view)
// .setStarRatingContentViewGroupId(R.id.star_rating_view)
.setCallToActionButtonId(R.id.ad_call_to_action)
.build() .build()
return MaxNativeAdView(binder, context) return MaxNativeAdView(binder, context)
} }
...@@ -113,8 +129,9 @@ object AdMaxNativeUtils { ...@@ -113,8 +129,9 @@ object AdMaxNativeUtils {
val adView = createNativeAdView(activity) val adView = createNativeAdView(activity)
parent.isVisible = true parent.isVisible = true
nativeAdLoader.render(adView, nativeAd) nativeAdLoader.render(adView, nativeAd)
parent.removeAllViews()
parent.addView(adView) parent.addView(adView)
nativeAd?.let { AdMaxEvent.showAd(it, "nativeAd", activity) } nativeAd?.let { AdMaxEvent.showAd(it, "nativeAd") }
AdDisplayUtils.getInstance().incrementAdDisplayCount() AdDisplayUtils.getInstance().incrementAdDisplayCount()
} }
} }
......
...@@ -105,9 +105,14 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() { ...@@ -105,9 +105,14 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>() {
animatorSet.pause() animatorSet.pause()
} }
var resumeTime = 0
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
animatorSet.resume() animatorSet.resume()
if (resumeTime != 0) {
AdmobMaxHelper.admobMaxShowNativeAd(requireActivity(), binding.flAd)
resumeTime++
}
} }
} }
\ 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