[partners] Refactored downloader banner

This commit is contained in:
r.kuznetsov 2019-05-24 14:56:25 +03:00 committed by Arsentiy Milchakov
parent 4bfcdf14cb
commit b3618bd893
11 changed files with 175 additions and 47 deletions

View file

@ -14,6 +14,7 @@
#include "partners_api/ads_engine.hpp"
#include "partners_api/banner.hpp"
#include "partners_api/booking_block_params.hpp"
#include "partners_api/downloader_promo.hpp"
#include "partners_api/mopub_ads.hpp"
#include "partners_api/megafon_countries.hpp"
@ -1919,16 +1920,27 @@ Java_com_mapswithme_maps_Framework_nativeMoPubInitializationBannerId(JNIEnv * en
return jni::ToJavaString(env, ads::Mopub::InitializationBannerId());
}
JNIEXPORT jboolean JNICALL
Java_com_mapswithme_maps_Framework_nativeHasMegafonDownloaderBanner(JNIEnv * env, jclass,
jstring mwmId)
JNIEXPORT jobject JNICALL
Java_com_mapswithme_maps_Framework_nativeGetDownloaderPromoBanner(JNIEnv * env, jclass,
jstring mwmId)
{
static jclass const downloaderPromoBannerClass = jni::GetGlobalClassRef(env,
"com/mapswithme/maps/downloader/DownloaderPromoBanner");
// Java signature : DownloaderPromoBanner(@DownloaderPromoType int type, @NonNull String url)
static jmethodID const downloaderPromoBannerConstructor = jni::GetConstructorID(env,
downloaderPromoBannerClass, "(ILjava/lang/String;)V");
auto const & purchase = frm()->GetPurchase();
if (purchase && purchase->IsSubscriptionActive(SubscriptionType::RemoveAds))
return static_cast<jboolean>(false);
return static_cast<jboolean>(ads::HasMegafonDownloaderBanner(frm()->GetStorage(),
jni::ToNativeString(env, mwmId),
languages::GetCurrentNorm()));
bool const hasSubscription = purchase != nullptr &&
purchase->IsSubscriptionActive(SubscriptionType::RemoveAds);
auto const banner = promo::DownloaderPromo::GetBanner(frm()->GetStorage(),
jni::ToNativeString(env, mwmId),
languages::GetCurrentNorm(),
hasSubscription);
jni::TScopedLocalRef const url(env, jni::ToJavaString(env, banner.m_url));
return env->NewObject(downloaderPromoBannerClass, downloaderPromoBannerConstructor,
static_cast<jint>(banner.m_type), url.get());
}
JNIEXPORT jboolean JNICALL
@ -1948,12 +1960,6 @@ Java_com_mapswithme_maps_Framework_nativeHasMegafonCategoryBanner(JNIEnv * env,
languages::GetCurrentNorm()));
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_Framework_nativeGetMegafonDownloaderBannerUrl(JNIEnv * env, jclass)
{
return jni::ToJavaString(env, ads::GetMegafonDownloaderBannerUrl());
}
JNIEXPORT jstring JNICALL
Java_com_mapswithme_maps_Framework_nativeGetMegafonCategoryBannerUrl(JNIEnv * env, jclass)
{

View file

@ -19,6 +19,7 @@ import com.mapswithme.maps.auth.AuthorizationListener;
import com.mapswithme.maps.background.NotificationCandidate;
import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.downloader.DownloaderPromoBanner;
import com.mapswithme.maps.gdpr.UserBindingListener;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.routing.RouteMarkData;
@ -477,10 +478,8 @@ public class Framework
@NonNull
public static native String nativeMoPubInitializationBannerId();
public static native boolean nativeHasMegafonDownloaderBanner(@NonNull String mwmId);
@NonNull
public static native String nativeGetMegafonDownloaderBannerUrl();
public static native DownloaderPromoBanner nativeGetDownloaderPromoBanner(@NonNull String mwmId);
public static native boolean nativeHasMegafonCategoryBanner();

View file

@ -0,0 +1,41 @@
package com.mapswithme.maps.downloader;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Promo banner for on-map downloader. Created by native code.
*/
public final class DownloaderPromoBanner
{
@Retention(RetentionPolicy.SOURCE)
@IntDef({ DOWNLOADER_PROMO_TYPE_NO_PROMO, DOWNLOADER_PROMO_TYPE_BOOKMARK_CATALOG,
DOWNLOADER_PROMO_TYPE_MEGAFON })
public @interface DownloaderPromoType {}
// Must be corresponded to DownloaderPromoType in downloader_promo.hpp
public static final int DOWNLOADER_PROMO_TYPE_NO_PROMO = 0;
public static final int DOWNLOADER_PROMO_TYPE_BOOKMARK_CATALOG = 1;
public static final int DOWNLOADER_PROMO_TYPE_MEGAFON = 2;
@DownloaderPromoType
private final int mType;
@NonNull
private final String mUrl;
public DownloaderPromoBanner(@DownloaderPromoType int type, @NonNull String url)
{
this.mType = type;
this.mUrl = url;
}
@DownloaderPromoType
public int getType() { return mType; }
@NonNull
public String getUrl() { return mUrl; }
}

View file

@ -42,6 +42,9 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
@Nullable
private CountryItem mCurrentCountry;
@Nullable
private DownloaderPromoBanner mPromoBanner;
private final MapManager.StorageCallback mStorageCallback = new MapManager.StorageCallback()
{
@Override
@ -237,7 +240,8 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
});
mFrame.findViewById(R.id.banner_button).setOnClickListener(v -> {
Utils.openUrl(mActivity, Framework.nativeGetMegafonDownloaderBannerUrl());
if (mPromoBanner != null && mPromoBanner.getType() != DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_NO_PROMO)
Utils.openUrl(mActivity, mPromoBanner.getUrl());
});
}
@ -246,14 +250,23 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
if (mCurrentCountry == null || TextUtils.isEmpty(mCurrentCountry.id))
return;
if (!Framework.nativeHasMegafonDownloaderBanner(mCurrentCountry.id))
mPromoBanner = Framework.nativeGetDownloaderPromoBanner(mCurrentCountry.id);
if (mPromoBanner.getType() == DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_NO_PROMO)
return;
boolean enqueued = mCurrentCountry.status == CountryItem.STATUS_ENQUEUED;
boolean progress = mCurrentCountry.status == CountryItem.STATUS_PROGRESS;
boolean applying = mCurrentCountry.status == CountryItem.STATUS_APPLYING;
if (mPromoBanner.getType() == DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_MEGAFON)
{
boolean enqueued = mCurrentCountry.status == CountryItem.STATUS_ENQUEUED;
boolean progress = mCurrentCountry.status == CountryItem.STATUS_PROGRESS;
boolean applying = mCurrentCountry.status == CountryItem.STATUS_APPLYING;
UiUtils.showIf(enqueued || progress || applying, mFrame, R.id.banner);
UiUtils.showIf(enqueued || progress || applying, mFrame, R.id.banner);
}
else
{
// TODO: implement me.
throw new RuntimeException("Not implemented yet");
}
}
@Override

