Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Donskoy <donskdmitry@mail.ru>2018-09-25 18:43:26 +0300
committerAleksandr Zatsepin <alexzatsepin@users.noreply.github.com>2018-09-27 15:40:37 +0300
commit55b9ffe8d9c524519846b96746734127afc2e6fd (patch)
tree7e358507b0c1442a08fdeee459463c860d111cc3 /partners_api
parent9a6509614971ad8501cf7c2deb6c2d446aa561df (diff)
[android] Supported enabled flag for ad provider, modified container item
Diffstat (limited to 'partners_api')
-rw-r--r--partners_api/ads_engine.cpp61
-rw-r--r--partners_api/ads_engine.hpp10
2 files changed, 26 insertions, 45 deletions
diff --git a/partners_api/ads_engine.cpp b/partners_api/ads_engine.cpp
index e5e9f63b95..73bc25f2f3 100644
--- a/partners_api/ads_engine.cpp
+++ b/partners_api/ads_engine.cpp
@@ -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
diff --git a/partners_api/ads_engine.hpp b/partners_api/ads_engine.hpp
index 3cb41ba62b..0f7f3f4623 100644
--- a/partners_api/ads_engine.hpp
+++ b/partners_api/ads_engine.hpp
@@ -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;