[booking][ios][android]review fixes

This commit is contained in:
Arsentiy Milchakov 2018-02-07 14:24:08 +03:00 committed by Aleksandr Zatsepin
parent 219b3c78f5
commit b7f96dcf67
10 changed files with 77 additions and 68 deletions

View file

@ -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");
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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;

View file

@ -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);
}

View file

@ -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);
}
}

View file

@ -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 +

View file

@ -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;

View file

@ -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

View file

@ -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