Skip to content

Commit

Permalink
[ios] Remove updateFrameworkInfo from LocationManager
Browse files Browse the repository at this point in the history
The LocationManager updates the framework location quite complicated. On every
location update the LocationManager sets the frameworkUpdateMode property. The
setter of this property calls updateFrameworkInfo and passes the update to the
framework. A quick test revealed that calling the framework directly without
going over the property also works. Removing the frameworkUpdateMode property
and the updateFrmeworkInfo makes the code clearer and easier to read.

Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
  • Loading branch information
fabwu authored and biodranik committed Aug 14, 2024
1 parent e2ca702 commit ab6d10b
Showing 1 changed file with 3 additions and 59 deletions.
62 changes: 3 additions & 59 deletions iphone/Maps/Core/Location/MWMLocationManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import "MWMLocationObserver.h"
#import "MWMLocationPredictor.h"
#import "MWMRouter.h"
#import "MapsAppDelegate.h"
#import "SwiftBridge.h"
#import "location_util.h"

Expand All @@ -16,13 +15,6 @@
using Observer = id<MWMLocationObserver>;
using Observers = NSHashTable<Observer>;

typedef NS_OPTIONS(NSUInteger, MWMLocationFrameworkUpdate) {
MWMLocationFrameworkUpdateNone = 0,
MWMLocationFrameworkUpdateLocation = 1 << 0,
MWMLocationFrameworkUpdateHeading = 1 << 1,
MWMLocationFrameworkUpdateStatus = 1 << 2
};

enum class GeoMode
{
Pending,
Expand Down Expand Up @@ -162,7 +154,6 @@ @interface MWMLocationManager ()<CLLocationManagerDelegate>
@property(nonatomic) MWMLocationStatus lastLocationStatus;
@property(nonatomic) MWMLocationPredictor * predictor;
@property(nonatomic) Observers * observers;
@property(nonatomic) MWMLocationFrameworkUpdate frameworkUpdateMode;
@property(nonatomic) location::TLocationSource locationSource;

@end
Expand Down Expand Up @@ -272,7 +263,7 @@ - (void)processLocationStatus:(MWMLocationStatus)locationStatus
LOG(LINFO, ("Location status updated from", DebugPrint(self.lastLocationStatus), "to", DebugPrint(locationStatus)));
self.lastLocationStatus = locationStatus;
if (self.lastLocationStatus != MWMLocationStatusNoError)
self.frameworkUpdateMode |= MWMLocationFrameworkUpdateStatus;
GetFramework().OnLocationError((location::TLocationError)self.lastLocationStatus);
for (Observer observer in self.observers)
{
if ([observer respondsToSelector:@selector(onLocationError:)])
Expand All @@ -283,8 +274,7 @@ - (void)processLocationStatus:(MWMLocationStatus)locationStatus
- (void)processHeadingUpdate:(CLHeading *)headingInfo
{
self.lastHeadingInfo = headingInfo;
self.frameworkUpdateMode |= MWMLocationFrameworkUpdateHeading;
// location::CompassInfo const compassInfo = compassInfoFromHeading(headingInfo);
GetFramework().OnCompassUpdate(location_util::compassInfoFromHeading(headingInfo));
for (Observer observer in self.observers)
{
if ([observer respondsToSelector:@selector(onHeadingUpdate:)])
Expand All @@ -305,10 +295,10 @@ - (void)onLocationUpdate:(CLLocation *)locationInfo source:(location::TLocationS
{
location::GpsInfo const gpsInfo = location_util::gpsInfoFromLocation(locationInfo, source);
GpsTracker::Instance().OnLocationUpdated(gpsInfo);
GetFramework().OnLocationUpdate(gpsInfo);

self.lastLocationInfo = locationInfo;
self.locationSource = source;
self.frameworkUpdateMode |= MWMLocationFrameworkUpdateLocation;
for (Observer observer in self.observers)
{
if ([observer respondsToSelector:@selector(onLocationUpdate:)])
Expand Down Expand Up @@ -588,52 +578,6 @@ - (void)stop
[locationManager stopUpdatingHeading];
}

#pragma mark - Framework

- (void)updateFrameworkInfo
{
auto app = UIApplication.sharedApplication;
auto delegate = static_cast<MapsAppDelegate *>(app.delegate);
if (delegate.isDrapeEngineCreated)
{
auto & f = GetFramework();
if (self.frameworkUpdateMode & MWMLocationFrameworkUpdateLocation)
{
location::GpsInfo const gpsInfo =
location_util::gpsInfoFromLocation(self.lastLocationInfo, self.locationSource);
f.OnLocationUpdate(gpsInfo);
}
if (self.frameworkUpdateMode & MWMLocationFrameworkUpdateHeading)
f.OnCompassUpdate(location_util::compassInfoFromHeading(self.lastHeadingInfo));
if (self.frameworkUpdateMode & MWMLocationFrameworkUpdateStatus)
f.OnLocationError((location::TLocationError)self.lastLocationStatus);
self.frameworkUpdateMode = MWMLocationFrameworkUpdateNone;
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[self updateFrameworkInfo];
});
}
}

#pragma mark - Property

- (void)setFrameworkUpdateMode:(MWMLocationFrameworkUpdate)frameworkUpdateMode
{
if (frameworkUpdateMode != _frameworkUpdateMode &&
_frameworkUpdateMode == MWMLocationFrameworkUpdateNone &&
frameworkUpdateMode != MWMLocationFrameworkUpdateNone)
{
_frameworkUpdateMode = frameworkUpdateMode;
[self updateFrameworkInfo];
}
else
{
_frameworkUpdateMode = frameworkUpdateMode;
}
}

#pragma mark - Location alert

+ (void)enableLocationAlert {
Expand Down

0 comments on commit ab6d10b

Please sign in to comment.