[ios] Deep link parsing is refactored. See 09c67f9baf for detailed info.

This commit is contained in:
Arsentiy Milchakov 2020-09-02 09:52:06 +03:00 committed by mpimenov
parent 8bf60b616e
commit 9169ea5470
11 changed files with 59 additions and 50 deletions

View file

@ -131,7 +131,7 @@
993F54F5237C5D1100545511 /* PromoAfterBookingCampaignAdapter.h in Headers */ = {isa = PBXBuildFile; fileRef = 993F54F1237C5D1000545511 /* PromoAfterBookingCampaignAdapter.h */; settings = {ATTRIBUTES = (Public, ); }; };
9940622023EAC57900493D1A /* ElevationHeightPoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 9940621E23EAC57900493D1A /* ElevationHeightPoint.h */; settings = {ATTRIBUTES = (Public, ); }; };
9940622123EAC57900493D1A /* ElevationHeightPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 9940621F23EAC57900493D1A /* ElevationHeightPoint.m */; };
99447849238559F2004DAEE5 /* DeeplinkParsingResult.h in Headers */ = {isa = PBXBuildFile; fileRef = 99447847238559F2004DAEE5 /* DeeplinkParsingResult.h */; };
99447849238559F2004DAEE5 /* DeeplinkUrlType.h in Headers */ = {isa = PBXBuildFile; fileRef = 99447847238559F2004DAEE5 /* DeeplinkUrlType.h */; };
9957FACE237AB01400855F48 /* DeepLinkParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 9957FACC237AB01400855F48 /* DeepLinkParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
9957FACF237AB01400855F48 /* DeepLinkParser.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9957FACD237AB01400855F48 /* DeepLinkParser.mm */; };
9957FADB237ACB1100855F48 /* DeepLinkSearchData.h in Headers */ = {isa = PBXBuildFile; fileRef = 9957FAD9237ACB1100855F48 /* DeepLinkSearchData.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -288,7 +288,7 @@
993F54F1237C5D1000545511 /* PromoAfterBookingCampaignAdapter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PromoAfterBookingCampaignAdapter.h; sourceTree = "<group>"; };
9940621E23EAC57900493D1A /* ElevationHeightPoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElevationHeightPoint.h; sourceTree = "<group>"; };
9940621F23EAC57900493D1A /* ElevationHeightPoint.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ElevationHeightPoint.m; sourceTree = "<group>"; };
99447847238559F2004DAEE5 /* DeeplinkParsingResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeeplinkParsingResult.h; sourceTree = "<group>"; };
99447847238559F2004DAEE5 /* DeeplinkUrlType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeeplinkUrlType.h; sourceTree = "<group>"; };
994C4E0E246C22CA0018EB1E /* MWMUTM+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MWMUTM+Core.h"; sourceTree = "<group>"; };
9957FACC237AB01400855F48 /* DeepLinkParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLinkParser.h; sourceTree = "<group>"; };
9957FACD237AB01400855F48 /* DeepLinkParser.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DeepLinkParser.mm; sourceTree = "<group>"; };
@ -658,7 +658,7 @@
9957FADA237ACB1100855F48 /* DeepLinkSearchData.mm */,
99103841237EDFA200893C9F /* DeepLinkData.h */,
99103842237EDFA200893C9F /* DeepLinkData.m */,
99447847238559F2004DAEE5 /* DeeplinkParsingResult.h */,
99447847238559F2004DAEE5 /* DeeplinkUrlType.h */,
);
path = Data;
sourceTree = "<group>";
@ -820,7 +820,7 @@
47C637D72354AEBE00E12DE0 /* MWMMapOverlayManager.h in Headers */,
99F31EB923D5DD9000CE2CE1 /* PromoAfterBookingData+Core.h in Headers */,
993F54F2237C5D1100545511 /* PromoDiscoveryCampaignAdapter.h in Headers */,
99447849238559F2004DAEE5 /* DeeplinkParsingResult.h in Headers */,
99447849238559F2004DAEE5 /* DeeplinkUrlType.h in Headers */,
47942D9C237D927800DEFAE3 /* PlacePageBookmarkData.h in Headers */,
47942D75237CC41A00DEFAE3 /* HotelBookingData+Core.h in Headers */,
47938905239A932D006ECACC /* UgcSummaryRatingType.h in Headers */,

