[iOS] add 'guides_page' deeplink

This commit is contained in:
Aleksey Belouosv 2019-04-25 18:21:44 +03:00 committed by Arsentiy Milchakov
parent 0db85d14ba
commit 7042a5d405
6 changed files with 70 additions and 9 deletions

View file

@ -31,8 +31,20 @@ final class CatalogWebViewController: WebViewController {
var fwdButton: UIBarButtonItem!
var toolbar = UIToolbar()
@objc init() {
super.init(url: MWMBookmarksManager.shared().catalogFrontendUrl()!, title: L("guides"))!
@objc init(_ deeplinkURL: URL? = nil) {
var catalogUrl = MWMBookmarksManager.shared().catalogFrontendUrl()!
if let dl = deeplinkURL {
if dl.path == "/guides_page" {
if let urlComponents = URLComponents(url: dl, resolvingAgainstBaseURL: false),
let path = urlComponents.queryItems?.reduce(into: "", { if $1.name == "url" { $0 = $1.value } }),
let url = MWMBookmarksManager.shared().catalogFrontendUrlPlusPath(path) {
catalogUrl = url
}
} else {
deeplink = deeplinkURL
}
}
super.init(url: catalogUrl, title: L("guides"))!
backButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_catalog_back"), style: .plain, target: self, action: #selector(onBack))
fwdButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_catalog_fwd"), style: .plain, target: self, action: #selector(onFwd))
backButton.tintColor = .blackSecondaryText()
@ -45,11 +57,6 @@ final class CatalogWebViewController: WebViewController {
fatalError("init(coder:) has not been implemented")
}
@objc convenience init(_ deeplinkURL: URL) {
self.init()
deeplink = deeplinkURL
}
override func viewDidLoad() {
super.viewDidLoad()

View file

@ -91,6 +91,9 @@ static NSInteger const kSearchInViewportZoom = 16;
case ParsedMapApi::ParsingResult::Catalogue:
[MapViewController.sharedController openCatalogDeeplink:url animated:NO];
break;
case ParsedMapApi::ParsingResult::CataloguePath:
[MapViewController.sharedController openCatalogDeeplink:url animated:NO];
break;
case ParsedMapApi::ParsingResult::Lead: break;
}
}

View file

@ -59,6 +59,7 @@ typedef void (^LoadTagsCompletionBlock)(NSArray<MWMTagGroup *> * _Nullable tags,
- (BOOL)areNotificationsEnabled;
- (NSURL * _Nullable)catalogFrontendUrl;
- (NSURL * _Nullable)catalogFrontendUrlPlusPath:(NSString *)path;
- (NSURL * _Nullable)sharingUrlForCategoryId:(MWMMarkGroupID)groupId;
- (NSURL * _Nullable)webEditorUrlForCategoryId:(MWMMarkGroupID)groupId;
- (void)downloadItemWithId:(NSString *)itemId

View file

@ -545,6 +545,12 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
return urlString ? [NSURL URLWithString:urlString] : nil;
}
- (NSURL * _Nullable)catalogFrontendUrlPlusPath:(NSString *)path
{
NSString * urlString = @(self.bm.GetCatalog().GetFrontendUrl().c_str());
return urlString ? [NSURL URLWithString:[urlString stringByAppendingString:path]] : nil;
}
- (NSURL *)sharingUrlForCategoryId:(MWMMarkGroupID)groupId
{
NSString * urlString = @(self.bm.GetCategoryCatalogDeeplink(groupId).c_str());

View file

@ -102,6 +102,11 @@ char const * kId = "id";
char const * kName = "name";
}
namespace cataloguePath
{
char const * kUrl = "url";
}
namespace
{
enum class ApiURLType
@ -111,7 +116,8 @@ enum class ApiURLType
Route,
Search,
Lead,
Catalogue
Catalogue,
CataloguePath
};
std::array<std::string, 3> const kAvailableSchemes = {{"mapswithme", "mwm", "mapsme"}};
@ -132,6 +138,8 @@ ApiURLType URLType(Uri const & uri)
return ApiURLType::Lead;
if (path == "catalogue")
return ApiURLType::Catalogue;
if (path == "guides_page")
return ApiURLType::CataloguePath;
return ApiURLType::Incorrect;
}
@ -284,6 +292,23 @@ ParsedMapApi::ParsingResult ParsedMapApi::Parse(Uri const & uri)
m_catalogItem = item;
return ParsingResult::Catalogue;
}
case ApiURLType::CataloguePath:
{
CatalogPathItem item;
auto const result = uri.ForEachKeyValue([&item, this](string const & key, string const & value)
{
return CatalogPathKeyValue(key, value, item);
});
if (!result)
return ParsingResult::Incorrect;
if (item.m_url.empty())
return ParsingResult::Incorrect;
m_catalogPathItem = item;
return ParsingResult::CataloguePath;
}
}
UNREACHABLE();
}
@ -473,6 +498,16 @@ bool ParsedMapApi::CatalogKeyValue(string const & key, string const & value, Cat
return true;
}
bool ParsedMapApi::CatalogPathKeyValue(string const & key, string const & value, CatalogPathItem & item) const
{
using namespace cataloguePath;
if (key == kUrl)
item.m_url = value;
return true;
}
void ParsedMapApi::Reset()
{
m_globalBackUrl.clear();

View file

@ -43,6 +43,11 @@ struct CatalogItem
string m_name;
};
struct CatalogPathItem
{
string m_url;
};
namespace lead
{
struct CampaignDescription;
@ -61,7 +66,8 @@ public:
Route,
Search,
Lead,
Catalogue
Catalogue,
CataloguePath
};
ParsedMapApi() = default;
@ -83,6 +89,7 @@ public:
string const & GetRoutingType() const { return m_routingType; }
SearchRequest const & GetSearchRequest() const { return m_request; }
CatalogItem const & GetCatalogItem() const { return m_catalogItem; }
CatalogPathItem const & GetCatalogPathItem() const { return m_catalogPathItem; }
private:
ParsingResult Parse(Uri const & uri);
bool AddKeyValue(string const & key, string const & value, vector<ApiPoint> & points);
@ -90,11 +97,13 @@ private:
bool SearchKeyValue(string const & key, string const & value, SearchRequest & request) const;
bool LeadKeyValue(string const & key, string const & value, lead::CampaignDescription & description) const;
bool CatalogKeyValue(string const & key, string const & value, CatalogItem & item) const;
bool CatalogPathKeyValue(string const & key, string const & value, CatalogPathItem & item) const;
BookmarkManager * m_bmManager = nullptr;
vector<RoutePoint> m_routePoints;
SearchRequest m_request;
CatalogItem m_catalogItem;
CatalogPathItem m_catalogPathItem;
string m_globalBackUrl;
string m_appTitle;
string m_routingType;