[ios] Tap to pause/resume
Tapping on a download now pauses or resumes it. Tapping on a completed download navigates to the downloaded region and switches to the downloaded style.
This commit is contained in:
committed by
Minh Nguyễn
parent
f5ac63dfec
commit
0348c1ee96
@@ -19,6 +19,15 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLTilePyramidOfflineRegion (MBXAdditions)
|
||||
|
||||
- (void)applyToMapView:(MGLMapView *)mapView {
|
||||
mapView.styleURL = self.styleURL;
|
||||
[mapView setVisibleCoordinateBounds:self.bounds];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface MBXDownloadsTableViewController () <MGLOfflineTaskDelegate>
|
||||
|
||||
@property (nonatomic, strong) NS_MUTABLE_ARRAY_OF(MGLOfflineTask *) *offlineTasks;
|
||||
@@ -118,11 +127,15 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ
|
||||
NSString *statusString;
|
||||
switch (task.state) {
|
||||
case MGLOfflineTaskStateInactive:
|
||||
case MGLOfflineTaskStateComplete:
|
||||
statusString = [NSString stringWithFormat:@"%@ of %@ resources (%@)",
|
||||
completedString, expectedString, byteCountString];
|
||||
break;
|
||||
|
||||
case MGLOfflineTaskStateComplete:
|
||||
statusString = [NSString stringWithFormat:@"%@ resources (%@)",
|
||||
completedString, byteCountString];
|
||||
break;
|
||||
|
||||
case MGLOfflineTaskStateActive:
|
||||
if (progress.countOfResourcesExpected) {
|
||||
completedString = [NSNumberFormatter localizedStringFromNumber:@(progress.countOfResourcesCompleted + 1)
|
||||
@@ -152,6 +165,32 @@ static NSString * const MBXDownloadsTableViewActiveCellReuseIdentifier = @"Activ
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Table view delegate
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
|
||||
MGLOfflineTask *task = self.offlineTasks[indexPath.row];
|
||||
switch (task.state) {
|
||||
case MGLOfflineTaskStateComplete:
|
||||
if ([task.region respondsToSelector:@selector(applyToMapView:)]) {
|
||||
[task.region performSelector:@selector(applyToMapView:) withObject:self.mapView];
|
||||
}
|
||||
[self performSegueWithIdentifier:@"ReturnToMap" sender:self];
|
||||
break;
|
||||
|
||||
case MGLOfflineTaskStateInactive:
|
||||
[task resume];
|
||||
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
|
||||
break;
|
||||
|
||||
case MGLOfflineTaskStateActive:
|
||||
[task suspend];
|
||||
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Offline task delegate
|
||||
|
||||
- (void)offlineTask:(MGLOfflineTask *)task progressDidChange:(MGLOfflineTaskProgress)progress {
|
||||
|
||||
@@ -505,6 +505,9 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
- (IBAction)unwindToMapViewController:(__unused UIStoryboardSegue *)sender {
|
||||
}
|
||||
|
||||
#pragma mark - Destruction
|
||||
|
||||
- (void)dealloc
|
||||
|
||||
@@ -148,8 +148,12 @@
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
</navigationItem>
|
||||
<connections>
|
||||
<segue destination="x2D-ga-sM5" kind="unwind" identifier="ReturnToMap" unwindAction="unwindToMapViewController:" id="6MZ-Ed-tu2"/>
|
||||
</connections>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="Dga-Vh-IxZ" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
<exit id="x2D-ga-sM5" userLabel="Exit" sceneMemberID="exit"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="2075" y="350"/>
|
||||
</scene>
|
||||
|
||||
Reference in New Issue
Block a user