[ios, osx] Distinguish between unknown and inactive state

This commit is contained in:
Minh Nguyễn
2016-03-09 08:50:45 -08:00
committed by Minh Nguyễn
parent 68ba0712f7
commit 77d99584ce
3 changed files with 38 additions and 14 deletions

View File

@@ -11,27 +11,44 @@ NS_ASSUME_NONNULL_BEGIN
*/
typedef NS_ENUM (NSInteger, MGLOfflineTaskState) {
/**
The task is incomplete and is not currently downloading. This is the
initial state of a task that is added using the
`-[MGLOfflineStorage addTaskForRegion:withContext:completionHandler:]`
method.
It is unknown whether the task is inactive, active, or complete.
This is the initial state of a task that is obtained using the
`-[MGLOfflineStorage getTasksWithCompletionHandler:]` method. The state
becomes known by the time the task’s delegate receives its first progress
update. For inactive tasks, you must explicitly request a progress update
using the `-[MGLOfflineTask requestProgress]` method.
An invalid task always has a state of `MGLOfflineTaskStateInvalid`, never
`MGLOfflineTaskStateUnknown`.
*/
MGLOfflineTaskStateInactive = 0,
MGLOfflineTaskStateUnknown = 0,
/**
The task is incomplete and is currently downloading. This is the state of a
task after the `-[MGLOfflineTask resume]` method is called.
The task is incomplete and is not currently downloading.
This is the initial state of a task that is created using the
`-[MGLOfflineTask addTaskForRegion:withContext:completionHandler:]` method,
as well as after the `-[MGLOfflineTask suspend]` method is
called.
*/
MGLOfflineTaskStateActive = 1,
MGLOfflineTaskStateInactive = 1,
/**
The task is incomplete and is currently downloading.
This is the state of a task after the `-[MGLOfflineTask resume]` method is
called.
*/
MGLOfflineTaskStateActive = 2,
/**
The task has downloaded to completion.
*/
MGLOfflineTaskStateComplete = 2,
MGLOfflineTaskStateComplete = 3,
/**
The task has been removed using the
`-[MGLOfflineStorage removeTask:withCompletionHandler:]` method. Any
messages sent to the task will raise an exception.
`-[MGLOfflineStorage removeTask:withCompletionHandler:]` method. Sending
any message to the task will raise an exception.
*/
MGLOfflineTaskStateInvalid = 3,
MGLOfflineTaskStateInvalid = 4,
};
/**
@@ -91,7 +108,7 @@ typedef struct MGLOfflineTaskProgress {
The task’s current state.
The state of an inactive or completed task is computed lazily and is set to
`MGLOfflineTaskStateInactive` by default. If you need the state of a task
`MGLOfflineTaskStateUnknown` by default. If you need the state of a task
inside an `MGLOfflineTaskListingCompletionHandler`, set the `delegate` property
then call the `-requestProgress` method.
*/

View File

@@ -51,7 +51,7 @@ private:
- (instancetype)initWithMBGLRegion:(mbgl::OfflineRegion *)region {
if (self = [super init]) {
_mbglOfflineRegion = region;
_state = MGLOfflineTaskStateInactive;
_state = MGLOfflineTaskStateUnknown;
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
MBGLOfflineRegionObserver *mbglObserver = new MBGLOfflineRegionObserver(self);

View File

@@ -126,6 +126,10 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ
countStyle:NSByteCountFormatterCountStyleFile];
NSString *statusString;
switch (task.state) {
case MGLOfflineTaskStateUnknown:
statusString = @"Calculating progress…";
break;
case MGLOfflineTaskStateInactive:
statusString = [NSString stringWithFormat:@"%@ of %@ resources (%@)",
completedString, expectedString, byteCountString];
@@ -176,6 +180,9 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ
MGLOfflineTask *task = self.offlineTasks[indexPath.row];
switch (task.state) {
case MGLOfflineTaskStateUnknown:
break;
case MGLOfflineTaskStateComplete:
if ([task.region respondsToSelector:@selector(applyToMapView:)]) {
[task.region performSelector:@selector(applyToMapView:) withObject:self.mapView];