From 4e6ca0ec96a16108c39ec8451d3d6b0122f87d5a Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Wed, 17 Jul 2019 14:13:50 +0300 Subject: [PATCH] [ios] Improved location mode --- .../Maps/Classes/CarPlay/CarPlayService.swift | 3 ++ iphone/Maps/Classes/MapViewController.mm | 53 ++++++++----------- .../Location/MWMLocationModeListener.h | 1 + .../Maps/Core/Location/MWMLocationManager.h | 1 + .../Maps/Core/Location/MWMLocationManager.mm | 4 ++ 5 files changed, 30 insertions(+), 32 deletions(-) diff --git a/iphone/Maps/Classes/CarPlay/CarPlayService.swift b/iphone/Maps/Classes/CarPlay/CarPlayService.swift index 8ce2268db4..58ec04fb1f 100644 --- a/iphone/Maps/Classes/CarPlay/CarPlayService.swift +++ b/iphone/Maps/Classes/CarPlay/CarPlayService.swift @@ -532,6 +532,9 @@ extension CarPlayService: LocationModeListener { break } } + + func processMyPositionPendingTimeout() { + } } // MARK: - Alerts and Trip Previews diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm index 51badaeb71..8734b71ada 100644 --- a/iphone/Maps/Classes/MapViewController.mm +++ b/iphone/Maps/Classes/MapViewController.mm @@ -52,10 +52,6 @@ NSString * const kEditorSegue = @"Map2EditorSegue"; NSString * const kUDViralAlertWasShown = @"ViralAlertWasShown"; NSString * const kPP2BookmarkEditingSegue = @"PP2BookmarkEditing"; NSString * const kHotelFacilitiesSegue = @"Map2FacilitiesSegue"; - -// The first launch after process started. Used to skip "Not follow, no position" state and to run -// locator. -BOOL gIsFirstMyPositionMode = YES; } // namespace @interface NSValueWrapper : NSObject @@ -269,8 +265,7 @@ BOOL gIsFirstMyPositionMode = YES; [MWMRouter restoreRouteIfNeeded]; self.view.clipsToBounds = YES; - self.currentPositionMode = MWMMyPositionModePendingPosition; - [self processMyPositionStateModeEvent:self.currentPositionMode]; + [self processMyPositionStateModeEvent:MWMMyPositionModePendingPosition]; [MWMKeyboard addObserver:self]; self.welcomePageController = [MWMWelcomePageController controllerWithParent:self]; if ([MWMNavigationDashboardManager manager].state == MWMNavigationDashboardStateHidden) @@ -390,6 +385,9 @@ BOOL gIsFirstMyPositionMode = YES; // May be better solution would be multiobservers support in the C++ core. [self processMyPositionStateModeEvent:location_helpers::mwmMyPositionMode(mode)]; }); + f.SetMyPositionPendingTimeoutListener([self]{ + [self processMyPositionPendingTimeout]; + }); self.userTouchesAction = UserTouchesActionNone; [[MWMBookmarksManager sharedManager] loadBookmarks]; @@ -565,36 +563,27 @@ BOOL gIsFirstMyPositionMode = YES; self.disableStandbyOnLocationStateMode = NO; switch (mode) { - case MWMMyPositionModeNotFollowNoPosition: - { - BOOL const hasLocation = [MWMLocationManager lastLocation] != nil; - if (hasLocation) - { - GetFramework().SwitchMyPositionNextMode(); - break; - } - if ([Alohalytics isFirstSession]) - break; - if (gIsFirstMyPositionMode) - { - GetFramework().SwitchMyPositionNextMode(); - break; - } - BOOL const isMapVisible = (self.navigationController.visibleViewController == self); - if (isMapVisible && ![MWMLocationManager isLocationProhibited]) - { - [self.alertController presentLocationNotFoundAlertWithOkBlock:^{ - GetFramework().SwitchMyPositionNextMode(); - }]; - } - break; - } - case MWMMyPositionModePendingPosition: + case MWMMyPositionModeNotFollowNoPosition: break; + case MWMMyPositionModePendingPosition: [MWMLocationManager start]; break; case MWMMyPositionModeNotFollow: break; case MWMMyPositionModeFollow: case MWMMyPositionModeFollowAndRotate: self.disableStandbyOnLocationStateMode = YES; break; } - gIsFirstMyPositionMode = NO; +} + +- (void)processMyPositionPendingTimeout { + [MWMLocationManager stop]; + NSArray> * objects = self.listeners.allObjects; + for (id object in objects) { + [object processMyPositionPendingTimeout]; + } + BOOL const isMapVisible = (self.navigationController.visibleViewController == self); + if (isMapVisible && ![MWMLocationManager isLocationProhibited]) + { + [self.alertController presentLocationNotFoundAlertWithOkBlock:^{ + GetFramework().SwitchMyPositionNextMode(); + }]; + } } #pragma mark - MWMRemoveAdsViewControllerDelegate diff --git a/iphone/Maps/Core/Framework/ProxyObjects/Location/MWMLocationModeListener.h b/iphone/Maps/Core/Framework/ProxyObjects/Location/MWMLocationModeListener.h index 744a423ac9..9cfc9949a8 100644 --- a/iphone/Maps/Core/Framework/ProxyObjects/Location/MWMLocationModeListener.h +++ b/iphone/Maps/Core/Framework/ProxyObjects/Location/MWMLocationModeListener.h @@ -4,6 +4,7 @@ NS_ASSUME_NONNULL_BEGIN NS_SWIFT_NAME(LocationModeListener) @protocol MWMLocationModeListener - (void)processMyPositionStateModeEvent:(MWMMyPositionMode)mode; +- (void)processMyPositionPendingTimeout; @end NS_ASSUME_NONNULL_END diff --git a/iphone/Maps/Core/Location/MWMLocationManager.h b/iphone/Maps/Core/Location/MWMLocationManager.h index 0503fd3cfc..ede5ee84a5 100644 --- a/iphone/Maps/Core/Location/MWMLocationManager.h +++ b/iphone/Maps/Core/Location/MWMLocationManager.h @@ -5,6 +5,7 @@ @interface MWMLocationManager : NSObject + (void)start; ++ (void)stop; + (void)addObserver:(id)observer; + (void)removeObserver:(id)observer; diff --git a/iphone/Maps/Core/Location/MWMLocationManager.mm b/iphone/Maps/Core/Location/MWMLocationManager.mm index df6c8aab1b..73adb6e018 100644 --- a/iphone/Maps/Core/Location/MWMLocationManager.mm +++ b/iphone/Maps/Core/Location/MWMLocationManager.mm @@ -193,7 +193,11 @@ void setPermissionRequested() [NSNotificationCenter.defaultCenter removeObserver:self]; self.locationManager.delegate = nil; } + + (void)start { [self manager].started = YES; } + ++ (void)stop { [self manager].started = NO; } + #pragma mark - Add/Remove Observers + (void)addObserver:(Observer)observer