diff options
author | Ilya Grechuhin <i.grechuhin@mapswithme.com> | 2015-05-27 11:01:23 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:49:40 +0300 |
commit | 72740cd15dae576de1de90dc6f972e10b90994b2 (patch) | |
tree | 9c9d92d3cc37c8dbc94f37c6f40372e6b9250bec /iphone/Maps/Classes/RouteState | |
parent | b9bd35435e1c87763afe9d5d3222b979a546cb7a (diff) |
[ios] Restore active routing.
Diffstat (limited to 'iphone/Maps/Classes/RouteState')
-rw-r--r-- | iphone/Maps/Classes/RouteState/RouteState.h | 23 | ||||
-rw-r--r-- | iphone/Maps/Classes/RouteState/RouteState.mm | 80 |
2 files changed, 103 insertions, 0 deletions
diff --git a/iphone/Maps/Classes/RouteState/RouteState.h b/iphone/Maps/Classes/RouteState/RouteState.h new file mode 100644 index 0000000000..87f177a4fc --- /dev/null +++ b/iphone/Maps/Classes/RouteState/RouteState.h @@ -0,0 +1,23 @@ +// +// RouteState.h +// Maps +// +// Created by Ilya Grechuhin on 26.05.15. +// Copyright (c) 2015 MapsWithMe. All rights reserved. +// + +#import <Foundation/Foundation.h> + +#include <geometry/point2d.hpp> + +@interface RouteState : NSObject + +@property (nonatomic, readonly) BOOL hasActualRoute; +@property (nonatomic) m2::PointD endPoint; + ++ (instancetype)savedState; + ++ (void)save; ++ (void)remove; + +@end diff --git a/iphone/Maps/Classes/RouteState/RouteState.mm b/iphone/Maps/Classes/RouteState/RouteState.mm new file mode 100644 index 0000000000..f01d162e63 --- /dev/null +++ b/iphone/Maps/Classes/RouteState/RouteState.mm @@ -0,0 +1,80 @@ +// +// RouteState.m +// Maps +// +// Created by Ilya Grechuhin on 26.05.15. +// Copyright (c) 2015 MapsWithMe. All rights reserved. +// + +#import "RouteState.h" +#import "Framework.h" + +static NSString * const kEndPointKey = @"endPoint"; +static NSString * const kETAKey = @"eta"; + +@interface RouteState() + +@property (nonatomic) NSDate * eta; + +@end + +@implementation RouteState + ++ (instancetype)savedState +{ + RouteState * const state = [[super alloc] init]; + if (state) + { + NSDictionary * const stateDict = [NSDictionary dictionaryWithContentsOfURL:[RouteState stateFileURL]]; + if (stateDict) + { + m2::PointD point; + NSUInteger size; + NSGetSizeAndAlignment(@encode(m2::PointD), &size, NULL); + NSData const * const endPointData = stateDict[kEndPointKey]; + NSDate * const eta = stateDict[kETAKey]; + if (endPointData && eta) + { + [endPointData getBytes:&point length:size]; + state.endPoint = point; + state.eta = eta; + } + } + } + return state; +} + ++ (void)save +{ + Framework & f = GetFramework(); + if (!f.IsRoutingActive()) + return; + location::FollowingInfo routeInfo; + f.GetRouteFollowingInfo(routeInfo); + m2::PointD const endPoint = f.GetRouteEndPoint(); + NSMutableDictionary * const stateDict = [NSMutableDictionary dictionary]; + NSUInteger size; + NSGetSizeAndAlignment(@encode(m2::PointD), &size, nullptr); + stateDict[kEndPointKey] = [NSData dataWithBytes:&endPoint length:size]; + stateDict[kETAKey] = [NSDate dateWithTimeIntervalSinceNow:routeInfo.m_time]; + [stateDict writeToURL:[RouteState stateFileURL] atomically:YES]; +} + ++ (void)remove +{ + [[NSFileManager defaultManager] removeItemAtURL:[RouteState stateFileURL] error:nil]; +} + ++ (NSURL *)stateFileURL +{ + return [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"route_info.ini"]]; +} + +#pragma mark - Properties + +- (BOOL)hasActualRoute +{ + return [self.eta compare:[NSDate date]] == NSOrderedDescending; +} + +@end |