From 9169ea5470ebb260462572e416f892eae64d5b64 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Wed, 2 Sep 2020 09:52:06 +0300 Subject: [PATCH] [ios] Deep link parsing is refactored. See 09c67f9baf for detailed info. --- .../CoreApi/CoreApi.xcodeproj/project.pbxproj | 8 +++---- .../CoreApi/DeepLink/Data/DeepLinkData.h | 24 +++++++++---------- .../CoreApi/DeepLink/Data/DeepLinkData.m | 4 ++-- .../DeepLink/Data/DeepLinkSearchData.h | 4 ++-- .../DeepLink/Data/DeepLinkSearchData.mm | 2 +- .../DeepLink/Data/DeepLinkSubscriptionData.h | 4 ++-- .../DeepLink/Data/DeepLinkSubscriptionData.mm | 2 +- .../DeepLink/Data/DeeplinkParsingResult.h | 21 ---------------- .../CoreApi/DeepLink/Data/DeeplinkUrlType.h | 21 ++++++++++++++++ .../CoreApi/DeepLink/DeepLinkParser.mm | 17 +++++++++---- .../DeepLink/DeepLinkStrategyFactory.swift | 2 +- 11 files changed, 59 insertions(+), 50 deletions(-) delete mode 100644 iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkParsingResult.h create mode 100644 iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkUrlType.h diff --git a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj index d3add8b1ad..598a58038d 100644 --- a/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj +++ b/iphone/CoreApi/CoreApi.xcodeproj/project.pbxproj @@ -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 = ""; }; 9940621E23EAC57900493D1A /* ElevationHeightPoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElevationHeightPoint.h; sourceTree = ""; }; 9940621F23EAC57900493D1A /* ElevationHeightPoint.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ElevationHeightPoint.m; sourceTree = ""; }; - 99447847238559F2004DAEE5 /* DeeplinkParsingResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeeplinkParsingResult.h; sourceTree = ""; }; + 99447847238559F2004DAEE5 /* DeeplinkUrlType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeeplinkUrlType.h; sourceTree = ""; }; 994C4E0E246C22CA0018EB1E /* MWMUTM+Core.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MWMUTM+Core.h"; sourceTree = ""; }; 9957FACC237AB01400855F48 /* DeepLinkParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeepLinkParser.h; sourceTree = ""; }; 9957FACD237AB01400855F48 /* DeepLinkParser.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DeepLinkParser.mm; sourceTree = ""; }; @@ -658,7 +658,7 @@ 9957FADA237ACB1100855F48 /* DeepLinkSearchData.mm */, 99103841237EDFA200893C9F /* DeepLinkData.h */, 99103842237EDFA200893C9F /* DeepLinkData.m */, - 99447847238559F2004DAEE5 /* DeeplinkParsingResult.h */, + 99447847238559F2004DAEE5 /* DeeplinkUrlType.h */, ); path = Data; sourceTree = ""; @@ -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 */, diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.h b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.h index 18816648a4..54b5eedba0 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.h +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.h @@ -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 -@property (nonatomic, readonly) DeeplinkParsingResult result; +@property (nonatomic, readonly) DeeplinkUrlType urlType; @end @interface DeepLinkData : NSObject -@property (nonatomic, readonly) DeeplinkParsingResult result; +@property (nonatomic, readonly) DeeplinkUrlType urlType; -- (instancetype)init:(DeeplinkParsingResult)result; +- (instancetype)init:(DeeplinkUrlType)urlType; @end diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.m b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.m index aa21503f5c..9063c84e6f 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.m +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkData.m @@ -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; } diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.h b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.h index 395c245d30..5c9baac40a 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.h +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.h @@ -5,14 +5,14 @@ NS_ASSUME_NONNULL_BEGIN @interface DeepLinkSearchData : NSObject -@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 diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.mm b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.mm index 257641ffcb..5be483679d 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.mm +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSearchData.mm @@ -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; diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.h b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.h index 6770763d05..c59a42a8a7 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.h +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.h @@ -5,10 +5,10 @@ NS_ASSUME_NONNULL_BEGIN @interface DeepLinkSubscriptionData : NSObject -@property (nonatomic, readonly) DeeplinkParsingResult result; +@property (nonatomic, readonly) DeeplinkUrlType result; @property(nonatomic, readonly) NSString* groups; -- (instancetype)init:(DeeplinkParsingResult)result; +- (instancetype)init:(DeeplinkUrlType)result; @end diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.mm b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.mm index bd0f912855..94c6cdbca8 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.mm +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeepLinkSubscriptionData.mm @@ -3,7 +3,7 @@ @implementation DeepLinkSubscriptionData -- (instancetype)init:(DeeplinkParsingResult)result { +- (instancetype)init:(DeeplinkUrlType)result { self = [super init]; if (self) { _result = result; diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkParsingResult.h b/iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkParsingResult.h deleted file mode 100644 index 407306e22a..0000000000 --- a/iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkParsingResult.h +++ /dev/null @@ -1,21 +0,0 @@ -#import -#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 diff --git a/iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkUrlType.h b/iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkUrlType.h new file mode 100644 index 0000000000..d7bf0205c5 --- /dev/null +++ b/iphone/CoreApi/CoreApi/DeepLink/Data/DeeplinkUrlType.h @@ -0,0 +1,21 @@ +#import +#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 diff --git a/iphone/CoreApi/CoreApi/DeepLink/DeepLinkParser.mm b/iphone/CoreApi/CoreApi/DeepLink/DeepLinkParser.mm index 152b481fbe..de385d79c3 100644 --- a/iphone/CoreApi/CoreApi/DeepLink/DeepLinkParser.mm +++ b/iphone/CoreApi/CoreApi/DeepLink/DeepLinkParser.mm @@ -3,17 +3,26 @@ #import "DeepLinkData.h" #import "DeepLinkSearchData.h" #import "DeepLinkSubscriptionData.h" -#import "DeeplinkParsingResult.h" +#import "DeeplinkUrlType.h" @implementation DeepLinkParser + (id)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]; diff --git a/iphone/Maps/Core/DeepLink/DeepLinkStrategyFactory.swift b/iphone/Maps/Core/DeepLink/DeepLinkStrategyFactory.swift index ff159ba2cb..3cffba5b30 100644 --- a/iphone/Maps/Core/DeepLink/DeepLinkStrategyFactory.swift +++ b/iphone/Maps/Core/DeepLink/DeepLinkStrategyFactory.swift @@ -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: