[android] Added Mopub_google network type to distinguish google ad coming from mopub in UI

[android] Refactored ad abstractions locations, i.e. move all our public interfaces back to our package from mopub
This commit is contained in:
Alexander Zatsepin 2018-07-13 14:43:42 +03:00 committed by Vlad Mihaylenko
parent 73501ccc2d
commit 4caeaca2be
10 changed files with 115 additions and 65 deletions

View file

@ -1,14 +1,17 @@
package com.mopub.nativeads;
package com.mapswithme.maps.ads;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mopub.nativeads.BaseNativeAd;
import com.mopub.nativeads.StaticNativeAd;
public abstract class AdDataAdapter<T extends BaseNativeAd>
{
@NonNull
private T mAd;
private AdDataAdapter(@NonNull T ad)
protected AdDataAdapter(@NonNull T ad)
{
mAd = ad;
}
@ -29,6 +32,8 @@ public abstract class AdDataAdapter<T extends BaseNativeAd>
public abstract String getCallToAction();
@Nullable
public abstract String getPrivacyInfoUrl();
@NonNull
public abstract NetworkType getType();
public static class StaticAd extends AdDataAdapter<StaticNativeAd>
{
@ -71,48 +76,12 @@ public abstract class AdDataAdapter<T extends BaseNativeAd>
{
return getAd().getPrivacyInformationIconClickThroughUrl();
}
}
public static class GoogleAd extends AdDataAdapter<GooglePlayServicesNative.GooglePlayServicesNativeAd>
{
public GoogleAd(@NonNull GooglePlayServicesNative.GooglePlayServicesNativeAd ad)
{
super(ad);
}
@Nullable
@NonNull
@Override
public String getTitle()
public NetworkType getType()
{
return getAd().getTitle();
}
@Nullable
@Override
public String getText()
{
return getAd().getText();
}
@Nullable
@Override
public String getIconImageUrl()
{
return getAd().getIconImageUrl();
}
@Nullable
@Override
public String getCallToAction()
{
return getAd().getCallToAction();
}
@Nullable
@Override
public String getPrivacyInfoUrl()
{
return null;
return NetworkType.MOPUB;
}
}
}

View file

@ -1,8 +1,10 @@
package com.mopub.nativeads;
package com.mapswithme.maps.ads;
import android.support.annotation.NonNull;
import android.view.View;
import com.mopub.nativeads.BaseNativeAd;
public interface AdRegistrator
{
void registerView(@NonNull BaseNativeAd ad, @NonNull View view);

View file

@ -54,4 +54,10 @@ abstract class BaseMwmNativeAd implements MwmNativeAd
abstract void register(@NonNull View view);
abstract void unregister(@NonNull View view);
@Override
public String toString()
{
return "Ad title: " + getTitle();
}
}

View file

@ -6,8 +6,6 @@ import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import com.mopub.nativeads.AdDataAdapter;
import com.mopub.nativeads.AdRegistrator;
import com.mopub.nativeads.NativeAd;
import com.mopub.nativeads.NativeImageHelper;
@ -16,7 +14,7 @@ public class MopubNativeAd extends CachedMwmNativeAd
@NonNull
private final NativeAd mNativeAd;
@NonNull
private final AdDataAdapter mAd;
private final AdDataAdapter mDataAdapter;
@Nullable
private AdRegistrator mAdRegistrator;
@ -25,7 +23,7 @@ public class MopubNativeAd extends CachedMwmNativeAd
{
super(timestamp);
mNativeAd = ad;
mAd = adData;
mDataAdapter = adData;
mAdRegistrator = registrator;
}
@ -40,27 +38,27 @@ public class MopubNativeAd extends CachedMwmNativeAd
@Override
public String getTitle()
{
return TextUtils.isEmpty(mAd.getTitle()) ? "" : mAd.getTitle();
return TextUtils.isEmpty(mDataAdapter.getTitle()) ? "" : mDataAdapter.getTitle();
}
@NonNull
@Override
public String getDescription()
{
return TextUtils.isEmpty(mAd.getText()) ? "" : mAd.getText();
return TextUtils.isEmpty(mDataAdapter.getText()) ? "" : mDataAdapter.getText();
}
@NonNull
@Override
public String getAction()
{
return TextUtils.isEmpty(mAd.getCallToAction()) ? "" : mAd.getCallToAction();
return TextUtils.isEmpty(mDataAdapter.getCallToAction()) ? "" : mDataAdapter.getCallToAction();
}
@Override
public void loadIcon(@NonNull View view)
{
NativeImageHelper.loadImageView(mAd.getIconImageUrl(), (ImageView) view);
NativeImageHelper.loadImageView(mDataAdapter.getIconImageUrl(), (ImageView) view);
}
@Override
@ -104,7 +102,7 @@ public class MopubNativeAd extends CachedMwmNativeAd
@Override
public String getPrivacyInfoUrl()
{
return mAd.getPrivacyInfoUrl();
return mDataAdapter.getPrivacyInfoUrl();
}
@Override
@ -127,6 +125,12 @@ public class MopubNativeAd extends CachedMwmNativeAd
@Override
public NetworkType getNetworkType()
{
return NetworkType.MOPUB;
return mDataAdapter.getType();
}
@Override
public String toString()
{
return super.toString() + ", mediated ad: " + mNativeAd.getBaseNativeAd();
}
}

