Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[ios, macos] Ignore progress updates after suspending
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Aug 27, 2016
1 parent f4be826 commit adf5733
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions platform/darwin/src/MGLOfflinePack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ @interface MGLOfflinePack ()

@end

@implementation MGLOfflinePack
@implementation MGLOfflinePack {
BOOL _isSuspending;
}

- (instancetype)init {
if (self = [super init]) {
Expand Down Expand Up @@ -93,6 +95,11 @@ - (void)resume {
- (void)suspend {
MGLAssertOfflinePackIsValid();

if (self.state == MGLOfflinePackStateActive) {
self.state = MGLOfflinePackStateInactive;
_isSuspending = YES;
}

mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
mbglFileSource->setOfflineRegionDownloadState(*_mbglOfflineRegion, mbgl::OfflineRegionDownloadState::Inactive);
}
Expand All @@ -117,7 +124,10 @@ - (void)setState:(MGLOfflinePackState)state {

NSAssert(_state != MGLOfflinePackStateInvalid, @"Cannot change the state of an invalid offline pack.");

_state = state;
if (!_isSuspending || state != MGLOfflinePackStateActive) {
_isSuspending = NO;
_state = state;
}
}

- (void)requestProgress {
Expand Down Expand Up @@ -150,6 +160,10 @@ - (void)offlineRegionStatusDidChange:(mbgl::OfflineRegionStatus)status {
break;
}

if (_isSuspending) {
return;
}

MGLOfflinePackProgress progress;
progress.countOfResourcesCompleted = status.completedResourceCount;
progress.countOfBytesCompleted = status.completedResourceSize;
Expand Down

0 comments on commit adf5733

Please sign in to comment.