From 6924a723b189c91bd78b9a470e22e4d953f8ccc8 Mon Sep 17 00:00:00 2001 From: alexzatsepin Date: Mon, 3 Apr 2017 16:35:25 +0300 Subject: [PATCH] [andorid] Fixed ad view registration --- .../mapswithme/maps/ads/BaseMwmNativeAd.java | 36 +++++++++++++++++++ .../maps/ads/CachedMwmNativeAd.java | 2 +- .../mapswithme/maps/ads/FacebookNativeAd.java | 11 ++---- .../mapswithme/maps/ads/MyTargetNativeAd.java | 6 ++-- .../widget/placepage/BannerController.java | 10 +++--- 5 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 android/src/com/mapswithme/maps/ads/BaseMwmNativeAd.java diff --git a/android/src/com/mapswithme/maps/ads/BaseMwmNativeAd.java b/android/src/com/mapswithme/maps/ads/BaseMwmNativeAd.java new file mode 100644 index 0000000000..2a06951325 --- /dev/null +++ b/android/src/com/mapswithme/maps/ads/BaseMwmNativeAd.java @@ -0,0 +1,36 @@ +package com.mapswithme.maps.ads; + +import android.support.annotation.NonNull; +import android.view.View; + +import com.mapswithme.maps.R; +import com.mapswithme.util.UiUtils; +import com.mapswithme.util.log.Logger; +import com.mapswithme.util.log.LoggerFactory; + +abstract class BaseMwmNativeAd implements MwmNativeAd +{ + private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC); + private static final String TAG = BaseMwmNativeAd.class.getSimpleName(); + + @Override + public void registerView(@NonNull View bannerView) + { + View largeAction = bannerView.findViewById(R.id.tv__action_large); + if (UiUtils.isVisible(largeAction)) + { + LOGGER.d(TAG, "Register the large action button for '" + getBannerId() + "'"); + registerViewForInteraction(largeAction); + return; + } + + View actionSmall = bannerView.findViewById(R.id.tv__action_small); + if (UiUtils.isVisible(actionSmall)) + { + LOGGER.d(TAG, "Register the small action button for '" + getBannerId() + "'"); + registerViewForInteraction(actionSmall); + } + } + + abstract void registerViewForInteraction(@NonNull View view); +} diff --git a/android/src/com/mapswithme/maps/ads/CachedMwmNativeAd.java b/android/src/com/mapswithme/maps/ads/CachedMwmNativeAd.java index 1fc0f52a3c..1778247924 100644 --- a/android/src/com/mapswithme/maps/ads/CachedMwmNativeAd.java +++ b/android/src/com/mapswithme/maps/ads/CachedMwmNativeAd.java @@ -1,6 +1,6 @@ package com.mapswithme.maps.ads; -abstract class CachedMwmNativeAd implements MwmNativeAd +abstract class CachedMwmNativeAd extends BaseMwmNativeAd { private final long mLoadedTime; diff --git a/android/src/com/mapswithme/maps/ads/FacebookNativeAd.java b/android/src/com/mapswithme/maps/ads/FacebookNativeAd.java index 1bba9e5503..cef0148ef5 100644 --- a/android/src/com/mapswithme/maps/ads/FacebookNativeAd.java +++ b/android/src/com/mapswithme/maps/ads/FacebookNativeAd.java @@ -5,10 +5,6 @@ import android.view.View; import android.widget.ImageView; import com.facebook.ads.NativeAd; -import com.mapswithme.maps.R; - -import java.util.ArrayList; -import java.util.List; class FacebookNativeAd extends CachedMwmNativeAd { @@ -62,12 +58,9 @@ class FacebookNativeAd extends CachedMwmNativeAd } @Override - public void registerView(@NonNull View bannerView) + void registerViewForInteraction(@NonNull View view) { - List clickableViews = new ArrayList<>(); - clickableViews.add(bannerView.findViewById(R.id.tv__action_small)); - clickableViews.add(bannerView.findViewById(R.id.tv__action_large)); - mAd.registerViewForInteraction(bannerView, clickableViews); + mAd.registerViewForInteraction(view); } @NonNull diff --git a/android/src/com/mapswithme/maps/ads/MyTargetNativeAd.java b/android/src/com/mapswithme/maps/ads/MyTargetNativeAd.java index b81de558fc..e9029600d9 100644 --- a/android/src/com/mapswithme/maps/ads/MyTargetNativeAd.java +++ b/android/src/com/mapswithme/maps/ads/MyTargetNativeAd.java @@ -4,7 +4,6 @@ import android.support.annotation.NonNull; import android.view.View; import android.widget.ImageView; -import com.mapswithme.maps.R; import com.my.target.ads.CustomParams; import com.my.target.nativeads.NativeAd; import com.my.target.nativeads.banners.NativePromoBanner; @@ -66,10 +65,9 @@ class MyTargetNativeAd extends CachedMwmNativeAd } @Override - public void registerView(@NonNull View bannerView) + void registerViewForInteraction(@NonNull View view) { - mAd.registerView(bannerView.findViewById(R.id.tv__action_small)); - mAd.registerView(bannerView.findViewById(R.id.tv__action_large)); + mAd.registerView(view); } @NonNull diff --git a/android/src/com/mapswithme/maps/widget/placepage/BannerController.java b/android/src/com/mapswithme/maps/widget/placepage/BannerController.java index 3841b42ae0..9ef2ebdd86 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/BannerController.java +++ b/android/src/com/mapswithme/maps/widget/placepage/BannerController.java @@ -174,14 +174,15 @@ final class BannerController mOpened = true; setFrameHeight(WRAP_CONTENT); + mMessage.setMaxLines(MAX_MESSAGE_LINES); + mTitle.setMaxLines(MAX_TITLE_LINES); + updateVisibility(); if (mCurrentAd != null) { loadIcon(mCurrentAd); Statistics.INSTANCE.trackPPBanner(PP_BANNER_SHOW, mCurrentAd, 1); + mCurrentAd.registerView(mFrame); } - mMessage.setMaxLines(MAX_MESSAGE_LINES); - mTitle.setMaxLines(MAX_TITLE_LINES); - updateVisibility(); } @@ -196,7 +197,8 @@ final class BannerController mMessage.setMaxLines(MIN_MESSAGE_LINES); mTitle.setMaxLines(MIN_TITLE_LINES); updateVisibility(); - + if (mCurrentAd != null) + mCurrentAd.registerView(mFrame); return true; }