[ios] Catalog opening logic is changed

This commit is contained in:
Arsentiy Milchakov 2019-07-12 12:54:32 +03:00 committed by Aleksey Belousov
parent c9d128b640
commit 5dbb86d11d
6 changed files with 45 additions and 26 deletions

View file

@ -32,19 +32,31 @@ final class CatalogWebViewController: WebViewController {
var toolbar = UIToolbar()
var billing = InAppPurchase.inAppBilling()
@objc init(_ deeplinkURL: URL? = nil, utm: MWMUTM = .none) {
@objc static func catalogFromAbsoluteUrl(_ url: URL? = nil, utm: MWMUTM = .none) -> CatalogWebViewController {
return CatalogWebViewController(url, utm:utm, isAbsoluteUrl:true)
}
@objc static func catalogFromDeeplink(_ url: URL, utm: MWMUTM = .none) -> CatalogWebViewController {
return CatalogWebViewController(url, utm:utm)
}
private init(_ url: URL? = nil, utm: MWMUTM = .none, isAbsoluteUrl: Bool = false) {
var catalogUrl = MWMBookmarksManager.shared().catalogFrontendUrl(utm)!
if let dl = deeplinkURL {
if dl.host == "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, utm: utm) {
catalogUrl = url
}
if let u = url {
if isAbsoluteUrl {
catalogUrl = u
} else {
deeplink = deeplinkURL
if u.host == "guides_page" {
if let urlComponents = URLComponents(url: u, resolvingAgainstBaseURL: false),
let path = urlComponents.queryItems?.reduce(into: "", { if $1.name == "url" { $0 = $1.value } }),
let calculatedUrl = MWMBookmarksManager.shared().catalogFrontendUrlPlusPath(path, utm: utm) {
catalogUrl = calculatedUrl
}
} else {
deeplink = url
}
Statistics.logEvent(kStatCatalogOpen, withParameters: [kStatFrom : kStatDeeplink])
}
Statistics.logEvent(kStatCatalogOpen, withParameters: [kStatFrom : kStatDeeplink])
}
super.init(url: catalogUrl, title: L("guides_catalogue_title"))!
backButton = UIBarButtonItem(image: #imageLiteral(resourceName: "ic_catalog_back"), style: .plain, target: self, action: #selector(onBack))

View file

@ -58,7 +58,7 @@ class DownloadedBookmarksViewController: MWMViewController {
return
}
Statistics.logEvent(kStatCatalogOpen, withParameters: [kStatFrom: kStatDownloaded])
let webViewController = CatalogWebViewController(nil, utm: .bookmarksPageCatalogButton)
let webViewController = CatalogWebViewController.catalogFromAbsoluteUrl(nil, utm: .bookmarksPageCatalogButton)
MapViewController.topViewController().navigationController?.pushViewController(webViewController,
animated: true)
}

View file

@ -34,9 +34,8 @@
- (void)showUGCAuth;
- (void)showBookmarksLoadedAlert:(UInt64)categoryId;
- (void)openCatalogAnimated:(BOOL)animated utm:(MWMUTM)utm;
- (void)openCatalogDeeplink:(NSURL * _Nullable)deeplinkUrl
animated:(BOOL)animated
utm:(MWMUTM)utm;
- (void)openCatalogDeeplink:(NSURL *)deeplinkUrl animated:(BOOL)animated utm:(MWMUTM)utm;
- (void)openCatalogAbsoluteUrl:(NSURL *)url animated:(BOOL)animated utm:(MWMUTM)utm;
- (void)searchText:(NSString *)text;
- (void)openDrivingOptions;

View file

@ -507,25 +507,33 @@ BOOL gIsFirstMyPositionMode = YES;
- (void)openCatalogAnimated:(BOOL)animated utm:(MWMUTM)utm
{
[Statistics logEvent:kStatCatalogOpen withParameters:@{kStatFrom : kStatMenu}];
[self openCatalogDeeplink:nil animated:animated utm:utm];
[self openCatalogAbsoluteUrl:nil animated:animated utm:utm];
}
- (void)openCatalogDeeplink:(NSURL *)deeplinkUrl animated:(BOOL)animated utm:(MWMUTM)utm
- (void)openCatalogInternal:(MWMCatalogWebViewController *)catalog animated:(BOOL)animated utm:(MWMUTM)utm
{
[self.navigationController popToRootViewControllerAnimated:NO];
auto bookmarks = [[MWMBookmarksTabViewController alloc] init];
bookmarks.activeTab = ActiveTabCatalog;
MWMCatalogWebViewController *catalog;
if (deeplinkUrl)
catalog = [[MWMCatalogWebViewController alloc] init:deeplinkUrl utm:utm];
else
catalog = [[MWMCatalogWebViewController alloc] init:nil utm:utm];
NSMutableArray<UIViewController *> * controllers = [self.navigationController.viewControllers mutableCopy];
[controllers addObjectsFromArray:@[bookmarks, catalog]];
[self.navigationController setViewControllers:controllers animated:animated];
}
- (void)openCatalogDeeplink:(NSURL *)deeplinkUrl animated:(BOOL)animated utm:(MWMUTM)utm
{
MWMCatalogWebViewController *catalog;
catalog = [MWMCatalogWebViewController catalogFromDeeplink:deeplinkUrl utm:utm];
[self openCatalogInternal:catalog animated:animated utm:utm];
}
- (void)openCatalogAbsoluteUrl:(NSURL *)url animated:(BOOL)animated utm:(MWMUTM)utm
{
MWMCatalogWebViewController *catalog;
catalog = [MWMCatalogWebViewController catalogFromAbsoluteUrl:url utm:utm];
[self openCatalogInternal:catalog animated:animated utm:utm];
}
- (void)searchText:(NSString *)text
{
[self.controlsManager searchText:text forInputLocale:[[AppInfo sharedInfo] languageId]];

View file

@ -344,8 +344,8 @@ struct Callback
- (void)openCatalogForURL:(NSURL *)url {
auto bookmarks = [[MWMBookmarksTabViewController alloc] init];
bookmarks.activeTab = ActiveTabCatalog;
// NOTE: UTM is already is URL, core part does it for Discovery page.
MWMCatalogWebViewController *catalog = [[MWMCatalogWebViewController alloc] init:url utm:MWMUTMNone];
// NOTE: UTM is already into URL, core part does it for Discovery page.
MWMCatalogWebViewController *catalog = [MWMCatalogWebViewController catalogFromAbsoluteUrl:url utm:MWMUTMNone];
NSMutableArray<UIViewController *> * controllers = [self.navigationController.viewControllers mutableCopy];
[controllers addObjectsFromArray:@[bookmarks, catalog]];
[self.navigationController setViewControllers:controllers animated:YES];

View file

@ -791,8 +791,8 @@ void RegisterEventIfPossible(eye::MapObject::Event::Type const type, place_page:
- (void)openCatalogForURL:(NSURL *)url {
auto bookmarks = [[MWMBookmarksTabViewController alloc] init];
bookmarks.activeTab = ActiveTabCatalog;
// NOTE: UTM is already is URL, core part does it for Placepage Gallery.
MWMCatalogWebViewController *catalog = [[MWMCatalogWebViewController alloc] init:url utm:MWMUTMNone];
// NOTE: UTM is already into URL, core part does it for Placepage Gallery.
MWMCatalogWebViewController *catalog = [MWMCatalogWebViewController catalogFromAbsoluteUrl:url utm:MWMUTMNone];
NSMutableArray<UIViewController *> * controllers = [self.ownerViewController.navigationController.viewControllers mutableCopy];
[controllers addObjectsFromArray:@[bookmarks, catalog]];
[self.ownerViewController.navigationController setViewControllers:controllers animated:YES];