summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-03-07 01:14:36 -0800
committerMinh Nguyễn <mxn@1ec5.org>2016-03-10 17:08:58 -0800
commit0348c1ee967cf3e19d9dc91918d28e42b40b5b19 (patch)
treecb9cfbdb805599153a569ee912e0f58365c3b597
parentf5ac63dfeccc185bc198b21f3ff6f87a9017848d (diff)
downloadqtlocation-mapboxgl-0348c1ee967cf3e19d9dc91918d28e42b40b5b19.tar.gz
[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.
-rw-r--r--platform/ios/app/MBXDownloadsTableViewController.m41
-rw-r--r--platform/ios/app/MBXViewController.mm3
-rw-r--r--platform/ios/app/Storyboard.storyboard4
3 files changed, 47 insertions, 1 deletions
diff --git a/platform/ios/app/MBXDownloadsTableViewController.m b/platform/ios/app/MBXDownloadsTableViewController.m
index db79d77d3e..1748310be6 100644
--- a/platform/ios/app/MBXDownloadsTableViewController.m
+++ b/platform/ios/app/MBXDownloadsTableViewController.m
@@ -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 {
diff --git a/platform/ios/app/MBXViewController.mm b/platform/ios/app/MBXViewController.mm
index ba35feed62..e1155f1e17 100644
--- a/platform/ios/app/MBXViewController.mm
+++ b/platform/ios/app/MBXViewController.mm
@@ -505,6 +505,9 @@ static const CLLocationCoordinate2D WorldTourDestinations[] = {
return filePath;
}
+- (IBAction)unwindToMapViewController:(__unused UIStoryboardSegue *)sender {
+}
+
#pragma mark - Destruction
- (void)dealloc
diff --git a/platform/ios/app/Storyboard.storyboard b/platform/ios/app/Storyboard.storyboard
index 7e1eded47e..01dface475 100644
--- a/platform/ios/app/Storyboard.storyboard
+++ b/platform/ios/app/Storyboard.storyboard
@@ -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>