diff options
-rw-r--r-- | gyp/platform-ios.gypi | 12 | ||||
-rw-r--r-- | gyp/platform-osx.gypi | 12 | ||||
-rw-r--r-- | platform/darwin/include/MGLDownloadController.h | 30 | ||||
-rw-r--r-- | platform/darwin/include/MGLDownloadable.h | 49 | ||||
-rw-r--r-- | platform/darwin/include/MGLOfflineRegion.h (renamed from platform/darwin/include/MGLDownloadRegion.h) | 2 | ||||
-rw-r--r-- | platform/darwin/include/MGLOfflineStorage.h | 30 | ||||
-rw-r--r-- | platform/darwin/include/MGLOfflineTask.h | 49 | ||||
-rw-r--r-- | platform/darwin/include/MGLTilePyramidOfflineRegion.h (renamed from platform/darwin/include/MGLTilePyramidDownloadRegion.h) | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineRegion_Private.h (renamed from platform/darwin/src/MGLDownloadRegion_Private.h) | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage.mm (renamed from platform/darwin/src/MGLDownloadController.mm) | 54 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineStorage_Private.h (renamed from platform/darwin/src/MGLDownloadController_Private.h) | 6 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineTask.mm (renamed from platform/darwin/src/MGLDownloadable.mm) | 70 | ||||
-rw-r--r-- | platform/darwin/src/MGLOfflineTask_Private.h (renamed from platform/darwin/src/MGLDownloadable_Private.h) | 8 | ||||
-rw-r--r-- | platform/darwin/src/MGLTilePyramidOfflineRegion.mm (renamed from platform/darwin/src/MGLTilePyramidDownloadRegion.mm) | 10 | ||||
-rw-r--r-- | platform/ios/app/MBXDownloadsTableViewController.m | 76 | ||||
-rw-r--r-- | platform/ios/framework/Mapbox.h | 8 | ||||
-rw-r--r-- | platform/ios/framework/Mapbox.m | 6 | ||||
-rw-r--r-- | platform/osx/sdk/Mapbox.h | 8 | ||||
-rw-r--r-- | platform/osx/sdk/Mapbox.m | 10 |
19 files changed, 224 insertions, 224 deletions
diff --git a/gyp/platform-ios.gypi b/gyp/platform-ios.gypi index 15b2fef0cc..bece0a6a6f 100644 --- a/gyp/platform-ios.gypi +++ b/gyp/platform-ios.gypi @@ -44,12 +44,12 @@ '../platform/darwin/src/MGLPolyline.mm', '../platform/darwin/src/MGLPolygon.mm', '../platform/darwin/src/MGLMapCamera.mm', - '../platform/darwin/src/MGLDownloadable.mm', - '../platform/darwin/src/MGLDownloadable_Private.h', - '../platform/darwin/src/MGLDownloadController.mm', - '../platform/darwin/src/MGLDownloadController_Private.h', - '../platform/darwin/src/MGLDownloadRegion_Private.h', - '../platform/darwin/src/MGLTilePyramidDownloadRegion.mm', + '../platform/darwin/src/MGLOfflineTask.mm', + '../platform/darwin/src/MGLOfflineTask_Private.h', + '../platform/darwin/src/MGLOfflineStorage.mm', + '../platform/darwin/src/MGLOfflineStorage_Private.h', + '../platform/darwin/src/MGLOfflineRegion_Private.h', + '../platform/darwin/src/MGLTilePyramidOfflineRegion.mm', '../platform/darwin/src/MGLAccountManager_Private.h', '../platform/darwin/src/MGLAccountManager.m', '../platform/darwin/src/NSBundle+MGLAdditions.h', diff --git a/gyp/platform-osx.gypi b/gyp/platform-osx.gypi index ae09a60d99..252dbdb3cb 100644 --- a/gyp/platform-osx.gypi +++ b/gyp/platform-osx.gypi @@ -43,12 +43,12 @@ '../platform/darwin/src/MGLPolyline.mm', '../platform/darwin/src/MGLPolygon.mm', '../platform/darwin/src/MGLMapCamera.mm', - '../platform/darwin/src/MGLDownloadable.mm', - '../platform/darwin/src/MGLDownloadable_Private.h', - '../platform/darwin/src/MGLDownloadController.mm', - '../platform/darwin/src/MGLDownloadController_Private.h', - '../platform/darwin/src/MGLDownloadRegion_Private.h', - '../platform/darwin/src/MGLTilePyramidDownloadRegion.mm', + '../platform/darwin/src/MGLOfflineTask.mm', + '../platform/darwin/src/MGLOfflineTask_Private.h', + '../platform/darwin/src/MGLOfflineStorage.mm', + '../platform/darwin/src/MGLOfflineStorage_Private.h', + '../platform/darwin/src/MGLOfflineRegion_Private.h', + '../platform/darwin/src/MGLTilePyramidOfflineRegion.mm', '../platform/darwin/src/MGLAccountManager_Private.h', '../platform/darwin/src/MGLAccountManager.m', '../platform/darwin/src/NSBundle+MGLAdditions.h', diff --git a/platform/darwin/include/MGLDownloadController.h b/platform/darwin/include/MGLDownloadController.h deleted file mode 100644 index 86bd1e6573..0000000000 --- a/platform/darwin/include/MGLDownloadController.h +++ /dev/null @@ -1,30 +0,0 @@ -#import <Foundation/Foundation.h> - -#import "MGLTypes.h" - -NS_ASSUME_NONNULL_BEGIN - -@class MGLDownloadable; -@protocol MGLDownloadRegion; - -typedef void (^MGLDownloadableRegistrationCompletionHandler)(MGLDownloadable *downloadable, NSError *error); -typedef void (^MGLDownloadableRemovalCompletionHandler)(NSError *error); -typedef void (^MGLDownloadablesRequestCompletionHandler)(NS_ARRAY_OF(MGLDownloadable *) *downloadables, NSError *error); - -@interface MGLDownloadController : NSObject - -+ (instancetype)sharedController; - -- (instancetype)init NS_UNAVAILABLE; - -- (void)addDownloadableForRegion:(id <MGLDownloadRegion>)downloadRegion withContext:(NSData *)context completionHandler:(MGLDownloadableRegistrationCompletionHandler)completion; - -- (void)removeDownloadable:(MGLDownloadable *)downloadable withCompletionHandler:(MGLDownloadableRemovalCompletionHandler)completion; - -- (void)requestDownloadablesWithCompletionHandler:(MGLDownloadablesRequestCompletionHandler)completion; - -- (void)setMaximumAllowedMapboxTiles:(uint64_t)maximumCount; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/include/MGLDownloadable.h b/platform/darwin/include/MGLDownloadable.h deleted file mode 100644 index 522a3c37ab..0000000000 --- a/platform/darwin/include/MGLDownloadable.h +++ /dev/null @@ -1,49 +0,0 @@ -#import <Foundation/Foundation.h> - -#import "MGLDownloadRegion.h" - -NS_ASSUME_NONNULL_BEGIN - -@protocol MGLDownloadableDelegate; - -typedef NS_ENUM (NSInteger, MGLDownloadableState) { - MGLDownloadableStateInactive = 0, - MGLDownloadableStateActive = 1, - MGLDownloadableStateComplete = 2, -}; - -typedef struct MGLDownloadableProgress { - uint64_t countOfResourcesCompleted; - uint64_t countOfBytesCompleted; - uint64_t countOfResourcesExpected; - uint64_t maximumResourcesExpected; -} MGLDownloadableProgress; - -@interface MGLDownloadable : NSObject - -@property (nonatomic, readonly) id <MGLDownloadRegion> region; -@property (nonatomic, readonly) NSData *context; -@property (nonatomic, readonly) MGLDownloadableState state; -@property (nonatomic, readonly) MGLDownloadableProgress progress; -@property (nonatomic, weak, nullable) id <MGLDownloadableDelegate> delegate; - -- (instancetype)init NS_UNAVAILABLE; - -- (void)resume; -- (void)suspend; - -- (void)requestProgress; - -@end - -@protocol MGLDownloadableDelegate <NSObject> - -@optional - -- (void)downloadable:(MGLDownloadable *)downloadable progressDidChange:(MGLDownloadableProgress)progress; -- (void)downloadable:(MGLDownloadable *)downloadable didReceiveError:(NSError *)error; -- (void)downloadable:(MGLDownloadable *)downloadable didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount; - -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/include/MGLDownloadRegion.h b/platform/darwin/include/MGLOfflineRegion.h index 5910c2117b..6958e3bffe 100644 --- a/platform/darwin/include/MGLDownloadRegion.h +++ b/platform/darwin/include/MGLOfflineRegion.h @@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN -@protocol MGLDownloadRegion <NSObject> +@protocol MGLOfflineRegion <NSObject> @property (nonatomic, readonly) NSURL *styleURL; diff --git a/platform/darwin/include/MGLOfflineStorage.h b/platform/darwin/include/MGLOfflineStorage.h new file mode 100644 index 0000000000..2d33f3ba69 --- /dev/null +++ b/platform/darwin/include/MGLOfflineStorage.h @@ -0,0 +1,30 @@ +#import <Foundation/Foundation.h> + +#import "MGLTypes.h" + +NS_ASSUME_NONNULL_BEGIN + +@class MGLOfflineTask; +@protocol MGLOfflineRegion; + +typedef void (^MGLOfflineTaskRegistrationCompletionHandler)(MGLOfflineTask *task, NSError *error); +typedef void (^MGLOfflineTaskRemovalCompletionHandler)(NSError *error); +typedef void (^MGLOfflineTasksRetrievalCompletionHandler)(NS_ARRAY_OF(MGLOfflineTask *) *tasks, NSError *error); + +@interface MGLOfflineStorage : NSObject + ++ (instancetype)sharedOfflineStorage; + +- (instancetype)init NS_UNAVAILABLE; + +- (void)addTaskForRegion:(id <MGLOfflineRegion>)region withContext:(NSData *)context completionHandler:(MGLOfflineTaskRegistrationCompletionHandler)completion; + +- (void)removeTask:(MGLOfflineTask *)task withCompletionHandler:(MGLOfflineTaskRemovalCompletionHandler)completion; + +- (void)getTasksWithCompletionHandler:(MGLOfflineTasksRetrievalCompletionHandler)completion; + +- (void)setMaximumAllowedMapboxTiles:(uint64_t)maximumCount; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/include/MGLOfflineTask.h b/platform/darwin/include/MGLOfflineTask.h new file mode 100644 index 0000000000..72e66a50f5 --- /dev/null +++ b/platform/darwin/include/MGLOfflineTask.h @@ -0,0 +1,49 @@ +#import <Foundation/Foundation.h> + +#import "MGLOfflineRegion.h" + +NS_ASSUME_NONNULL_BEGIN + +@protocol MGLOfflineTaskDelegate; + +typedef NS_ENUM (NSInteger, MGLOfflineTaskState) { + MGLOfflineTaskStateInactive = 0, + MGLOfflineTaskStateActive = 1, + MGLOfflineTaskStateComplete = 2, +}; + +typedef struct MGLOfflineTaskProgress { + uint64_t countOfResourcesCompleted; + uint64_t countOfBytesCompleted; + uint64_t countOfResourcesExpected; + uint64_t maximumResourcesExpected; +} MGLOfflineTaskProgress; + +@interface MGLOfflineTask : NSObject + +@property (nonatomic, readonly) id <MGLOfflineRegion> region; +@property (nonatomic, readonly) NSData *context; +@property (nonatomic, readonly) MGLOfflineTaskState state; +@property (nonatomic, readonly) MGLOfflineTaskProgress progress; +@property (nonatomic, weak, nullable) id <MGLOfflineTaskDelegate> delegate; + +- (instancetype)init NS_UNAVAILABLE; + +- (void)resume; +- (void)suspend; + +- (void)requestProgress; + +@end + +@protocol MGLOfflineTaskDelegate <NSObject> + +@optional + +- (void)offlineTask:(MGLOfflineTask *)task progressDidChange:(MGLOfflineTaskProgress)progress; +- (void)offlineTask:(MGLOfflineTask *)task didReceiveError:(NSError *)error; +- (void)offlineTask:(MGLOfflineTask *)task didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/include/MGLTilePyramidDownloadRegion.h b/platform/darwin/include/MGLTilePyramidOfflineRegion.h index 6269775f19..7beca3390f 100644 --- a/platform/darwin/include/MGLTilePyramidDownloadRegion.h +++ b/platform/darwin/include/MGLTilePyramidOfflineRegion.h @@ -1,11 +1,11 @@ #import <Foundation/Foundation.h> -#import "MGLDownloadRegion.h" +#import "MGLOfflineRegion.h" #import "MGLGeometry.h" NS_ASSUME_NONNULL_BEGIN -@interface MGLTilePyramidDownloadRegion : NSObject <MGLDownloadRegion> +@interface MGLTilePyramidOfflineRegion : NSObject <MGLOfflineRegion> @property (nonatomic, readonly) MGLCoordinateBounds bounds; @property (nonatomic, readonly) double minimumZoomLevel; diff --git a/platform/darwin/src/MGLDownloadRegion_Private.h b/platform/darwin/src/MGLOfflineRegion_Private.h index 785775198a..41cd5843f6 100644 --- a/platform/darwin/src/MGLDownloadRegion_Private.h +++ b/platform/darwin/src/MGLOfflineRegion_Private.h @@ -1,12 +1,12 @@ #import <Foundation/Foundation.h> -#import "MGLDownloadRegion.h" +#import "MGLOfflineRegion.h" #include <mbgl/storage/offline.hpp> NS_ASSUME_NONNULL_BEGIN -@protocol MGLDownloadRegion_Private <MGLDownloadRegion> +@protocol MGLOfflineRegion_Private <MGLOfflineRegion> - (instancetype)initWithOfflineRegionDefinition:(const mbgl::OfflineRegionDefinition &)definition; diff --git a/platform/darwin/src/MGLDownloadController.mm b/platform/darwin/src/MGLOfflineStorage.mm index 95eae86b53..17537452a3 100644 --- a/platform/darwin/src/MGLDownloadController.mm +++ b/platform/darwin/src/MGLOfflineStorage.mm @@ -1,14 +1,14 @@ -#import "MGLDownloadController_Private.h" +#import "MGLOfflineStorage_Private.h" #import "MGLAccountManager_Private.h" #import "MGLGeometry_Private.h" -#import "MGLDownloadable_Private.h" -#import "MGLDownloadRegion_Private.h" -#import "MGLTilePyramidDownloadRegion.h" +#import "MGLOfflineTask_Private.h" +#import "MGLOfflineRegion_Private.h" +#import "MGLTilePyramidOfflineRegion.h" #include <mbgl/util/string.hpp> -@interface MGLDownloadController () +@interface MGLOfflineStorage () @property (nonatomic) mbgl::DefaultFileSource *mbglFileSource; @@ -16,15 +16,15 @@ @end -@implementation MGLDownloadController +@implementation MGLOfflineStorage -+ (instancetype)sharedController { ++ (instancetype)sharedOfflineStorage { static dispatch_once_t onceToken; - static MGLDownloadController *sharedController; + static MGLOfflineStorage *sharedOfflineStorage; dispatch_once(&onceToken, ^{ - sharedController = [[self alloc] initWithFileName:@"offline.db"]; + sharedOfflineStorage = [[self alloc] initWithFileName:@"offline.db"]; }); - return sharedController; + return sharedOfflineStorage; } - (instancetype)initWithFileName:(NSString *)fileName { @@ -76,17 +76,17 @@ } } -- (void)addDownloadableForRegion:(id <MGLDownloadRegion>)downloadRegion withContext:(NSData *)context completionHandler:(MGLDownloadableRegistrationCompletionHandler)completion { - if (![downloadRegion conformsToProtocol:@protocol(MGLDownloadRegion_Private)]) { +- (void)addTaskForRegion:(id <MGLOfflineRegion>)region withContext:(NSData *)context completionHandler:(MGLOfflineTaskRegistrationCompletionHandler)completion { + if (![region conformsToProtocol:@protocol(MGLOfflineRegion_Private)]) { [NSException raise:@"Unsupported region type" format: - @"Regions of type %@ are unsupported.", NSStringFromClass([downloadRegion class])]; + @"Regions of type %@ are unsupported.", NSStringFromClass([region class])]; return; } - const mbgl::OfflineTilePyramidRegionDefinition regionDefinition = [(id <MGLDownloadRegion_Private>)downloadRegion offlineRegionDefinition]; + const mbgl::OfflineTilePyramidRegionDefinition regionDefinition = [(id <MGLOfflineRegion_Private>)region offlineRegionDefinition]; mbgl::OfflineRegionMetadata metadata(context.length); [context getBytes:&metadata[0] length:metadata.size()]; - self.mbglFileSource->createOfflineRegion(regionDefinition, metadata, [&, completion](std::exception_ptr exception, mbgl::optional<mbgl::OfflineRegion> region) { + self.mbglFileSource->createOfflineRegion(regionDefinition, metadata, [&, completion](std::exception_ptr exception, mbgl::optional<mbgl::OfflineRegion> mbglOfflineRegion) { NSError *error; if (exception) { NSString *errorDescription = @(mbgl::util::toString(exception).c_str()); @@ -95,16 +95,16 @@ } : nil]; } if (completion) { - MGLDownloadable *downloadable = [[MGLDownloadable alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(*region))]; - dispatch_async(dispatch_get_main_queue(), [&, completion, error, downloadable](void) { - completion(downloadable, error); + MGLOfflineTask *task = [[MGLOfflineTask alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(*mbglOfflineRegion))]; + dispatch_async(dispatch_get_main_queue(), [&, completion, error, task](void) { + completion(task, error); }); } }); } -- (void)removeDownloadable:(MGLDownloadable *)downloadable withCompletionHandler:(MGLDownloadableRemovalCompletionHandler)completion { - self.mbglFileSource->deleteOfflineRegion(std::move(*downloadable.mbglOfflineRegion), [&, completion](std::exception_ptr exception) { +- (void)removeTask:(MGLOfflineTask *)task withCompletionHandler:(MGLOfflineTaskRemovalCompletionHandler)completion { + self.mbglFileSource->deleteOfflineRegion(std::move(*task.mbglOfflineRegion), [&, completion](std::exception_ptr exception) { NSError *error; if (exception) { error = [NSError errorWithDomain:MGLErrorDomain code:-1 userInfo:@{ @@ -119,7 +119,7 @@ }); } -- (void)requestDownloadablesWithCompletionHandler:(MGLDownloadablesRequestCompletionHandler)completion { +- (void)getTasksWithCompletionHandler:(MGLOfflineTasksRetrievalCompletionHandler)completion { self.mbglFileSource->listOfflineRegions([&, completion](std::exception_ptr exception, mbgl::optional<std::vector<mbgl::OfflineRegion>> regions) { NSError *error; if (exception) { @@ -127,17 +127,17 @@ NSLocalizedDescriptionKey: @(mbgl::util::toString(exception).c_str()), }]; } - NSMutableArray *downloadables; + NSMutableArray *tasks; if (regions) { - downloadables = [NSMutableArray arrayWithCapacity:regions->size()]; + tasks = [NSMutableArray arrayWithCapacity:regions->size()]; for (mbgl::OfflineRegion ®ion : *regions) { - MGLDownloadable *downloadable = [[MGLDownloadable alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(region))]; - [downloadables addObject:downloadable]; + MGLOfflineTask *task = [[MGLOfflineTask alloc] initWithMBGLRegion:new mbgl::OfflineRegion(std::move(region))]; + [tasks addObject:task]; } } if (completion) { - dispatch_async(dispatch_get_main_queue(), [&, completion, error, downloadables](void) { - completion(downloadables, error); + dispatch_async(dispatch_get_main_queue(), [&, completion, error, tasks](void) { + completion(tasks, error); }); } }); diff --git a/platform/darwin/src/MGLDownloadController_Private.h b/platform/darwin/src/MGLOfflineStorage_Private.h index 2e26ab90cb..48f87a7785 100644 --- a/platform/darwin/src/MGLDownloadController_Private.h +++ b/platform/darwin/src/MGLOfflineStorage_Private.h @@ -1,12 +1,12 @@ -#import "MGLDownloadController.h" +#import "MGLOfflineStorage.h" -#import "MGLDownloadable.h" +#import "MGLOfflineTask.h" #include <mbgl/storage/default_file_source.hpp> NS_ASSUME_NONNULL_BEGIN -@interface MGLDownloadController (Private) +@interface MGLOfflineStorage (Private) @property (nonatomic) mbgl::DefaultFileSource *mbglFileSource; diff --git a/platform/darwin/src/MGLDownloadable.mm b/platform/darwin/src/MGLOfflineTask.mm index 507461b4b7..a5b6e66031 100644 --- a/platform/darwin/src/MGLDownloadable.mm +++ b/platform/darwin/src/MGLOfflineTask.mm @@ -1,40 +1,40 @@ -#import "MGLDownloadable_Private.h" +#import "MGLOfflineTask_Private.h" -#import "MGLDownloadController_Private.h" -#import "MGLDownloadRegion_Private.h" -#import "MGLTilePyramidDownloadRegion.h" +#import "MGLOfflineStorage_Private.h" +#import "MGLOfflineRegion_Private.h" +#import "MGLTilePyramidOfflineRegion.h" #include <mbgl/storage/default_file_source.hpp> #include <mbgl/util/string.hpp> class MBGLOfflineRegionObserver; -@interface MGLDownloadable () +@interface MGLOfflineTask () @property (nonatomic, readwrite) mbgl::OfflineRegion *mbglOfflineRegion; @property (nonatomic, readwrite) MBGLOfflineRegionObserver *mbglOfflineRegionObserver; -@property (nonatomic, readwrite) MGLDownloadableState state; -@property (nonatomic, readwrite) MGLDownloadableProgress progress; +@property (nonatomic, readwrite) MGLOfflineTaskState state; +@property (nonatomic, readwrite) MGLOfflineTaskProgress progress; @end -@implementation MGLDownloadable +@implementation MGLOfflineTask - (instancetype)init { [NSException raise:@"Method unavailable" format: - @"-[MGLDownloadable init] is unavailable. " - @"Use +[MGLDownloadController addDownloadRegion:context:completionHandler:] instead."]; + @"-[MGLOfflineTask init] is unavailable. " + @"Use +[MGLOfflineStorage addTaskForRegion:withContext:completionHandler:] instead."]; return nil; } - (instancetype)initWithMBGLRegion:(mbgl::OfflineRegion *)region { if (self = [super init]) { _mbglOfflineRegion = region; - _state = MGLDownloadableStateInactive; + _state = MGLOfflineTaskStateInactive; _mbglOfflineRegionObserver = new MBGLOfflineRegionObserver(self); - mbgl::DefaultFileSource *mbglFileSource = [[MGLDownloadController sharedController] mbglFileSource]; + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionObserver(*_mbglOfflineRegion, std::make_unique<MBGLOfflineRegionObserver>(*_mbglOfflineRegionObserver)); } return self; @@ -45,10 +45,10 @@ class MBGLOfflineRegionObserver; _mbglOfflineRegionObserver = nullptr; } -- (id <MGLDownloadRegion>)region { +- (id <MGLOfflineRegion>)region { const mbgl::OfflineRegionDefinition ®ionDefinition = _mbglOfflineRegion->getDefinition(); - NSAssert([MGLTilePyramidDownloadRegion conformsToProtocol:@protocol(MGLDownloadRegion_Private)], @"MGLTilePyramidDownloadRegion should conform to MGLDownloadRegion_Private."); - return [(id <MGLDownloadRegion_Private>)[MGLTilePyramidDownloadRegion alloc] initWithOfflineRegionDefinition:regionDefinition]; + NSAssert([MGLTilePyramidOfflineRegion conformsToProtocol:@protocol(MGLOfflineRegion_Private)], @"MGLTilePyramidOfflineRegion should conform to MGLOfflineRegion_Private."); + return [(id <MGLOfflineRegion_Private>)[MGLTilePyramidOfflineRegion alloc] initWithOfflineRegionDefinition:regionDefinition]; } - (NSData *)context { @@ -57,26 +57,26 @@ class MBGLOfflineRegionObserver; } - (void)resume { - mbgl::DefaultFileSource *mbglFileSource = [[MGLDownloadController sharedController] mbglFileSource]; + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Active); - self.state = MGLDownloadableStateActive; + self.state = MGLOfflineTaskStateActive; } - (void)suspend { - mbgl::DefaultFileSource *mbglFileSource = [[MGLDownloadController sharedController] mbglFileSource]; + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Inactive); - self.state = MGLDownloadableStateInactive; + self.state = MGLOfflineTaskStateInactive; } - (void)requestProgress { - mbgl::DefaultFileSource *mbglFileSource = [[MGLDownloadController sharedController] mbglFileSource]; + mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource]; - __weak MGLDownloadable *weakSelf = self; + __weak MGLOfflineTask *weakSelf = self; mbglFileSource->getOfflineRegionStatus(*_mbglOfflineRegion, [&, weakSelf](__unused std::exception_ptr exception, mbgl::optional<mbgl::OfflineRegionStatus> status) { if (status) { mbgl::OfflineRegionStatus checkedStatus = *status; dispatch_async(dispatch_get_main_queue(), ^{ - MGLDownloadable *strongSelf = weakSelf; + MGLOfflineTask *strongSelf = weakSelf; [strongSelf offlineRegionStatusDidChange:checkedStatus]; }); } @@ -86,23 +86,23 @@ class MBGLOfflineRegionObserver; - (void)offlineRegionStatusDidChange:(mbgl::OfflineRegionStatus)status { switch (status.downloadState) { case mbgl::OfflineRegionDownloadState::Inactive: - self.state = status.complete() ? MGLDownloadableStateComplete : MGLDownloadableStateInactive; + self.state = status.complete() ? MGLOfflineTaskStateComplete : MGLOfflineTaskStateInactive; break; case mbgl::OfflineRegionDownloadState::Active: - self.state = MGLDownloadableStateActive; + self.state = MGLOfflineTaskStateActive; break; } - MGLDownloadableProgress progress; + MGLOfflineTaskProgress progress; progress.countOfResourcesCompleted = status.completedResourceCount; progress.countOfBytesCompleted = status.completedResourceSize; progress.countOfResourcesExpected = status.requiredResourceCount; progress.maximumResourcesExpected = status.requiredResourceCountIsPrecise ? status.requiredResourceCount : UINT64_MAX; self.progress = progress; - if ([self.delegate respondsToSelector:@selector(downloadable:progressDidChange:)]) { - [self.delegate downloadable:self progressDidChange:progress]; + if ([self.delegate respondsToSelector:@selector(offlineTask:progressDidChange:)]) { + [self.delegate offlineTask:self progressDidChange:progress]; } } @@ -131,28 +131,28 @@ NSError *MGLErrorFromResponseError(mbgl::Response::Error error) { void MBGLOfflineRegionObserver::statusChanged(mbgl::OfflineRegionStatus status) { dispatch_async(dispatch_get_main_queue(), ^{ - NSCAssert(downloadable, @"MBGLOfflineRegionObserver is dangling without an associated MGLDownloadable."); + NSCAssert(offlineTask, @"MBGLOfflineRegionObserver is dangling without an associated MGLOfflineTask."); - [downloadable offlineRegionStatusDidChange:status]; + [offlineTask offlineRegionStatusDidChange:status]; }); } void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) { dispatch_async(dispatch_get_main_queue(), ^{ - NSCAssert(downloadable, @"MBGLOfflineRegionObserver is dangling without an associated MGLDownloadable."); + NSCAssert(offlineTask, @"MBGLOfflineRegionObserver is dangling without an associated MGLOfflineTask."); - if ([downloadable.delegate respondsToSelector:@selector(downloadable:didReceiveError:)]) { - [downloadable.delegate downloadable:downloadable didReceiveError:MGLErrorFromResponseError(error)]; + if ([offlineTask.delegate respondsToSelector:@selector(offlineTask:didReceiveError:)]) { + [offlineTask.delegate offlineTask:offlineTask didReceiveError:MGLErrorFromResponseError(error)]; } }); } void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) { dispatch_async(dispatch_get_main_queue(), ^{ - NSCAssert(downloadable, @"MBGLOfflineRegionObserver is dangling without an associated MGLDownloadable."); + NSCAssert(offlineTask, @"MBGLOfflineRegionObserver is dangling without an associated MGLOfflineTask."); - if ([downloadable.delegate respondsToSelector:@selector(downloadable:didReceiveMaximumAllowedMapboxTiles:)]) { - [downloadable.delegate downloadable:downloadable didReceiveMaximumAllowedMapboxTiles:limit]; + if ([offlineTask.delegate respondsToSelector:@selector(offlineTask:didReceiveMaximumAllowedMapboxTiles:)]) { + [offlineTask.delegate offlineTask:offlineTask didReceiveMaximumAllowedMapboxTiles:limit]; } }); } diff --git a/platform/darwin/src/MGLDownloadable_Private.h b/platform/darwin/src/MGLOfflineTask_Private.h index a9b2460c19..ad0e597a8d 100644 --- a/platform/darwin/src/MGLDownloadable_Private.h +++ b/platform/darwin/src/MGLOfflineTask_Private.h @@ -1,10 +1,10 @@ -#import "MGLDownloadable.h" +#import "MGLOfflineTask.h" #include <mbgl/storage/default_file_source.hpp> class MBGLOfflineRegionObserver; -@interface MGLDownloadable (Private) +@interface MGLOfflineTask (Private) @property (nonatomic) mbgl::OfflineRegion *mbglOfflineRegion; @property (nonatomic, readonly) MBGLOfflineRegionObserver *mbglOfflineRegionObserver; @@ -15,12 +15,12 @@ class MBGLOfflineRegionObserver; class MBGLOfflineRegionObserver : public mbgl::OfflineRegionObserver { public: - MBGLOfflineRegionObserver(MGLDownloadable *downloadable_) : downloadable(downloadable_) {} + MBGLOfflineRegionObserver(MGLOfflineTask *offlineTask_) : offlineTask(offlineTask_) {} void statusChanged(mbgl::OfflineRegionStatus status) override; void responseError(mbgl::Response::Error error) override; void mapboxTileCountLimitExceeded(uint64_t limit) override; private: - __weak MGLDownloadable *downloadable = nullptr; + __weak MGLOfflineTask *offlineTask = nullptr; }; diff --git a/platform/darwin/src/MGLTilePyramidDownloadRegion.mm b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm index 94c0ac6358..3d51917c3e 100644 --- a/platform/darwin/src/MGLTilePyramidDownloadRegion.mm +++ b/platform/darwin/src/MGLTilePyramidOfflineRegion.mm @@ -1,18 +1,18 @@ -#import "MGLTilePyramidDownloadRegion.h" +#import "MGLTilePyramidOfflineRegion.h" #if !TARGET_OS_IPHONE && !TARGET_OS_SIMULATOR #import <Cocoa/Cocoa.h> #endif -#import "MGLDownloadRegion_Private.h" +#import "MGLOfflineRegion_Private.h" #import "MGLGeometry_Private.h" #import "MGLStyle.h" -@interface MGLTilePyramidDownloadRegion () <MGLDownloadRegion_Private> +@interface MGLTilePyramidOfflineRegion () <MGLOfflineRegion_Private> @end -@implementation MGLTilePyramidDownloadRegion { +@implementation MGLTilePyramidOfflineRegion { NSURL *_styleURL; } @@ -21,7 +21,7 @@ - (instancetype)init { [NSException raise:@"Method unavailable" format: - @"-[MGLTilePyramidDownloadRegion init] is unavailable. " + @"-[MGLTilePyramidOfflineRegion init] is unavailable. " @"Use -initWithStyleURL:bounds:fromZoomLevel:toZoomLevel: instead."]; return nil; } diff --git a/platform/ios/app/MBXDownloadsTableViewController.m b/platform/ios/app/MBXDownloadsTableViewController.m index db80fdef52..db79d77d3e 100644 --- a/platform/ios/app/MBXDownloadsTableViewController.m +++ b/platform/ios/app/MBXDownloadsTableViewController.m @@ -2,26 +2,26 @@ #import <Mapbox/Mapbox.h> -static NSString * const MBXDownloadContextNameKey = @"Name"; +static NSString * const MBXOfflineTaskContextNameKey = @"Name"; static NSString * const MBXDownloadsTableViewInactiveCellReuseIdentifier = @"Inactive"; static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Active"; -@implementation MGLDownloadable (MBXAdditions) +@implementation MGLOfflineTask (MBXAdditions) - (NSString *)name { NSDictionary *userInfo = [NSKeyedUnarchiver unarchiveObjectWithData:self.context]; - NSAssert([userInfo isKindOfClass:[NSDictionary class]], @"Context of downloadable isn’t a dictionary."); - NSString *name = userInfo[MBXDownloadContextNameKey]; - NSAssert([name isKindOfClass:[NSString class]], @"Name of downloadable isn’t a string."); + NSAssert([userInfo isKindOfClass:[NSDictionary class]], @"Context of offline task isn’t a dictionary."); + NSString *name = userInfo[MBXOfflineTaskContextNameKey]; + NSAssert([name isKindOfClass:[NSString class]], @"Name of offline task isn’t a string."); return name; } @end -@interface MBXDownloadsTableViewController () <MGLDownloadableDelegate> +@interface MBXDownloadsTableViewController () <MGLOfflineTaskDelegate> -@property (nonatomic, strong) NS_MUTABLE_ARRAY_OF(MGLDownloadable *) *downloadables; +@property (nonatomic, strong) NS_MUTABLE_ARRAY_OF(MGLOfflineTask *) *offlineTasks; @end @@ -33,14 +33,14 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ [super viewDidLoad]; __weak MBXDownloadsTableViewController *weakSelf = self; - [[MGLDownloadController sharedController] requestDownloadablesWithCompletionHandler:^(NS_ARRAY_OF(MGLDownloadable *) *downloadables, NSError *error) { + [[MGLOfflineStorage sharedOfflineStorage] getTasksWithCompletionHandler:^(NS_ARRAY_OF(MGLOfflineTask *) *tasks, NSError *error) { MBXDownloadsTableViewController *strongSelf = weakSelf; - strongSelf.downloadables = downloadables.mutableCopy; + strongSelf.offlineTasks = tasks.mutableCopy; [strongSelf.tableView reloadData]; - for (MGLDownloadable *downloadable in strongSelf.downloadables) { - downloadable.delegate = strongSelf; - [downloadable requestProgress]; + for (MGLOfflineTask *task in strongSelf.offlineTasks) { + task.delegate = strongSelf; + [task requestProgress]; } if (error) { @@ -67,13 +67,13 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ name = [NSString stringWithFormat:@"Untitled %lu", (unsigned long)++_untitledRegionCount]; } - MGLTilePyramidDownloadRegion *region = [[MGLTilePyramidDownloadRegion alloc] initWithStyleURL:mapView.styleURL bounds:mapView.visibleCoordinateBounds fromZoomLevel:mapView.zoomLevel toZoomLevel:mapView.maximumZoomLevel]; + MGLTilePyramidOfflineRegion *region = [[MGLTilePyramidOfflineRegion alloc] initWithStyleURL:mapView.styleURL bounds:mapView.visibleCoordinateBounds fromZoomLevel:mapView.zoomLevel toZoomLevel:mapView.maximumZoomLevel]; NSData *context = [NSKeyedArchiver archivedDataWithRootObject:@{ - MBXDownloadContextNameKey: name, + MBXOfflineTaskContextNameKey: name, }]; __weak MBXDownloadsTableViewController *weakSelf = self; - [[MGLDownloadController sharedController] addDownloadableForRegion:region withContext:context completionHandler:^(MGLDownloadable *downloadable, NSError *error) { + [[MGLOfflineStorage sharedOfflineStorage] addTaskForRegion:region withContext:context completionHandler:^(MGLOfflineTask *task, NSError *error) { MBXDownloadsTableViewController *strongSelf = weakSelf; if (error) { NSString *message = [NSString stringWithFormat:@"Mapbox GL was unable to add the download “%@”.", name]; @@ -81,11 +81,11 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; [self presentViewController:alertController animated:YES completion:nil]; } else { - downloadable.delegate = strongSelf; - [downloadable resume]; + task.delegate = strongSelf; + [task resume]; - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:strongSelf.downloadables.count inSection:0]; - [strongSelf.downloadables addObject:downloadable]; + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:strongSelf.offlineTasks.count inSection:0]; + [strongSelf.offlineTasks addObject:task]; [strongSelf.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; } }]; @@ -99,16 +99,16 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.downloadables.count; + return self.offlineTasks.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - MGLDownloadable *downloadable = self.downloadables[indexPath.row]; + MGLOfflineTask *task = self.offlineTasks[indexPath.row]; - NSString *reuseIdentifier = downloadable.state == MGLDownloadableStateActive ? MBXDownloadsTableViewActiveCellReuseIdentifier : MBXDownloadsTableViewInactiveCellReuseIdentifier; + NSString *reuseIdentifier = task.state == MGLOfflineTaskStateActive ? MBXDownloadsTableViewActiveCellReuseIdentifier : MBXDownloadsTableViewInactiveCellReuseIdentifier; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier forIndexPath:indexPath]; - cell.textLabel.text = downloadable.name; - MGLDownloadableProgress progress = downloadable.progress; + cell.textLabel.text = task.name; + MGLOfflineTaskProgress progress = task.progress; NSString *completedString = [NSNumberFormatter localizedStringFromNumber:@(progress.countOfResourcesCompleted) numberStyle:NSNumberFormatterDecimalStyle]; NSString *expectedString = [NSNumberFormatter localizedStringFromNumber:@(progress.countOfResourcesExpected) @@ -116,14 +116,14 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ NSString *byteCountString = [NSByteCountFormatter stringFromByteCount:progress.countOfBytesCompleted countStyle:NSByteCountFormatterCountStyleFile]; NSString *statusString; - switch (downloadable.state) { - case MGLDownloadableStateInactive: - case MGLDownloadableStateComplete: + switch (task.state) { + case MGLOfflineTaskStateInactive: + case MGLOfflineTaskStateComplete: statusString = [NSString stringWithFormat:@"%@ of %@ resources (%@)", completedString, expectedString, byteCountString]; break; - case MGLDownloadableStateActive: + case MGLOfflineTaskStateActive: if (progress.countOfResourcesExpected) { completedString = [NSNumberFormatter localizedStringFromNumber:@(progress.countOfResourcesCompleted + 1) numberStyle:NSNumberFormatterDecimalStyle]; @@ -142,20 +142,20 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { - MGLDownloadable *downloadable = self.downloadables[indexPath.row]; + MGLOfflineTask *task = self.offlineTasks[indexPath.row]; __weak MBXDownloadsTableViewController *weakSelf = self; - [[MGLDownloadController sharedController] removeDownloadable:downloadable withCompletionHandler:^(NSError *error) { + [[MGLOfflineStorage sharedOfflineStorage] removeTask:task withCompletionHandler:^(NSError *error) { MBXDownloadsTableViewController *strongSelf = weakSelf; - [strongSelf.downloadables removeObjectAtIndex:indexPath.row]; + [strongSelf.offlineTasks removeObjectAtIndex:indexPath.row]; [strongSelf.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }]; } } -#pragma mark - Downloadable delegate +#pragma mark - Offline task delegate -- (void)downloadable:(MGLDownloadable *)downloadable progressDidChange:(MGLDownloadableProgress)progress { - NSUInteger index = [self.downloadables indexOfObject:downloadable]; +- (void)offlineTask:(MGLOfflineTask *)task progressDidChange:(MGLOfflineTaskProgress)progress { + NSUInteger index = [self.offlineTasks indexOfObject:task]; if (index == NSNotFound) { return; } @@ -164,12 +164,12 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone]; } -- (void)downloadable:(MGLDownloadable *)downloadable didReceiveError:(NSError *)error { - NSLog(@"Downloadable “%@” received error: %@", downloadable.name, error.localizedFailureReason); +- (void)offlineTask:(MGLOfflineTask *)task didReceiveError:(NSError *)error { + NSLog(@"Offline task “%@” received error: %@", task.name, error.localizedFailureReason); } -- (void)downloadable:(MGLDownloadable *)downloadable didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount { - NSLog(@"Downloadable “%@” reached limit of %llu tiles.", downloadable.name, maximumCount); +- (void)offlineTask:(MGLOfflineTask *)task didReceiveMaximumAllowedMapboxTiles:(uint64_t)maximumCount { + NSLog(@"Offline task “%@” reached limit of %llu tiles.", task.name, maximumCount); } @end diff --git a/platform/ios/framework/Mapbox.h b/platform/ios/framework/Mapbox.h index f13a542ac2..f88a75c8c5 100644 --- a/platform/ios/framework/Mapbox.h +++ b/platform/ios/framework/Mapbox.h @@ -12,19 +12,19 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import "MGLCalloutView.h" #import "MGLMapCamera.h" #import "MGLGeometry.h" -#import "MGLDownloadable.h" -#import "MGLDownloadRegion.h" -#import "MGLDownloadController.h" #import "MGLMapView.h" #import "MGLMapView+IBAdditions.h" #import "MGLMapView+MGLCustomStyleLayerAdditions.h" #import "MGLMultiPoint.h" +#import "MGLOfflineRegion.h" +#import "MGLOfflineStorage.h" +#import "MGLOfflineTask.h" #import "MGLOverlay.h" #import "MGLPointAnnotation.h" #import "MGLPolygon.h" #import "MGLPolyline.h" #import "MGLShape.h" #import "MGLStyle.h" -#import "MGLTilePyramidDownloadRegion.h" +#import "MGLTilePyramidOfflineRegion.h" #import "MGLTypes.h" #import "MGLUserLocation.h" diff --git a/platform/ios/framework/Mapbox.m b/platform/ios/framework/Mapbox.m index cc3be1e2b2..094cbd3506 100644 --- a/platform/ios/framework/Mapbox.m +++ b/platform/ios/framework/Mapbox.m @@ -17,16 +17,16 @@ static void InitializeMapbox() { [MGLAccountManager class]; [MGLAnnotationImage class]; - [MGLDownloadable class]; - [MGLDownloadController class]; [MGLMapCamera class]; [MGLMapView class]; [MGLMultiPoint class]; + [MGLOfflineStorage class]; + [MGLOfflineTask class]; [MGLPointAnnotation class]; [MGLPolygon class]; [MGLPolyline class]; [MGLShape class]; [MGLStyle class]; - [MGLTilePyramidDownloadRegion class]; + [MGLTilePyramidOfflineRegion class]; [MGLUserLocation class]; } diff --git a/platform/osx/sdk/Mapbox.h b/platform/osx/sdk/Mapbox.h index 018d16b3c0..62f050130b 100644 --- a/platform/osx/sdk/Mapbox.h +++ b/platform/osx/sdk/Mapbox.h @@ -9,20 +9,20 @@ FOUNDATION_EXPORT const unsigned char MapboxVersionString[]; #import <Mapbox/MGLAccountManager.h> #import <Mapbox/MGLAnnotation.h> #import <Mapbox/MGLAnnotationImage.h> -#import <Mapbox/MGLDownloadable.h> -#import <Mapbox/MGLDownloadRegion.h> -#import <Mapbox/MGLDownloadController.h> #import <Mapbox/MGLGeometry.h> #import <Mapbox/MGLMapCamera.h> #import <Mapbox/MGLMapView.h> #import <Mapbox/MGLMapView+IBAdditions.h> #import <Mapbox/MGLMapViewDelegate.h> #import <Mapbox/MGLMultiPoint.h> +#import <Mapbox/MGLOfflineRegion.h> +#import <Mapbox/MGLOfflineStorage.h> +#import <Mapbox/MGLOfflineTask.h> #import <Mapbox/MGLOverlay.h> #import <Mapbox/MGLPointAnnotation.h> #import <Mapbox/MGLPolygon.h> #import <Mapbox/MGLPolyline.h> #import <Mapbox/MGLShape.h> #import <Mapbox/MGLStyle.h> -#import <Mapbox/MGLTilePyramidDownloadRegion.h> +#import <Mapbox/MGLTilePyramidOfflineRegion.h> #import <Mapbox/MGLTypes.h> diff --git a/platform/osx/sdk/Mapbox.m b/platform/osx/sdk/Mapbox.m index 5246124088..2ec28260d2 100644 --- a/platform/osx/sdk/Mapbox.m +++ b/platform/osx/sdk/Mapbox.m @@ -1,8 +1,8 @@ #import <Mapbox/Mapbox.h> #import "../src/MGLMapView_Private.h" -#import "../src/NSBundle+MGLAdditions.h" -#import "../src/NSProcessInfo+MGLAdditions.h" +#import "../../darwin/src/NSBundle+MGLAdditions.h" +#import "../../darwin/src/NSProcessInfo+MGLAdditions.h" #import "../../darwin/src/NSString+MGLAdditions.h" __attribute__((constructor)) @@ -19,15 +19,15 @@ static void InitializeMapbox() { [MGLAccountManager class]; [MGLAnnotationImage class]; - [MGLDownloadable class]; - [MGLDownloadController class]; [MGLMapCamera class]; [MGLMapView class]; [MGLMultiPoint class]; + [MGLOfflineStorage class]; + [MGLOfflineTask class]; [MGLPointAnnotation class]; [MGLPolygon class]; [MGLPolyline class]; [MGLShape class]; [MGLStyle class]; - [MGLTilePyramidDownloadRegion class]; + [MGLTilePyramidOfflineRegion class]; } |