[android] download on map banners are added

This commit is contained in:
Arsentiy Milchakov 2020-03-18 15:27:42 +03:00 committed by Aleksey Belousov
parent 57e0129a4d
commit d14e242f72
15 changed files with 380 additions and 108 deletions

View file

@ -1930,9 +1930,6 @@ Java_com_mapswithme_maps_Framework_nativeDeleteSavedRoutePoints()
JNIEXPORT jobjectArray JNICALL
Java_com_mapswithme_maps_Framework_nativeGetSearchBanners(JNIEnv * env, jclass)
{
auto const & purchase = frm()->GetPurchase();
if (purchase && purchase->IsSubscriptionActive(SubscriptionType::RemoveAds))
return nullptr;
return usermark_helper::ToBannersArray(env, frm()->GetAdsEngine().GetSearchBanners());
}
@ -2035,24 +2032,20 @@ Java_com_mapswithme_maps_Framework_nativeGetDownloaderPromoBanner(JNIEnv * env,
static jmethodID const downloaderPromoBannerConstructor = jni::GetConstructorID(env,
downloaderPromoBannerClass, "(ILjava/lang/String;)V");
auto const & purchase = frm()->GetPurchase();
bool const hasSubscription = purchase != nullptr &&
purchase->IsSubscriptionActive(SubscriptionType::RemoveAds);
promo::DownloaderPromo::Banner banner;
auto const policy = platform::GetCurrentNetworkPolicy();
if (policy.CanUse())
std::vector<ads::Banner> banners;
auto const pos = frm()->GetCurrentPosition();
if (pos)
{
auto const * promoApi = frm()->GetPromoApi(policy);
CHECK(promoApi != nullptr, ());
banner = promo::DownloaderPromo::GetBanner(frm()->GetStorage(), *promoApi,
jni::ToNativeString(env, mwmId),
languages::GetCurrentNorm(), hasSubscription);
banners = frm()->GetAdsEngine().GetDownloadOnMapBanners(jni::ToNativeString(env, mwmId), *pos,
languages::GetCurrentNorm());
}
jni::TScopedLocalRef const url(env, jni::ToJavaString(env, banner.m_url));
if (banners.empty())
return nullptr;
jni::TScopedLocalRef const url(env, jni::ToJavaString(env, banners[0].m_value));
return env->NewObject(downloaderPromoBannerClass, downloaderPromoBannerConstructor,
static_cast<jint>(banner.m_type), url.get());
static_cast<jint>(banners[0].m_type), url.get());
}
JNIEXPORT jboolean JNICALL

View file

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M23.9662,0.0366H0.0366V23.9663H23.9662V0.0366Z"
android:fillColor="#ED1D24"/>
<path
android:pathData="M11.9986,5.2986C10.9996,5.2986 9.8178,6.261 8.8385,7.8733C7.822,9.5464 7.2622,11.4569 7.2149,13.414C7.2149,16.045 8.6922,18.7013 11.9986,18.7013C15.3049,18.7013 16.7823,16.045 16.7823,13.414C16.7347,11.4595 16.1769,9.5514 15.1643,7.879C14.1794,6.2666 12.9947,5.3042 11.9986,5.3042"
android:fillColor="#ffffff"/>
</vector>

View file

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M24,0H0V24H24V0Z"
android:fillColor="#4287DF"/>
<path
android:pathData="M8.1408,15.3894C8.1408,15.3894 9.6012,17.3691 12.157,17.3691C13.6174,17.3691 14.8952,16.6492 14.8952,15.2994C14.8952,12.51 7.5019,12.9599 7.5019,8.8206C7.5019,6.4811 9.5099,5.3113 12.157,5.3113C13.6174,5.3113 16.2644,5.7612 16.2644,7.6509V8.7307H14.6214V8.1007C14.6214,7.111 13.2523,6.751 12.3395,6.751C10.514,6.751 9.4187,7.3809 9.4187,8.6406C9.4187,11.5201 16.8121,10.8903 16.8121,15.2095C16.8121,17.3691 14.804,18.8088 12.2482,18.8088C8.871,18.8088 7.228,16.5592 7.228,16.5592L8.1408,15.3894Z"
android:fillColor="#ffffff"/>
</vector>

File diff suppressed because one or more lines are too long

View file

@ -113,8 +113,6 @@
android:fontFamily="@string/robotoMedium"
android:textAllCaps="false"
android:textSize="@dimen/text_size_body_3"
android:text="@string/banner_megafon_banner_button"
android:background="@drawable/button_megafon"
style="?android:attr/borderlessButtonStyle"
android:textColor="@color/white_primary"
tools:targetApi="jelly_bean"/>

View file

