diff --git a/android/jni/com/mapswithme/maps/taxi/TaxiManager.cpp b/android/jni/com/mapswithme/maps/taxi/TaxiManager.cpp index ae5ce25952..6e97bc6510 100644 --- a/android/jni/com/mapswithme/maps/taxi/TaxiManager.cpp +++ b/android/jni/com/mapswithme/maps/taxi/TaxiManager.cpp @@ -46,7 +46,7 @@ void PrepareClassRefs(JNIEnv * env) "(I[Lcom/mapswithme/maps/taxi/TaxiInfo$Product;)V"); g_taxiInfoErrorConstructor = jni::GetConstructorID(env, g_taxiInfoErrorClass, "(ILjava/lang/String;)V"); - g_taxiLinksClass = jni::GetGlobalClassRef(env, "com/mapswithme/maps/util/SponsoredLinks"); + g_taxiLinksClass = jni::GetGlobalClassRef(env, "com/mapswithme/util/SponsoredLinks"); g_taxiLinksConstructor = jni::GetConstructorID(env, g_taxiLinksClass, "(Ljava/lang/String;Ljava/lang/String;)V"); } diff --git a/android/src/com/mapswithme/maps/routing/RoutingBottomMenuController.java b/android/src/com/mapswithme/maps/routing/RoutingBottomMenuController.java index 7116c767fa..0df092cf16 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingBottomMenuController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingBottomMenuController.java @@ -297,7 +297,7 @@ final class RoutingBottomMenuController implements View.OnClickListener SponsoredLinks links = TaxiManager.getTaxiLink(mTaxiProduct.getProductId(), mTaxiInfo.getType(), startPoint, endPoint); if (links != null) - launchTaxiApp(links); + TaxiManager.launchTaxiApp(mContext, links, mTaxiInfo.getType()); } void showError(@StringRes int message) @@ -396,14 +396,6 @@ final class RoutingBottomMenuController implements View.OnClickListener } } - private static void trackTaxiStatistics(@TaxiManager.TaxiType int type, boolean isTaxiAppInstalled) - { - MapObject from = RoutingController.get().getStartPoint(); - MapObject to = RoutingController.get().getEndPoint(); - Location location = LocationHelper.INSTANCE.getLastKnownLocation(); - Statistics.INSTANCE.trackTaxiInRoutePlanning(from, to, location, type, isTaxiAppInstalled); - } - @Override public void onClick(View v) { @@ -423,27 +415,4 @@ final class RoutingBottomMenuController implements View.OnClickListener break; } } - - private void launchTaxiApp(@Nullable SponsoredLinks links) - { - String packageName = TaxiManager.getTaxiPackageName(mTaxiInfo.getType()); - boolean isTaxiInstalled = Utils.isAppInstalled(mContext, packageName); - Utils.PartnerAppOpenMode openMode = Utils.PartnerAppOpenMode.None; - - switch (mTaxiInfo.getType()) - { - case TaxiManager.PROVIDER_UBER: - openMode = Utils.PartnerAppOpenMode.Direct; - break; - case TaxiManager.PROVIDER_YANDEX: - openMode = Utils.PartnerAppOpenMode.Indirect; - break; - default: - throw new AssertionError("Unsupported taxi type: " + mTaxiInfo.getType()); - } - - Utils.openPartner(mContext, links, packageName, openMode); - - trackTaxiStatistics(mTaxiInfo.getType(), isTaxiInstalled); - } } diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java index 2263184355..fc67bd71af 100644 --- a/android/src/com/mapswithme/maps/routing/RoutingController.java +++ b/android/src/com/mapswithme/maps/routing/RoutingController.java @@ -763,13 +763,13 @@ public class RoutingController implements TaxiManager.TaxiListener } @Nullable - MapObject getStartPoint() + public MapObject getStartPoint() { return getStartOrEndPointByType(RoutePointInfo.ROUTE_MARK_START); } @Nullable - MapObject getEndPoint() + public MapObject getEndPoint() { return getStartOrEndPointByType(RoutePointInfo.ROUTE_MARK_FINISH); } diff --git a/android/src/com/mapswithme/maps/taxi/TaxiManager.java b/android/src/com/mapswithme/maps/taxi/TaxiManager.java index b7c7ebc0a5..1c76f398e8 100644 --- a/android/src/com/mapswithme/maps/taxi/TaxiManager.java +++ b/android/src/com/mapswithme/maps/taxi/TaxiManager.java @@ -1,14 +1,20 @@ package com.mapswithme.maps.taxi; +import android.content.Context; +import android.location.Location; import android.support.annotation.IntDef; import android.support.annotation.MainThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.location.LocationHelper; +import com.mapswithme.maps.routing.RoutingController; import com.mapswithme.util.NetworkPolicy; import com.mapswithme.util.SponsoredLinks; +import com.mapswithme.util.Utils; import com.mapswithme.util.concurrency.UiThread; +import com.mapswithme.util.statistics.Statistics; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -111,6 +117,37 @@ public class TaxiManager } } + public static void launchTaxiApp(@NonNull Context context, @NonNull SponsoredLinks links, + @TaxiManager.TaxiType int type) + { + String packageName = TaxiManager.getTaxiPackageName(type); + boolean isTaxiInstalled = Utils.isAppInstalled(context, packageName); + Utils.PartnerAppOpenMode openMode; + + switch (type) + { + case TaxiManager.PROVIDER_UBER: + openMode = Utils.PartnerAppOpenMode.Direct; + break; + case TaxiManager.PROVIDER_YANDEX: + openMode = Utils.PartnerAppOpenMode.Indirect; + break; + default: + throw new AssertionError("Unsupported taxi type: " + type); + } + + Utils.openPartner(context, links, packageName, openMode); + + trackTaxiStatistics(type, isTaxiInstalled); + } + + private static void trackTaxiStatistics(@TaxiManager.TaxiType int type, boolean isTaxiAppInstalled) + { + MapObject from = RoutingController.get().getStartPoint(); + MapObject to = RoutingController.get().getEndPoint(); + Location location = LocationHelper.INSTANCE.getLastKnownLocation(); + Statistics.INSTANCE.trackTaxiInRoutePlanning(from, to, location, type, isTaxiAppInstalled); + } public void setTaxiListener(@Nullable TaxiListener listener) { mListener = listener; diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index e6e5ce9950..dfd4592f17 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -978,7 +978,7 @@ public class PlacePageView extends RelativeLayout if (partnerAppOpenMode != Utils.PartnerAppOpenMode.None) { SponsoredLinks links = new SponsoredLinks(info.getDeepLink(), info.getUrl()); - String packageName = Sponsored.GetPackageName(info.getType()); + String packageName = Sponsored.getPackageName(info.getType()); Utils.openPartner(getContext(), links, packageName, partnerAppOpenMode); } diff --git a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java index f6d3882ced..f6708dc488 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java +++ b/android/src/com/mapswithme/maps/widget/placepage/Sponsored.java @@ -390,14 +390,14 @@ public final class Sponsored } @NonNull - public static String GetPackageName(@SponsoredType int type) + static String getPackageName(@SponsoredType int type) { switch (type) { case Sponsored.TYPE_BOOKING: return "com.booking"; default: - return ""; + throw new AssertionError("Unsupported sponsored type: " + type); } } diff --git a/android/src/com/mapswithme/util/Utils.java b/android/src/com/mapswithme/util/Utils.java index a358ba4387..0164bedc14 100644 --- a/android/src/com/mapswithme/util/Utils.java +++ b/android/src/com/mapswithme/util/Utils.java @@ -316,24 +316,15 @@ public class Utils } } - public static void launchAppDirect(@NonNull Context context, @NonNull SponsoredLinks links, - String packageName) + private static void launchAppDirectly(@NonNull Context context, @NonNull SponsoredLinks links) { - boolean isAppInstalled = Utils.isAppInstalled(context, packageName); - - if (!isAppInstalled) - { - openUrl(context, links.getUniversalLink()); - return; - } - - final Intent intent = new Intent(Intent.ACTION_VIEW); + Intent intent = new Intent(Intent.ACTION_VIEW); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setData(Uri.parse(links.getDeepLink())); context.startActivity(intent); } - public static void launchAppIndirect(@NonNull Context context, @NonNull SponsoredLinks links) + private static void launchAppIndirectly(@NonNull Context context, @NonNull SponsoredLinks links) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(links.getDeepLink())); @@ -346,10 +337,15 @@ public class Utils switch (openMode) { case Direct: - launchAppDirect(activity, links, packageName); + if (!Utils.isAppInstalled(activity, packageName)) + { + openUrl(activity, links.getUniversalLink()); + return; + } + launchAppDirectly(activity, links); break; case Indirect: - launchAppIndirect(activity, links); + launchAppIndirectly(activity, links); break; default: throw new AssertionError("Unsupported partner app open mode: " + openMode + diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h index 69c2a1f95c..16020686db 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.h +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.h @@ -174,6 +174,7 @@ using NewSectionsAreReady = void (^)(NSRange const & range, MWMPlacePageData * d - (MWMUGCRatingValueType *)bookingRating; - (NSString *)bookingApproximatePricing; - (NSURL *)sponsoredURL; +- (NSURL *)deepLink; - (NSURL *)sponsoredDescriptionURL; - (NSURL *)bookingSearchURL; - (NSString *)sponsoredId; diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm index cae6ef593a..ba6ac314d8 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageData.mm @@ -519,12 +519,10 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; - (NSString *)bookingApproximatePricing { return self.isBooking ? @(m_info.GetApproximatePricing().c_str()) : nil; } - (NSURL *)sponsoredURL { - auto const link = self.isPartnerAppInstalled ? m_info.GetSponsoredDeepLink() : m_info.GetSponsoredUrl(); - - // There are sponsors without URL. For such partners we do not show special button. - if (m_info.IsSponsored() && !link.empty()) + // There are sponsors without URL. For such psrtners we do not show special button. + if (m_info.IsSponsored() && !m_info.GetSponsoredUrl().empty()) { - auto urlString = [@(link.c_str()) + auto urlString = [@(m_info.GetSponsoredUrl().c_str()) stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet .URLQueryAllowedCharacterSet]; auto url = [NSURL URLWithString:urlString]; @@ -533,6 +531,15 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; return nil; } +- (NSURL *)deepLink +{ + auto const & link = m_info.GetSponsoredDeepLink(); + if (m_info.IsSponsored() && !link.empty()) + return [NSURL URLWithString:@(link.c_str())]; + + return nil; +} + - (NSURL *)sponsoredDescriptionURL { return m_info.IsSponsored() @@ -792,13 +799,8 @@ NSString * const kUserDefaultsLatLonAsDMSKey = @"UserDefaultsLatLonAsDMS"; - (BOOL)isPreviewExtended { return m_info.IsPreviewExtended(); } - (BOOL)isPartnerAppInstalled { - NSURL * url; - switch (m_info.GetSponsoredType()) - { - case SponsoredType::Booking: url = [NSURL URLWithString:@"booking://"]; break; - default: return NO; - } - return [UIApplication.sharedApplication canOpenURL:url]; + // TODO(): Load list of registered schemas from plist. + return [UIApplication.sharedApplication canOpenURL:self.deepLink]; } + (MWMRatingSummaryViewValueType)ratingValueType:(rating::Impress)impress diff --git a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm index fb332437b0..95c63be113 100644 --- a/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm +++ b/iphone/Maps/UI/PlacePage/MWMPlacePageManager.mm @@ -482,13 +482,17 @@ void logSponsoredEvent(MWMPlacePageData * data, NSString * eventName) return; } logSponsoredEvent(data, eventName); + + if (!isDescription && data.isPartnerAppInstalled) + { + [UIApplication.sharedApplication openURL:data.deepLink]; + return; + } + NSURL * url = isDescription ? data.sponsoredDescriptionURL : data.sponsoredURL; NSAssert(url, @"Sponsored url can't be nil!"); - if (data.isPartnerAppInstalled) - [UIApplication.sharedApplication openURL:url]; - else - [self.ownerViewController openUrl:url]; + [self.ownerViewController openUrl:url]; } - (void)searchBookingHotels