View file

@ -20,7 +20,7 @@
#include "platform/local_country_file_utils.hpp"
#include "partners_api/megafon_countries.hpp"
#include "partners_api/downloader_promo.hpp"
namespace
{
@ -41,17 +41,12 @@ BOOL canAutoDownload(storage::CountryId const & countryId)
return !platform::migrate::NeedMigrate();
}
BOOL shouldShowBanner(std::string const & mwmId)
promo::DownloaderPromoBanner getPromoBanner(std::string const & mwmId)
{
auto const & purchase = GetFramework().GetPurchase();
if (purchase && purchase->IsSubscriptionActive(SubscriptionType::RemoveAds))
return NO;
return ads::HasMegafonDownloaderBanner(GetFramework().GetStorage(), mwmId, languages::GetCurrentNorm());
}
NSString * getBannerURL()
{
return @(ads::GetMegafonDownloaderBannerUrl().c_str());
bool const hasRemoveAdsSubscription = purchase && purchase->IsSubscriptionActive(SubscriptionType::RemoveAds);
return promo::DownloaderPromo::GetBanner(GetFramework().GetStorage(), mwmId, languages::GetCurrentNorm(),
hasRemoveAdsSubscription);
}
} // namespace
@ -82,6 +77,7 @@ using namespace storage;
{
CountryId m_countryId;
CountryId m_autoDownloadCountryId;
promo::DownloaderPromoBanner m_promoBanner;
}
+ (instancetype)dialogForController:(MapViewController *)controller
@ -289,7 +285,9 @@ using namespace storage;
- (void)showBannerIfNeeded
{
if (shouldShowBanner(m_countryId) && self.bannerView.hidden)
m_promoBanner = getPromoBanner(m_countryId);
// TODO: implement other banner types.
if (m_promoBanner.m_type == promo::DownloaderPromoType::Megafon && self.bannerView.hidden)
{
[self layoutIfNeeded];
self.bannerVisibleConstraint.priority = UILayoutPriorityDefaultHigh;
@ -358,7 +356,10 @@ using namespace storage;
- (IBAction)bannerAction
{
NSURL * bannerURL = [NSURL URLWithString:getBannerURL()];
if (m_promoBanner.m_url.empty())
return;
NSURL * bannerURL = [NSURL URLWithString:@(m_promoBanner.m_url.c_str())];
SFSafariViewController * safari = [[SFSafariViewController alloc] initWithURL:bannerURL];
[self.controller presentViewController:safari animated:YES completion:nil];
}

View file

@ -16,8 +16,6 @@ set(
benchmark_tools.cpp
booking_availability_filter.cpp
booking_availability_filter.hpp
promo_delegate.cpp
promo_delegate.hpp
booking_filter.hpp
booking_filter_cache.cpp
booking_filter_cache.hpp
@ -97,6 +95,8 @@ set(
power_management/power_manager.hpp
power_management/power_management_schemas.cpp
power_management/power_management_schemas.hpp
promo_delegate.cpp
promo_delegate.hpp
purchase.cpp
purchase.hpp
reachable_by_taxi_checker.cpp

View file

@ -16,8 +16,8 @@ set(
booking_block_params.cpp
booking_block_params.hpp
booking_params_base.hpp
promo_api.cpp
promo_api.hpp
downloader_promo.cpp
downloader_promo.hpp
facebook_ads.cpp
facebook_ads.hpp
google_ads.cpp
@ -34,6 +34,8 @@ set(
opentable_api.hpp
partners.cpp
partners.hpp
promo_api.cpp
promo_api.hpp
rb_ads.cpp
rb_ads.hpp
rutaxi_api.cpp

View file

@ -0,0 +1,20 @@
#include "partners_api/downloader_promo.hpp"
#include "partners_api/megafon_countries.hpp"
namespace promo
{
// static
DownloaderPromoBanner DownloaderPromo::GetBanner(storage::Storage const & storage,
std::string const & mwmId,
std::string const & currentLocale,
bool hasRemoveAdsSubscription)
{
if (!hasRemoveAdsSubscription && ads::HasMegafonDownloaderBanner(storage, mwmId, currentLocale))
return {DownloaderPromoType::Megafon, ads::GetMegafonDownloaderBannerUrl()};
// TODO: add bookmark catalog banner.
return {};
}
} // namespace promo

View file

@ -0,0 +1,38 @@
#pragma once
#include "storage/storage.hpp"
#include <cstdint>
#include <string>
namespace promo
{
// Do not change the order.
enum class DownloaderPromoType : uint8_t
{
NoPromo = 0,
BookmarkCatalog = 1,
Megafon = 2
};
struct DownloaderPromoBanner
{
DownloaderPromoBanner() = default;
DownloaderPromoBanner(DownloaderPromoType type, std::string const & url)
: m_type(type)
, m_url(url)
{}
DownloaderPromoType m_type = DownloaderPromoType::NoPromo;
std::string m_url;
};
class DownloaderPromo
{
public:
static DownloaderPromoBanner GetBanner(storage::Storage const & storage,
std::string const & mwmId,
std::string const & currentLocale,
bool hasRemoveAdsSubscription);
};
} // namespace promo

View file

@ -6,12 +6,12 @@ set(
SRC
ads_engine_tests.cpp
booking_tests.cpp
promo_tests.cpp
facebook_tests.cpp
google_tests.cpp
maxim_tests.cpp
megafon_countries_tests.cpp
mopub_tests.cpp
promo_tests.cpp
rb_tests.cpp
rutaxi_tests.cpp
taxi_engine_tests.cpp

View file

@ -66,6 +66,8 @@
4566605120D91FEE0085E8C1 /* megafon_countries.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 4566604F20D91FEE0085E8C1 /* megafon_countries.hpp */; };
4566605320D920000085E8C1 /* megafon_countries_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4566605220D920000085E8C1 /* megafon_countries_tests.cpp */; };
4566605520D920220085E8C1 /* libstorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4566605420D920220085E8C1 /* libstorage.a */; };
45BABC33229812830060FA53 /* downloader_promo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45BABC31229812820060FA53 /* downloader_promo.cpp */; };
45BABC34229812830060FA53 /* downloader_promo.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 45BABC32229812830060FA53 /* downloader_promo.hpp */; };
45C380772094C5B400C18D81 /* partners.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 45C380752094C5B400C18D81 /* partners.cpp */; };
45C380782094C5B400C18D81 /* partners.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 45C380762094C5B400C18D81 /* partners.hpp */; };
BB1956E61F543D7C003ECE6C /* locals_api.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BB1956E41F543D7B003ECE6C /* locals_api.cpp */; };
@ -158,6 +160,8 @@
4566604F20D91FEE0085E8C1 /* megafon_countries.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = megafon_countries.hpp; sourceTree = "<group>"; };
4566605220D920000085E8C1 /* megafon_countries_tests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = megafon_countries_tests.cpp; sourceTree = "<group>"; };
4566605420D920220085E8C1 /* libstorage.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libstorage.a; sourceTree = BUILT_PRODUCTS_DIR; };
45BABC31229812820060FA53 /* downloader_promo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = downloader_promo.cpp; sourceTree = "<group>"; };
45BABC32229812830060FA53 /* downloader_promo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = downloader_promo.hpp; sourceTree = "<group>"; };
45C380752094C5B400C18D81 /* partners.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = partners.cpp; sourceTree = "<group>"; };
45C380762094C5B400C18D81 /* partners.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = partners.hpp; sourceTree = "<group>"; };
BB1956E41F543D7B003ECE6C /* locals_api.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = locals_api.cpp; sourceTree = "<group>"; };
@ -241,13 +245,6 @@
F6B5363B1DA520B20067EEA5 /* partners_api */ = {
isa = PBXGroup;
children = (
3D18DC4022956DFA00A583A6 /* promo_api.cpp */,
3D18DC3F22956DFA00A583A6 /* promo_api.hpp */,
3D15ACE5214AA1B000F725D5 /* rutaxi_api.cpp */,
3D15ACE4214AA1B000F725D5 /* rutaxi_api.hpp */,
3D15ACE3214AA1AF00F725D5 /* taxi_delegate.hpp */,
3DCD415120DAB33700143533 /* booking_block_params.cpp */,
3DCD415220DAB33700143533 /* booking_block_params.hpp */,
346E888F1E9D087400D4CE9B /* ads_base.cpp */,
346E88901E9D087400D4CE9B /* ads_base.hpp */,
346E88911E9D087400D4CE9B /* ads_engine.cpp */,
@ -257,7 +254,11 @@
F6B5363D1DA520E40067EEA5 /* booking_api.hpp */,
3D4E997B1FB439260025B48C /* booking_availability_params.cpp */,
3D4E997A1FB439260025B48C /* booking_availability_params.hpp */,
3DCD415120DAB33700143533 /* booking_block_params.cpp */,
3DCD415220DAB33700143533 /* booking_block_params.hpp */,
3DA5713320B57358007BDE27 /* booking_params_base.hpp */,
45BABC31229812820060FA53 /* downloader_promo.cpp */,
45BABC32229812830060FA53 /* downloader_promo.hpp */,
3DBC1C521E4B14920016897F /* facebook_ads.cpp */,
3DBC1C531E4B14920016897F /* facebook_ads.hpp */,
3D452AF11EE6D20D009EAB9B /* google_ads.cpp */,
@ -274,10 +275,15 @@
F67E75241DB8F06F00D6741F /* opentable_api.hpp */,
45C380752094C5B400C18D81 /* partners.cpp */,
45C380762094C5B400C18D81 /* partners.hpp */,
3D18DC4022956DFA00A583A6 /* promo_api.cpp */,
3D18DC3F22956DFA00A583A6 /* promo_api.hpp */,
346E88941E9D087400D4CE9B /* rb_ads.cpp */,
346E88951E9D087400D4CE9B /* rb_ads.hpp */,
3D15ACE5214AA1B000F725D5 /* rutaxi_api.cpp */,
3D15ACE4214AA1B000F725D5 /* rutaxi_api.hpp */,
3D47B2961F054C89000828D2 /* taxi_base.cpp */,
3DFEBF941EFBFC1500317D5C /* taxi_base.hpp */,
3D15ACE3214AA1AF00F725D5 /* taxi_delegate.hpp */,
3DFEBF951EFBFC1500317D5C /* taxi_engine.cpp */,
3DFEBF961EFBFC1500317D5C /* taxi_engine.hpp */,
3DF9C21A207CAC3B00DA0793 /* taxi_places_loader.cpp */,
@ -373,6 +379,7 @@
45C380782094C5B400C18D81 /* partners.hpp in Headers */,
3DFEBF861EF82BEA00317D5C /* viator_api.hpp in Headers */,
346E889C1E9D087400D4CE9B /* rb_ads.hpp in Headers */,
45BABC34229812830060FA53 /* downloader_promo.hpp in Headers */,
3D15ACE6214AA1B000F725D5 /* taxi_delegate.hpp in Headers */,
3DFEBF9A1EFBFC1500317D5C /* taxi_base.hpp in Headers */,
346E889A1E9D087400D4CE9B /* banner.hpp in Headers */,
@ -504,6 +511,7 @@
3D452AF31EE6D20D009EAB9B /* google_ads.cpp in Sources */,
346E88981E9D087400D4CE9B /* ads_engine.cpp in Sources */,
F67E75251DB8F06F00D6741F /* opentable_api.cpp in Sources */,
45BABC33229812830060FA53 /* downloader_promo.cpp in Sources */,
3D18DC4422956E0900A583A6 /* promo_tests.cpp in Sources */,
BB1956E61F543D7C003ECE6C /* locals_api.cpp in Sources */,
3DFEBFA31EFBFC2300317D5C /* taxi_engine_tests.cpp in Sources */,