@ -503,7 +503,7 @@ public class Framework
@NonNull
public static native String nativeMoPubInitializationBannerId();
@NonNull
@Nullable
public static native DownloaderPromoBanner nativeGetDownloaderPromoBanner(@NonNull String mwmId);
public static native boolean nativeHasMegafonCategoryBanner();

View file

@ -0,0 +1,12 @@
package com.mapswithme.maps.downloader;
import android.view.View;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
interface DownloaderBannerConfigStrategy
{
void ConfigureView(@NonNull View parent, @IdRes int iconViewId, @IdRes int messageViewId,
@IdRes int buttonViewId);
}

View file

@ -0,0 +1,15 @@
package com.mapswithme.maps.downloader;
import android.view.View;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
class DownloaderBannerConfigStrategyDefault implements DownloaderBannerConfigStrategy
{
@Override
public void ConfigureView(@NonNull View parent, @IdRes int iconViewId, @IdRes int messageViewId,
@IdRes int buttonViewId)
{
}
}

View file

@ -0,0 +1,50 @@
package com.mapswithme.maps.downloader;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
class DownloaderBannerConfigStrategyPartner implements DownloaderBannerConfigStrategy
{
@DrawableRes
private int mIcon;
@StringRes
private int mMessage;
@StringRes
private int mButtonText;
@ColorInt
private int mButtonTextColor;
@ColorInt
private int mButtonColor;
DownloaderBannerConfigStrategyPartner(@DrawableRes int icon, @StringRes int message,
@StringRes int buttonText, @ColorInt int buttonTextColor,
@ColorInt int buttonColor)
{
mIcon = icon;
mMessage = message;
mButtonText = buttonText;
mButtonTextColor = buttonTextColor;
mButtonColor = buttonColor;
}
@Override
public void ConfigureView(@NonNull View parent, @IdRes int iconViewId, @IdRes int messageViewId,
@IdRes int buttonViewId)
{
ImageView icon = parent.findViewById(iconViewId);
icon.setImageResource(mIcon);
TextView message = parent.findViewById(messageViewId);
message.setText(mMessage);
TextView button = parent.findViewById(buttonViewId);
button.setText(mButtonText);
button.setTextColor(mButtonTextColor);
button.setBackgroundColor(mButtonColor);
}
}

View file

@ -0,0 +1,84 @@
package com.mapswithme.maps.downloader;
import android.graphics.Color;
import androidx.annotation.NonNull;
import com.mapswithme.maps.R;
import com.mapswithme.util.statistics.StatisticValueConverter;
import com.mapswithme.util.statistics.Statistics;
enum DownloaderBannerType implements StatisticValueConverter<String>
{
TINKOFF_AIRLINES(new DownloaderBannerConfigStrategyPartner(R.drawable.ic_logo_tinkoff,
R.string.tinkoff_allairlines_map_downloader_title,
R.string.tinkoff_allairlines_map_downloader_cta_button,
Color.parseColor("#000000"),
Color.parseColor("#FFDD2D")))
{
@NonNull
@Override
public String toStatisticValue()
{
return Statistics.ParamValue.TINKOFF_ALL_AIRLINES;
}
},
TINKOFF_INSURANCE(new DownloaderBannerConfigStrategyPartner(R.drawable.ic_logo_tinkoff,
R.string.tinkoff_insurance_map_downloader_title,
R.string.tinkoff_insurance_map_downloader_cta_button,
Color.parseColor("#000000"),
Color.parseColor("#FFDD2D")))
{
@NonNull
@Override
public String toStatisticValue()
{
return Statistics.ParamValue.TINKOFF_INSURANCE;
}
},
MTS(new DownloaderBannerConfigStrategyPartner(R.drawable.ic_logo_mts,
R.string.mts_map_downloader_title,
R.string.mts_map_downloader_cta_button,
Color.parseColor("#FFFFFF"),
Color.parseColor("#E30611")))
{
@NonNull
@Override
public String toStatisticValue()
{
return Statistics.ParamValue.SKYENG;
}
},
SKYENG(new DownloaderBannerConfigStrategyPartner(R.drawable.ic_logo_skyeng,
R.string.skyeng_map_downloader_title,
R.string.skyeng_map_downloader_cta_button,
Color.parseColor("#FFFFFF"),
Color.parseColor("#4287DF")))
{
@NonNull
@Override
public String toStatisticValue()
{
return Statistics.ParamValue.MTS;
}
},
BOOKMARK_CATALOG(new DownloaderBannerConfigStrategyDefault())
{
@NonNull
@Override
public String toStatisticValue()
{
return Statistics.ParamValue.MAPSME_GUIDES;
}
};
@NonNull
private final DownloaderBannerConfigStrategy mViewConfigStrategy;
DownloaderBannerType(@NonNull DownloaderBannerConfigStrategy viewConfigStrategy)
{
mViewConfigStrategy = viewConfigStrategy;
}
@NonNull
DownloaderBannerConfigStrategy getViewConfigStrategy() { return mViewConfigStrategy; }
}

