[ios] Correctly access current location mode.

This commit is contained in:
Alex Zolotarev 2016-02-25 13:53:46 +03:00 committed by Sergey Yershov
parent 3765367744
commit c89818f243
7 changed files with 19 additions and 17 deletions

View file

@ -474,10 +474,7 @@ extern NSString * const kAlohalyticsTapEventKey;
{
MWMAlertViewController * controller = [[MWMAlertViewController alloc] initWithViewController:self.ownerController];
LocationManager * manager = MapsAppDelegate.theApp.m_locationManager;
auto const m = [MWMFrameworkListener listener].myPositionMode;
BOOL const needToRebuild = manager.lastLocationIsValid &&
m != location::MODE_PENDING_POSITION &&
m != location::MODE_UNKNOWN_POSITION && !isDestinationMyPosition;
BOOL const needToRebuild = manager.lastLocationIsValid && !manager.isLocationModeUnknownOrPending && !isDestinationMyPosition;
m2::PointD const locationPoint = manager.lastLocation.mercator;
[controller presentPoint2PointAlertWithOkBlock:^
{

View file

@ -8,8 +8,6 @@
+ (void)addObserver:(id<MWMFrameworkObserver>)observer;
+ (void)removeObserver:(id<MWMFrameworkObserver>)observer;
@property (nonatomic) location::EMyPositionMode myPositionMode;
- (instancetype)init __attribute__((unavailable("call +listener instead")));
- (instancetype)copy __attribute__((unavailable("call +listener instead")));
- (instancetype)copyWithZone:(NSZone *)zone __attribute__((unavailable("call +listener instead")));

View file

@ -1,5 +1,6 @@
#import "LocationManager.h"
#import "MapsAppDelegate.h"
#import "MWMBasePlacePageView.h"
#import "MWMFrameworkListener.h"
#import "MWMPlacePage.h"
#import "MWMPlacePageActionBar.h"
#import "MWMPlacePageBookmarkCell.h"
@ -196,9 +197,7 @@ enum class AttributePosition
BOOL const isMyPosition = entity.isMyPosition;
self.addressLabel.text = entity.address;
BOOL const isHeadingAvaible = [CLLocationManager headingAvailable];
using namespace location;
auto const mode = [MWMFrameworkListener listener].myPositionMode;
BOOL const noLocation = (mode == EMyPositionMode::MODE_UNKNOWN_POSITION || mode == EMyPositionMode::MODE_PENDING_POSITION);
BOOL const noLocation = MapsAppDelegate.theApp.m_locationManager.isLocationModeUnknownOrPending;
self.distanceLabel.hidden = noLocation || isMyPosition;
BOOL const hideDirection = noLocation || isMyPosition || !isHeadingAvaible;
self.directionArrow.hidden = hideDirection;

View file

@ -187,11 +187,10 @@ extern NSString * const kBookmarksChangedNotification;
[[Statistics instance] logEvent:kStatEventName(kStatPlacePage, kStatBuildRoute)
withParameters:@{kStatValue : kStatDestination}];
[Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"ppRoute"];
m2::PointD const myPosition([MapsAppDelegate theApp].m_locationManager.lastLocation.mercator);
using namespace location;
auto const mode = MWMFrameworkListener.listener.myPositionMode;
bool const knownPosition = (mode != EMyPositionMode::MODE_UNKNOWN_POSITION && mode != EMyPositionMode::MODE_PENDING_POSITION);
[self.delegate buildRouteFrom:knownPosition ? MWMRoutePoint(myPosition) : MWMRoutePoint::MWMRoutePointZero()
LocationManager * lm = MapsAppDelegate.theApp.m_locationManager;
[self.delegate buildRouteFrom:lm.isLocationModeUnknownOrPending ? MWMRoutePoint::MWMRoutePointZero()
: MWMRoutePoint(lm.lastLocation.mercator)
to:{self.entity.mercator, self.placePage.basePlacePageView.titleLabel.text}];
}

View file

@ -497,8 +497,7 @@ NSString * const kEditorSegue = @"Map2EditorSegue";
// TODO: Review and improve this code.
f.SetMyPositionModeListener([self](location::EMyPositionMode mode)
{
MWMFrameworkListener.listener.myPositionMode = mode;
// Two global listeners are subscribed to the same event from the core.
// TODO: Two global listeners are subscribed to the same event from the core.
// Probably it's better to subscribe only wnen needed and usubscribe in other cases.
// May be better solution would be multiobservers support in the C++ core.
[self processMyPositionStateModeEvent:mode];

View file

@ -40,6 +40,7 @@
- (NSString *)formattedSpeedAndAltitude:(BOOL &)hasSpeed;
- (bool)lastLocationIsValid;
- (bool)isLocationModeUnknownOrPending;
- (BOOL)enabledOnMap;
- (void)triggerCompass;

View file

@ -343,6 +343,15 @@ static NSString * const kAlohalyticsLocationRequestAlwaysFailed = @"$locationAlw
return (([self lastLocation] != nil) && ([m_lastLocationTime timeIntervalSinceNow] > -300.0));
}
- (bool)isLocationModeUnknownOrPending
{
using location::EMyPositionMode;
EMyPositionMode mode;
if (!Settings::Get(Settings::kLocationStateMode, mode))
return true;
return mode == EMyPositionMode::MODE_PENDING_POSITION || mode == EMyPositionMode::MODE_UNKNOWN_POSITION;
}
- (BOOL)enabledOnMap
{
for (id observer in m_observers)