[android] Moved Banner class to ads package

This commit is contained in:
alexzatsepin 2017-03-30 15:16:41 +03:00 committed by Vladimir Byko-Ianko
parent b985ec1c19
commit 2f598c0db6
16 changed files with 71 additions and 34 deletions

View file

@ -44,7 +44,7 @@ JNI_OnLoad(JavaVM * jvm, void *)
g_httpHeaderClazz = jni::GetGlobalClassRef(env, "com/mapswithme/util/HttpClient$HttpHeader");
g_platformSocketClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/location/PlatformSocket");
g_utilsClazz = jni::GetGlobalClassRef(env, "com/mapswithme/util/Utils");
g_bannerClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/Banner");
g_bannerClazz = jni::GetGlobalClassRef(env, "com/mapswithme/maps/ads/Banner");
g_loggerFactoryClazz = jni::GetGlobalClassRef(env, "com/mapswithme/util/log/LoggerFactory");
return JNI_VERSION_1_6;

View file

@ -44,7 +44,7 @@ jobject CreateMapObject(JNIEnv * env, int mapObjectType, string const & title,
static jmethodID const ctorId =
jni::GetConstructorID(env, g_mapObjectClazz,
"(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;DDLjava/lang/"
"String;Lcom/mapswithme/maps/bookmarks/data/Banner;Z)V");
"String;Lcom/mapswithme/maps/ads/Banner;Z)V");
jobject mapObject =
env->NewObject(g_mapObjectClazz, ctorId, mapObjectType, jni::ToJavaString(env, title),
@ -69,7 +69,7 @@ jobject CreateMapObject(JNIEnv * env, place_page::Info const & info)
// String name, @Nullable String objectTitle, @NonNull Banner banner, boolean reachableByTaxi)
static jmethodID const ctorId = jni::GetConstructorID(
env, g_bookmarkClazz,
"(IILjava/lang/String;Ljava/lang/String;Lcom/mapswithme/maps/bookmarks/data/Banner;Z)V");
"(IILjava/lang/String;Ljava/lang/String;Lcom/mapswithme/maps/ads/Banner;Z)V");
auto const & bac = info.GetBookmarkAndCategory();
BookmarkCategory * cat = g_framework->NativeFramework()->GetBmCategory(bac.m_categoryIndex);

View file

@ -38,7 +38,7 @@ import com.mapswithme.maps.api.RoutePoint;
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.maps.bookmarks.BookmarkCategoriesActivity;
import com.mapswithme.maps.bookmarks.data.Banner;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.DownloaderActivity;

View file

@ -9,8 +9,8 @@ import android.support.annotation.NonNull;
*/
public interface AdTracker
{
void onViewShown(@NonNull BannerKey key);
void onViewHidden(@NonNull BannerKey key);
void onContentObtained(@NonNull BannerKey key);
void onViewShown(@NonNull Banner banner);
void onViewHidden(@NonNull Banner banner);
void onContentObtained(@NonNull Banner banner);
boolean isImpressionGood(@NonNull BannerKey key);
}

View file