View file

@ -1,8 +1,14 @@
package com.mapswithme.maps.downloader;
import android.graphics.Color;
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import com.mapswithme.maps.R;
import com.mapswithme.util.statistics.StatisticValueConverter;
import java.lang.annotation.Retention;
@ -11,40 +17,37 @@ import java.lang.annotation.RetentionPolicy;
/**
* Promo banner for on-map downloader. Created by native code.
*/
public final class DownloaderPromoBanner implements StatisticValueConverter<String>
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 DownloaderBannerType mType;
@NonNull
private final String mUrl;
public DownloaderPromoBanner(@DownloaderPromoType int type, @NonNull String url)
// Note: must be corresponded to ads::Banner::Type in ads/banner.hpp
private static DownloaderBannerType fromCoreType(int coreValue)
{
this.mType = type;
switch (coreValue)
{
case 4: return DownloaderBannerType.TINKOFF_AIRLINES;
case 5: return DownloaderBannerType.TINKOFF_INSURANCE;
case 6: return DownloaderBannerType.MTS;
case 7: return DownloaderBannerType.SKYENG;
case 8: return DownloaderBannerType.BOOKMARK_CATALOG;
default: throw new AssertionError("Incorrect core banner type: " + coreValue);
}
}
// Note: this constructor must be called from jni only.
private DownloaderPromoBanner(int coreType, @NonNull String url)
{
this.mType = fromCoreType(coreType);
this.mUrl = url;
}
@DownloaderPromoType
public int getType() { return mType; }
@NonNull
public DownloaderBannerType getType() { return mType; }
@NonNull
public String getUrl() { return mUrl; }
@NonNull
@Override
public String toStatisticValue()
{
return DownloaderPromoBannerStats.values()[getType()].getValue();
}
}

View file

@ -1,39 +0,0 @@
package com.mapswithme.maps.downloader;
import androidx.annotation.NonNull;
import com.mapswithme.util.statistics.Statistics;
public enum DownloaderPromoBannerStats
{
NO_PROMO
{
@NonNull
@Override
public String getValue()
{
throw new UnsupportedOperationException("Unsupported here");
}
},
CATALOG
{
@NonNull
@Override
public String getValue()
{
return Statistics.ParamValue.MAPSME_GUIDES;
}
},
MEGAFON
{
@NonNull
@Override
public String getValue()
{
return Statistics.ParamValue.MEGAFON;
}
};
@NonNull
public abstract String getValue();
}

View file