View file

@ -2,28 +2,28 @@
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, DeeplinkParsingResult) {
DeeplinkParsingResultIncorrect = 0,
DeeplinkParsingResultMap,
DeeplinkParsingResultRoute,
DeeplinkParsingResultSearch,
DeeplinkParsingResultLead,
DeeplinkParsingResultCatalogue,
DeeplinkParsingResultCataloguePath,
DeeplinkParsingResultSubscription
typedef NS_ENUM(NSUInteger, DeeplinkUrlType) {
DeeplinkUrlTypeIncorrect = 0,
DeeplinkUrlTypeMap,
DeeplinkUrlTypeRoute,
DeeplinkUrlTypeSearch,
DeeplinkUrlTypeLead,
DeeplinkUrlTypeCatalogue,
DeeplinkUrlTypeCataloguePath,
DeeplinkUrlTypeSubscription
};
@protocol IDeepLinkData <NSObject>
@property (nonatomic, readonly) DeeplinkParsingResult result;
@property (nonatomic, readonly) DeeplinkUrlType urlType;
@end
@interface DeepLinkData : NSObject <IDeepLinkData>
@property (nonatomic, readonly) DeeplinkParsingResult result;
@property (nonatomic, readonly) DeeplinkUrlType urlType;
- (instancetype)init:(DeeplinkParsingResult)result;
- (instancetype)init:(DeeplinkUrlType)urlType;
@end

View file

@ -2,10 +2,10 @@
@implementation DeepLinkData
- (instancetype)init:(DeeplinkParsingResult)result {
- (instancetype)init:(DeeplinkUrlType)urlType {
self = [super init];
if (self) {
_result = result;
_urlType = urlType;
}
return self;
}

View file

@ -5,14 +5,14 @@ NS_ASSUME_NONNULL_BEGIN
@interface DeepLinkSearchData : NSObject <IDeepLinkData>
@property(nonatomic, readonly) DeeplinkParsingResult result;
@property(nonatomic, readonly) DeeplinkUrlType result;
@property(nonatomic, readonly) NSString* query;
@property(nonatomic, readonly) NSString* locale;
@property(nonatomic, readonly) double centerLat;
@property(nonatomic, readonly) double centerLon;
@property(nonatomic, readonly) BOOL isSearchOnMap;
- (instancetype)init:(DeeplinkParsingResult)result;
- (instancetype)init:(DeeplinkUrlType)result;
- (void)onViewportChanged:(int)zoomLevel;
@end

View file

@ -4,7 +4,7 @@
#include "geometry/mercator.hpp"
@implementation DeepLinkSearchData
- (instancetype)init:(DeeplinkParsingResult)result {
- (instancetype)init:(DeeplinkUrlType)result {
self = [super init];
if (self) {
_result = result;

View file

@ -5,10 +5,10 @@ NS_ASSUME_NONNULL_BEGIN
@interface DeepLinkSubscriptionData : NSObject <IDeepLinkData>
@property (nonatomic, readonly) DeeplinkParsingResult result;
@property (nonatomic, readonly) DeeplinkUrlType result;
@property(nonatomic, readonly) NSString* groups;
- (instancetype)init:(DeeplinkParsingResult)result;
- (instancetype)init:(DeeplinkUrlType)result;
@end

View file

@ -3,7 +3,7 @@
@implementation DeepLinkSubscriptionData
- (instancetype)init:(DeeplinkParsingResult)result {
- (instancetype)init:(DeeplinkUrlType)result {
self = [super init];
if (self) {
_result = result;

View file

@ -1,21 +0,0 @@
#import <Foundation/Foundation.h>
#import "map/mwm_url.hpp"
NS_ASSUME_NONNULL_BEGIN
static inline DeeplinkParsingResult deeplinkParsingResult(url_scheme::ParsedMapApi::ParsingResult result)
{
switch (result)
{
case url_scheme::ParsedMapApi::ParsingResult::Incorrect: return DeeplinkParsingResultIncorrect;
case url_scheme::ParsedMapApi::ParsingResult::Map: return DeeplinkParsingResultMap;
case url_scheme::ParsedMapApi::ParsingResult::Route: return DeeplinkParsingResultRoute;
case url_scheme::ParsedMapApi::ParsingResult::Search: return DeeplinkParsingResultSearch;
case url_scheme::ParsedMapApi::ParsingResult::Lead: return DeeplinkParsingResultLead;
case url_scheme::ParsedMapApi::ParsingResult::Catalogue: return DeeplinkParsingResultCatalogue;
case url_scheme::ParsedMapApi::ParsingResult::CataloguePath: return DeeplinkParsingResultCataloguePath;
case url_scheme::ParsedMapApi::ParsingResult::Subscription: return DeeplinkParsingResultSubscription;
}
}
NS_ASSUME_NONNULL_END

View file

@ -0,0 +1,21 @@
#import <Foundation/Foundation.h>
#import "map/mwm_url.hpp"
NS_ASSUME_NONNULL_BEGIN
static inline DeeplinkUrlType deeplinkUrlType(url_scheme::ParsedMapApi::UrlType type)
{
switch (type)
{
case url_scheme::ParsedMapApi::UrlType::Incorrect: return DeeplinkUrlTypeIncorrect;
case url_scheme::ParsedMapApi::UrlType::Map: return DeeplinkUrlTypeMap;
case url_scheme::ParsedMapApi::UrlType::Route: return DeeplinkUrlTypeRoute;
case url_scheme::ParsedMapApi::UrlType::Search: return DeeplinkUrlTypeSearch;
case url_scheme::ParsedMapApi::UrlType::Lead: return DeeplinkUrlTypeLead;
case url_scheme::ParsedMapApi::UrlType::Catalogue: return DeeplinkUrlTypeCatalogue;
case url_scheme::ParsedMapApi::UrlType::CataloguePath: return DeeplinkUrlTypeCataloguePath;
case url_scheme::ParsedMapApi::UrlType::Subscription: return DeeplinkUrlTypeSubscription;
}
}
NS_ASSUME_NONNULL_END

View file

@ -3,17 +3,26 @@
#import "DeepLinkData.h"
#import "DeepLinkSearchData.h"
#import "DeepLinkSubscriptionData.h"
#import "DeeplinkParsingResult.h"
#import "DeeplinkUrlType.h"
@implementation DeepLinkParser
+ (id<IDeepLinkData>)parseAndSetApiURL:(NSURL *)url {
Framework &f = GetFramework();
DeeplinkParsingResult result = deeplinkParsingResult(f.ParseAndSetApiURL(url.absoluteString.UTF8String));
url_scheme::ParsedMapApi::ParsingResult internalResult = f.ParseAndSetApiURL(url.absoluteString.UTF8String);
DeeplinkUrlType result = deeplinkUrlType(internalResult.m_type);
// TODO: remove this if-contition and implement correct result handling.
// This condition is added for backward compatibility only.
// Two states were represented by DeeplinkUrlTypeIncorrect: incorrect url and failed parsing.
// But now it replaced by two parameters: url type and isSuccess flag.
if (!internalResult.m_isSuccess)
result = DeeplinkUrlTypeIncorrect;
switch (result) {
case DeeplinkParsingResultSearch:
case DeeplinkUrlTypeSearch:
return [[DeepLinkSearchData alloc] init:result];
case DeeplinkParsingResultSubscription:
case DeeplinkUrlTypeSubscription:
return [[DeepLinkSubscriptionData alloc] init:result];
default:
return [[DeepLinkData alloc] init:result];

View file

@ -14,7 +14,7 @@ class DeepLinkStrategyFactory {
private static func createCommon(url deeplinkURL: DeepLinkURL) -> IDeepLinkHandlerStrategy {
let data = DeepLinkParser.parseAndSetApiURL(deeplinkURL.url)
switch data.result {
switch data.urlType {
case .incorrect:
return DeepLinkIncorrectStrategy(url: deeplinkURL)
case .route: