[android] Supported enabled flag for ad provider, modified container item

This commit is contained in:
Dmitry Donskoy 2018-09-25 18:43:26 +03:00 committed by Aleksandr Zatsepin
parent 9a65096149
commit 55b9ffe8d9
8 changed files with 36 additions and 71 deletions

View file

@ -1135,12 +1135,13 @@ Java_com_mapswithme_maps_Framework_nativeGetRouteFollowingInfo(JNIEnv * env, jcl
return result;
}
JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeAddAdProvider(JNIEnv * env, jclass,
jint type, jint place)
JNIEXPORT void JNICALL Java_com_mapswithme_maps_Framework_nativeDisableAdProvider(JNIEnv * env,
jclass, jint type,
jint place)
{
auto const & bannerType = static_cast<ads::Banner::Type>(type);
auto const & bannerPlace = static_cast<ads::Banner::Place>(place);
frm()->AddAdProvider(bannerType, bannerPlace);
frm()->DisableAdProvider(bannerType, bannerPlace);
}
JNIEXPORT jintArray JNICALL

View file

@ -224,9 +224,9 @@ public class Framework
return FilterUtils.RATING_ANY;
}
public static void addAdProvider(@NonNull Banner.Type type)
public static void setAdProviderDisabled(@NonNull Banner.Type type)
{
nativeAddAdProvider(type.ordinal(), Banner.Place.DEFAULT.ordinal());
nativeDisableAdProvider(type.ordinal(), Banner.Place.DEFAULT.ordinal());
}
public static native void nativeShowTrackRect(long track);
@ -489,5 +489,5 @@ public class Framework
private static native void nativeTipsShown(int tipType, int event);
private static native void nativeAddAdProvider(int provider, int bannerPlace);
private static native void nativeDisableAdProvider(int provider, int bannerPlace);
}

View file

@ -20,7 +20,6 @@ class EventLoggerAggregator extends ContextDependentEventLogger
mLoggers.put(LibnotifyEventLogger.class, new LibnotifyEventLogger(application));
mLoggers.put(PushWooshEventLogger.class, new PushWooshEventLogger(application));
mLoggers.put(MyTrackerEventLogger.class, new MyTrackerEventLogger(application));
mLoggers.put(MyTargetEventLogger.class, new MyTargetEventLogger(application));
mLoggers.put(FlurryEventLogger.class, new FlurryEventLogger(application));
}

View file

@ -1,16 +0,0 @@
package com.mapswithme.maps.content;
import android.app.Application;
import android.support.annotation.NonNull;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.ads.Banner;
class MyTargetEventLogger extends DefaultEventLogger
{
MyTargetEventLogger(@NonNull Application application)
{
super(application);
Framework.addAdProvider(Banner.Type.TYPE_RB);
}
}

View file

@ -3336,10 +3336,10 @@ ads::Engine const & Framework::GetAdsEngine() const
return *m_adsEngine;
}
void Framework::AddAdProvider(ads::Banner::Type const type, ads::Banner::Place const place)
void Framework::DisableAdProvider(ads::Banner::Type const type, ads::Banner::Place const place)
{
ASSERT(m_adsEngine, ());
m_adsEngine.get()->AddAdProvider(type, place);
m_adsEngine.get()->DisableAdProvider(type, place);
}
void Framework::RunUITask(function<void()> fn)

View file

@ -352,7 +352,7 @@ public:
void VisualizeCityBoundariesInRect(m2::RectD const & rect);
ads::Engine const & GetAdsEngine() const;
void AddAdProvider(ads::Banner::Type const type, ads::Banner::Place const place);
void DisableAdProvider(ads::Banner::Type const type, ads::Banner::Place const place);
public:
// SearchAPI::Delegate overrides:

View file

@ -14,6 +14,7 @@ namespace ads
Engine::Engine()
{
// The banner systems are placed by priority. First has a top priority.
m_banners.emplace_back(Banner::Type::RB, std::make_unique<Rb>());
m_banners.emplace_back(Banner::Type::Mopub, std::make_unique<Mopub>());
m_searchBanners.emplace_back(Banner::Type::Facebook, std::make_unique<Facebook>());
@ -27,7 +28,7 @@ bool Engine::HasBanner(feature::TypesHolder const & types,
{
for (auto const & item : m_banners)
{
if (item.m_container->HasBanner(types, countryId, userLanguage))
if (item.m_enabled && item.m_container->HasBanner(types, countryId, userLanguage))
return true;
}
}
@ -43,14 +44,17 @@ std::vector<Banner> Engine::GetBanners(feature::TypesHolder const & types,
for (auto const & item : m_banners)
{
for (auto const & countryId : countryIds)
if (item.m_enabled)
{
auto const bannerId = item.m_container->GetBannerId(types, countryId, userLanguage);
// We need to add banner for every banner system just once.
if (!bannerId.empty())
for (auto const & countryId : countryIds)
{
result.emplace_back(item.m_type, bannerId);
break;
auto const bannerId = item.m_container->GetBannerId(types, countryId, userLanguage);
// We need to add banner for every banner system just once.
if (!bannerId.empty())
{
result.emplace_back(item.m_type, bannerId);
break;
}
}
}
}
@ -62,7 +66,7 @@ bool Engine::HasSearchBanner() const
{
for (auto const & item : m_searchBanners)
{
if (item.m_container->HasSearchBanner())
if (item.m_enabled && item.m_container->HasSearchBanner())
return true;
}
@ -84,46 +88,23 @@ std::vector<Banner> Engine::GetSearchBanners() const
return result;
}
void Engine::RemoveAdProvider(Banner::Type const type, Banner::Place const place)
void Engine::DisableAdProvider(Banner::Type const type, Banner::Place const place)
{
RemoveAdProviderInternal(place == Banner::Place::Search ? m_searchBanners : m_banners, type);
SetAdProviderEnabled(place == Banner::Place::Search ? m_searchBanners : m_banners, type, false);
}
void Engine::AddAdProvider(Banner::Type const type, Banner::Place const place)
void Engine::EnableAdProvider(Banner::Type const type, Banner::Place place)
{
AddAdProviderInternal(place == Banner::Place::Search ? m_searchBanners : m_banners, type);
SetAdProviderEnabled(place == Banner::Place::Search ? m_searchBanners : m_banners, type, true);
}
void Engine::RemoveAdProviderInternal(std::vector<Engine::ContainerItem> & banners,
Banner::Type const type)
void Engine::SetAdProviderEnabled(std::vector<Engine::ContainerItem> & banners,
Banner::Type const type, bool const isEnabled)
{
banners.erase(std::remove_if(banners.begin(), banners.end(),
[type](ContainerItem const & each) { return each.m_type == type; }),
banners.end());
}
void Engine::AddAdProviderInternal(std::vector<ContainerItem> & banners, Banner::Type const type)
{
auto const hasItemIterator =
std::find_if(std::begin(banners), std::end(banners),
[type](ContainerItem const & each) { return each.m_type == type; });
if (hasItemIterator != std::end(banners))
return;
switch (type)
for (auto & item : banners)
{
case Banner::Type::Facebook:
banners.emplace_back(Banner::Type::Facebook, std::make_unique<Facebook>());
break;
case Banner::Type::RB: banners.emplace_back(Banner::Type::RB, std::make_unique<Rb>()); break;
case Banner::Type::Mopub:
banners.emplace_back(Banner::Type::Mopub, std::make_unique<Mopub>());
break;
case Banner::Type::Google:
banners.emplace_back(Banner::Type::None, std::make_unique<Google>());
break;
case Banner::Type::None: break;
if (item.m_type == type)
item.m_enabled = isEnabled;
}
}
} // namespace ads

View file

@ -25,8 +25,8 @@ public:
std::vector<Banner> GetBanners(feature::TypesHolder const & types,
storage::TCountriesVec const & countryIds,
std::string const & userLanguage) const;
void AddAdProvider(Banner::Type const type, Banner::Place bannerPlace);
void RemoveAdProvider(Banner::Type const type, Banner::Place const place);
void EnableAdProvider(Banner::Type const type, Banner::Place bannerPlace);
void DisableAdProvider(Banner::Type const type, Banner::Place const place);
bool HasSearchBanner() const;
std::vector<Banner> GetSearchBanners() const;
@ -39,13 +39,13 @@ private:
: m_type(type), m_container(std::move(container))
{
}
bool m_enabled = true;
Banner::Type m_type;
ContainerPtr m_container;
};
void RemoveAdProviderInternal(std::vector<ContainerItem> & banners, Banner::Type const type);
void AddAdProviderInternal(std::vector<ContainerItem> & banners, Banner::Type const type);
void SetAdProviderEnabled(std::vector<ContainerItem> & banners, Banner::Type const type,
bool const isEnabled);
std::vector<ContainerItem> m_banners;
std::vector<ContainerItem> m_searchBanners;