View file

@ -10,9 +10,6 @@ import android.view.View;
*/
public interface MwmNativeAd
{
enum NetworkType{
FACEBOOK, GOOGLE, MOPUB, MYTARGET;
}
@NonNull
String getBannerId();

View file

@ -0,0 +1,16 @@
package com.mapswithme.maps.ads;
import android.support.annotation.LayoutRes;
import com.mapswithme.maps.R;
public enum NetworkType
{
FACEBOOK, GOOGLE, MOPUB, MOPUB_GOOGLE, MYTARGET;
@LayoutRes
public int getLayoutId()
{
return R.layout.place_page_banner;
}
}

View file

@ -20,6 +20,7 @@ import com.mapswithme.maps.ads.CompoundNativeAdLoader;
import com.mapswithme.maps.ads.MwmNativeAd;
import com.mapswithme.maps.ads.NativeAdError;
import com.mapswithme.maps.ads.NativeAdListener;
import com.mapswithme.maps.ads.NetworkType;
import com.mapswithme.util.Config;
import com.mapswithme.util.ThemeUtils;
import com.mapswithme.util.UiUtils;
@ -147,7 +148,7 @@ final class BannerController
}
else if (mCurrentAd != null)
{
UiUtils.showIf(mCurrentAd.getNetworkType() == MwmNativeAd.NetworkType.MOPUB, mAdChoices);
UiUtils.showIf(mCurrentAd.getNetworkType() == NetworkType.MOPUB, mAdChoices);
UiUtils.show(mIcon, mTitle, mMessage, mActionSmall, mActionLarge, mAdChoicesLabel);
if (mOpened)
UiUtils.hide(mActionSmall);
@ -347,7 +348,7 @@ final class BannerController
@Override
public void onAdLoaded(@NonNull MwmNativeAd ad)
{
LOGGER.d(TAG, "onAdLoaded, title = " + ad.getTitle() + " provider = " + ad.getProvider());
LOGGER.d(TAG, "onAdLoaded, ad = " + ad);
if (mBanners == null)
return;

View file

@ -2,18 +2,17 @@ package com.mopub.nativeads;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.google.android.gms.ads.formats.NativeAppInstallAd;
import com.google.android.gms.ads.formats.NativeAppInstallAdView;
import com.google.android.gms.ads.formats.NativeContentAd;
import com.google.android.gms.ads.formats.NativeContentAdView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.ads.AdRegistrator;
import com.mapswithme.util.UiUtils;
import com.mopub.nativeads.GooglePlayServicesNative.GooglePlayServicesNativeAd;
public class GoogleAdRegistrator implements AdRegistrator
class GoogleAdRegistrator implements AdRegistrator
{
@Override
public void registerView(@NonNull BaseNativeAd ad, @NonNull View view)

View file

@ -0,0 +1,57 @@
package com.mopub.nativeads;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapswithme.maps.ads.AdDataAdapter;
import com.mapswithme.maps.ads.NetworkType;
class GoogleDataAdapter extends AdDataAdapter<GooglePlayServicesNative.GooglePlayServicesNativeAd>
{
GoogleDataAdapter(@NonNull GooglePlayServicesNative.GooglePlayServicesNativeAd ad)
{
super(ad);
}
@Nullable
@Override
public String getTitle()
{
return getAd().getTitle();
}
@Nullable
@Override
public String getText()
{
return getAd().getText();
}
@Nullable
@Override
public String getIconImageUrl()
{
return getAd().getIconImageUrl();
}
@Nullable
@Override
public String getCallToAction()
{
return getAd().getCallToAction();
}
@Nullable
@Override
public String getPrivacyInfoUrl()
{
return null;
}
@NonNull
@Override
public NetworkType getType()
{
return NetworkType.MOPUB_GOOGLE;
}
}

View file

@ -4,6 +4,7 @@ import android.os.SystemClock;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapswithme.maps.ads.AdDataAdapter;
import com.mapswithme.maps.ads.CachedMwmNativeAd;
import com.mapswithme.maps.ads.MopubNativeAd;
import com.mopub.nativeads.GooglePlayServicesNative.GooglePlayServicesNativeAd;
@ -16,16 +17,14 @@ public class MopubNativeAdFactory
BaseNativeAd baseAd = ad.getBaseNativeAd();
if (baseAd instanceof StaticNativeAd)
{
return new MopubNativeAd(ad,
new AdDataAdapter.StaticAd((StaticNativeAd) baseAd),
null, SystemClock.elapsedRealtime());
return new MopubNativeAd(ad, new AdDataAdapter.StaticAd((StaticNativeAd) baseAd), null,
SystemClock.elapsedRealtime());
}
if (baseAd instanceof GooglePlayServicesNativeAd
&& ((GooglePlayServicesNativeAd) baseAd).isNativeContentAd())
{
return new MopubNativeAd(ad,
new AdDataAdapter.GoogleAd((GooglePlayServicesNativeAd) baseAd),
return new MopubNativeAd(ad, new GoogleDataAdapter((GooglePlayServicesNativeAd) baseAd),
new GoogleAdRegistrator(), SystemClock.elapsedRealtime());
}