@ -1,12 +1,15 @@
package com.mapswithme.maps.bookmarks.data;
package com.mapswithme.maps.ads;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
public final class Banner implements Parcelable
{
public static final Banner EMPTY = new Banner((String) null);
private static final int TYPE_FACEBOOK = 1;
private static final int TYPE_RB = 2;
public static final Creator<Banner> CREATOR = new Creator<Banner>()
{
@ -25,6 +28,10 @@ public final class Banner implements Parcelable
@Nullable
private final String mId;
//TODO: pass as argument constructor and read a correct value
private int mType = TYPE_FACEBOOK;
@Nullable
private BannerKey mKey;
public Banner(@Nullable String id)
{
@ -42,6 +49,31 @@ public final class Banner implements Parcelable
return mId;
}
@NonNull
BannerKey getKey()
{
if (mKey != null)
return mKey;
String provider;
switch (mType)
{
case TYPE_FACEBOOK:
provider = Providers.FACEBOOK;
break;
case TYPE_RB:
provider = Providers.MY_TARGET;
break;
default:
throw new AssertionError("Unsupported banner type: " + mType);
}
//noinspection ConstantConditions
mKey = new BannerKey(provider, mId);
return mKey;
}
@Override
public int describeContents()
{

View file

@ -86,6 +86,12 @@ abstract class CachingNativeAdLoader extends BaseNativeAdLoader
abstract void loadAdFromProvider(@NonNull Context context, @NonNull String bannerId);
/**
* Returns a provider name for this ad.
*/
@NonNull
abstract String getProvider();
void onError(@NonNull String bannerId, @NonNull MwmNativeAd ad, @NonNull NativeAdError error)
{
PENDING_REQUESTS.remove(new BannerKey(getProvider(), bannerId));

View file

@ -8,6 +8,7 @@ import com.mapswithme.util.log.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BrokenBarrierException;
public class DefaultAdTracker implements AdTracker, OnAdCacheModifiedListener
{
@ -17,32 +18,32 @@ public class DefaultAdTracker implements AdTracker, OnAdCacheModifiedListener
private final static Map<BannerKey, TrackInfo> TRACKS = new HashMap<>();
@Override
public void onViewShown(@NonNull BannerKey key)
public void onViewShown(@NonNull Banner banner)
{
LOGGER.d(TAG, "onViewShown bannerId = " + key);
TrackInfo info = TRACKS.get(key);
LOGGER.d(TAG, "onViewShown bannerId = " + banner.getKey());
TrackInfo info = TRACKS.get(banner.getKey());
if (info == null)
{
info = new TrackInfo();
TRACKS.put(key, info);
TRACKS.put(banner.getKey(), info);
}
info.setVisible(true);
}
@Override
public void onViewHidden(@NonNull BannerKey key)
public void onViewHidden(@NonNull Banner banner)
{
LOGGER.d(TAG, "onViewHidden bannerId = " + key);
TrackInfo info = TRACKS.get(key);
LOGGER.d(TAG, "onViewHidden bannerId = " + banner.getKey());
TrackInfo info = TRACKS.get(banner.getKey());
if (info != null)
info.setVisible(false);
}
@Override
public void onContentObtained(@NonNull BannerKey key)
public void onContentObtained(@NonNull Banner banner)
{
LOGGER.d(TAG, "onContentObtained bannerId = " + key);
TrackInfo info = TRACKS.get(key);
LOGGER.d(TAG, "onContentObtained bannerId = " + banner.getKey());
TrackInfo info = TRACKS.get(banner.getKey());
if (info == null)
throw new AssertionError("A track info must be put in a cache before a content is obtained");

View file

@ -60,7 +60,7 @@ class FacebookAdsLoader extends CachingNativeAdLoader implements AdListener
@NonNull
@Override
public String getProvider()
String getProvider()
{
return Providers.FACEBOOK;
}

View file

@ -61,7 +61,7 @@ class MyTargetAdsLoader extends CachingNativeAdLoader implements NativeAd.Native
@NonNull
@Override
public String getProvider()
String getProvider()
{
return Providers.MY_TARGET;
}

View file

@ -10,7 +10,7 @@ public interface NativeAdLoader
* Loads an ad for the specified banner id. A caller will be notified about loading through
* {@link NativeAdListener} interface.
*
* @param context An activity context.
* @param context An activity context.
* @param bannerId A banner id that ad will be loaded for.
*/
void loadAd(@NonNull Context context, @NonNull String bannerId);
@ -24,14 +24,9 @@ public interface NativeAdLoader
/**
* Indicated whether the ad for the specified banner is loading right now or not.
*
* @param bannerId A specified banner id.
* @return <code>true</code> if loading is in a progress, otherwise - <code>false</code>.
*/
boolean isAdLoading(@NonNull String bannerId);
/**
* Returns a name of native ad provider.
*/
@NonNull
String getProvider();
}

View file

@ -8,6 +8,7 @@ import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.util.Constants;
// TODO consider refactoring to remove hack with MapObject unmarshalling itself and Bookmark at the same time.

View file

@ -7,6 +7,8 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import com.mapswithme.maps.ads.Banner;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

View file

@ -10,7 +10,7 @@ import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.bookmarks.data.Banner;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.util.Config;

View file

@ -25,7 +25,7 @@ import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmFragment;
import com.mapswithme.maps.base.OnBackPressListener;
import com.mapswithme.maps.bookmarks.data.Banner;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.CountrySuggestFragment;
import com.mapswithme.maps.downloader.MapManager;

View file

@ -17,7 +17,7 @@ import com.mapswithme.maps.ads.MwmNativeAd;
import com.mapswithme.maps.ads.NativeAdError;
import com.mapswithme.maps.ads.NativeAdListener;
import com.mapswithme.maps.ads.NativeAdLoader;
import com.mapswithme.maps.bookmarks.data.Banner;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.util.Config;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.log.Logger;
@ -215,9 +215,9 @@ final class BannerController
return;
if (isVisible)
mAdTracker.onViewShown(Factory.createBannerKey(mAdsLoader.getProvider(), banner.getId()));
mAdTracker.onViewShown(banner);
else
mAdTracker.onViewHidden(Factory.createBannerKey(mAdsLoader.getProvider(), banner.getId()));
mAdTracker.onViewHidden(banner);
}
void onChangedVisibility(boolean isVisible)
@ -285,7 +285,7 @@ final class BannerController
loadIconAndOpenIfNeeded(ad, mBanner);
if (mAdTracker != null)
mAdTracker.onContentObtained(Factory.createBannerKey(mAdsLoader.getProvider(), mBanner.getId()));
mAdTracker.onContentObtained(mBanner);
if (mListener != null && mOpened)
mListener.onSizeChanged();

View file

@ -20,7 +20,7 @@ import com.mapswithme.maps.PrivateVariables;
import com.mapswithme.maps.ads.MwmNativeAd;
import com.mapswithme.maps.ads.NativeAdError;
import com.mapswithme.maps.api.ParsedMwmRequest;
import com.mapswithme.maps.bookmarks.data.Banner;
import com.mapswithme.maps.ads.Banner;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.maps.editor.Editor;