@ -43,6 +43,8 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
@NonNull
private final View mCatalogCallToActionContainer;
@NonNull
private final View mBannerContainer;
@NonNull
private final View mPromoContentDivider;
private int mStorageSubscriptionSlot;
@ -244,11 +246,17 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
});
mFrame.findViewById(R.id.banner_button).setOnClickListener(v -> {
if (mPromoBanner != null && mPromoBanner.getType() != DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_NO_PROMO)
Utils.openUrl(mActivity, mPromoBanner.getUrl());
if (mPromoBanner == null)
return;
Utils.openUrl(mActivity, mPromoBanner.getUrl());
if (mCurrentCountry == null)
return;
Statistics.ParameterBuilder builder =
Statistics.makeDownloaderBannerParamBuilder(Statistics.ParamValue.MEGAFON);
Statistics.makeDownloaderBannerParamBuilder(mPromoBanner.getType().toStatisticValue(),
mCurrentCountry.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_BANNER_CLICK, builder);
});
@ -256,6 +264,7 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
mCatalogCallToActionContainer = mFrame.findViewById(R.id.catalog_call_to_action_container);
downloadGuidesBtn.setOnClickListener(new CatalogCallToActionListener());
mPromoContentDivider = mFrame.findViewById(R.id.onmap_downloader_divider);
mBannerContainer = mFrame.findViewById(R.id.banner);
}
private void updateBannerVisibility()
@ -264,26 +273,31 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
return;
mPromoBanner = Framework.nativeGetDownloaderPromoBanner(mCurrentCountry.id);
boolean isPromoFound = mPromoBanner.getType() != DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_NO_PROMO;
boolean isPromoFound = mPromoBanner != null;
boolean enqueued = mCurrentCountry.status == CountryItem.STATUS_ENQUEUED;
boolean progress = mCurrentCountry.status == CountryItem.STATUS_PROGRESS;
boolean applying = mCurrentCountry.status == CountryItem.STATUS_APPLYING;
boolean isDownloading = enqueued || progress || applying;
UiUtils.showIf(isPromoFound && isDownloading, mPromoContentDivider);
boolean hasMegafonPromo = mPromoBanner.getType() == DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_MEGAFON;
boolean hasCatalogPromo = mPromoBanner.getType() == DownloaderPromoBanner.DOWNLOADER_PROMO_TYPE_BOOKMARK_CATALOG;
UiUtils.showIf(isDownloading && hasMegafonPromo, mFrame, R.id.banner);
UiUtils.showIf(isDownloading && hasCatalogPromo, mCatalogCallToActionContainer);
if (!isPromoFound)
if (!isDownloading || !isPromoFound)
{
UiUtils.hide(mPromoContentDivider, mBannerContainer, mCatalogCallToActionContainer);
return;
}
UiUtils.show(mPromoContentDivider);
boolean hasCatalogPromo = mPromoBanner.getType() == DownloaderBannerType.BOOKMARK_CATALOG;
View bannerView = hasCatalogPromo ? mCatalogCallToActionContainer : mBannerContainer;
mPromoBanner.getType().getViewConfigStrategy().ConfigureView(bannerView, R.id.icon, R.id.text,
R.id.banner_button);
UiUtils.showIf(!hasCatalogPromo, mBannerContainer);
UiUtils.showIf(hasCatalogPromo, mCatalogCallToActionContainer);
Statistics.ParameterBuilder builder =
Statistics.makeDownloaderBannerParamBuilder(mPromoBanner.toStatisticValue());
Statistics.makeDownloaderBannerParamBuilder(mPromoBanner.getType().toStatisticValue(),
mCurrentCountry.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_BANNER_SHOW, builder);
}
@ -336,8 +350,13 @@ public class OnmapDownloader implements MwmActivity.LeftAnimationTrackListener
BookmarksCatalogActivity.startForResult(mActivity, BookmarkCategoriesActivity.REQ_CODE_DOWNLOAD_BOOKMARK_CATEGORY,
mPromoBanner.getUrl());
if (mCurrentCountry == null)
return;
Statistics.ParameterBuilder builder =
Statistics.makeDownloaderBannerParamBuilder(Statistics.ParamValue.MAPSME_GUIDES);
Statistics.makeDownloaderBannerParamBuilder(mPromoBanner.getType().toStatisticValue(),
mCurrentCountry.id);
Statistics.INSTANCE.trackEvent(Statistics.EventName.DOWNLOADER_BANNER_CLICK, builder);
}
}

View file

@ -180,11 +180,13 @@ public enum Statistics
}
@NonNull
public static ParameterBuilder makeDownloaderBannerParamBuilder(@NonNull String provider)
public static ParameterBuilder makeDownloaderBannerParamBuilder(@NonNull String provider,
@NonNull String mwmId)
{
return new ParameterBuilder()
.add(EventParam.FROM, ParamValue.MAP)
.add(PROVIDER, provider);
.add(PROVIDER, provider)
.add(MWM_NAME, mwmId);
}
@NonNull
@ -774,6 +776,10 @@ public enum Statistics
public static final String DELETE_GROUP = "delete_group";
public static final String OFFSCREEEN = "Offscreen";
public static final String MAPSME_GUIDES = "MapsMeGuides";
public static final String TINKOFF_INSURANCE = "Tinkoff_Insurance";
public static final String TINKOFF_ALL_AIRLINES= "Tinkoff_AllAirlines";
public static final String SKYENG = "Skyeng";
public static final String MTS = "MTS";
public static final String BY_DEFAULT = "Default";
public static final String BY_DATE = "Date";
public static final String BY_DISTANCE = "Distance";

View file

@ -248,10 +248,8 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab
manager.textChanged = YES;
auto const & adsEngine = GetFramework().GetAdsEngine();
auto const banners = adsEngine.GetSearchBanners();
auto const & purchase = GetFramework().GetPurchase();
bool const hasSubscription = purchase && purchase->IsSubscriptionActive(SubscriptionType::RemoveAds);
if (!hasSubscription && !banners.empty()) {
if (!banners.empty()) {
auto coreBanners = banner_helpers::MatchPriorityBanners(banners, manager.lastQuery);
[[MWMBannersCache cache] refreshWithCoreBanners:coreBanners];
}
@ -387,10 +385,8 @@ booking::filter::Tasks MakeBookingFilterTasks(booking::filter::Params && availab
{
auto const & adsEngine = GetFramework().GetAdsEngine();
auto const banners = adsEngine.GetSearchBanners();
auto const & purchase = GetFramework().GetPurchase();
bool const hasSubscription = purchase && purchase->IsSubscriptionActive(SubscriptionType::RemoveAds);
if (!hasSubscription && !banners.empty()) {
if (!banners.empty()) {
self.banners = [[MWMSearchBanners alloc] initWithSearchIndex:itemsIndex];
__weak auto weakSelf = self;
[[MWMBannersCache cache] getWithCoreBanners:banner_helpers::MatchPriorityBanners(banners, self.lastQuery)