From b8fc4001ec6faca916f5cdc3b33e2e85c9f8399e Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 8 Nov 2016 16:28:00 -0500 Subject: [PATCH] Camera permission fixup - remove unknown segue, otherwise couldn't compile project - translated english strings - added translation comments - reused existing "dismiss" string - deselected row after dismissing permissions alert in linked devices screen // FREEBIE --- Signal/src/Storyboard/Main.storyboard | 1 - .../util/UIViewController+CameraPermissions.h | 3 +- .../util/UIViewController+CameraPermissions.m | 27 +++++++++++++----- .../FingerprintViewController.m | 3 +- .../view controllers/MessagesViewController.m | 4 +-- .../OWSLinkedDevicesTableViewController.m | 8 +++++- .../translations/en.lproj/Localizable.strings | Bin 61822 -> 62166 bytes 7 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Signal/src/Storyboard/Main.storyboard b/Signal/src/Storyboard/Main.storyboard index 0900049f3..aaa675771 100644 --- a/Signal/src/Storyboard/Main.storyboard +++ b/Signal/src/Storyboard/Main.storyboard @@ -1519,7 +1519,6 @@ - diff --git a/Signal/src/util/UIViewController+CameraPermissions.h b/Signal/src/util/UIViewController+CameraPermissions.h index bd1b6d121..12f8821c2 100644 --- a/Signal/src/util/UIViewController+CameraPermissions.h +++ b/Signal/src/util/UIViewController+CameraPermissions.h @@ -10,7 +10,8 @@ NS_ASSUME_NONNULL_BEGIN @interface UIViewController (CameraPermissions) --(void)ows_askForCameraPermissions:(void(^)())permissionsGrantedCallback; +- (void)ows_askForCameraPermissions:(void (^)())permissionsGrantedCallback + alertActionHandler:(nullable void (^)())alertActionHandler; @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/util/UIViewController+CameraPermissions.m b/Signal/src/util/UIViewController+CameraPermissions.m index 575613e9c..0ee816b55 100644 --- a/Signal/src/util/UIViewController+CameraPermissions.m +++ b/Signal/src/util/UIViewController+CameraPermissions.m @@ -13,7 +13,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation UIViewController (CameraPermissions) --(void)ows_askForCameraPermissions:(void(^)())permissionsGrantedCallback +- (void)ows_askForCameraPermissions:(void (^)())permissionsGrantedCallback + alertActionHandler:(nullable void (^)())alertActionHandler { if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { DDLogError(@"Camera ImagePicker source not available"); @@ -21,13 +22,25 @@ NS_ASSUME_NONNULL_BEGIN } AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (status == AVAuthorizationStatusDenied) { - UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"CAMERA_PERMISSION_TITLE",nil) message:NSLocalizedString(@"CAMERA_PERMISSION_MESSAGE",nil) preferredStyle:UIAlertControllerStyleAlert]; - - [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CAMERA_PERMISSION_PROCEED",nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + UIAlertController* alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"MISSING_CAMERA_PERMISSION_TITLE", @"Alert title") + message:NSLocalizedString(@"MISSING_CAMERA_PERMISSION_MESSAGE", @"Alert body") + preferredStyle:UIAlertControllerStyleAlert]; + + NSString *settingsTitle = NSLocalizedString(@"OPEN_SETTINGS_BUTTON", @"Button text which opens the settings app"); + UIAlertAction *openSettingsAction = [UIAlertAction actionWithTitle:settingsTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; - }]]; - [alert addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"CAMERA_PERMISSION_CANCEL",nil) style:UIAlertActionStyleCancel handler:nil]]; - [self presentViewController:alert animated:YES completion:[UIUtil modalCompletionBlock]]; + if (alertActionHandler) { + alertActionHandler(); + } + }]; + [alert addAction:openSettingsAction]; + + UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"DISMISS_BUTTON_TEXT", nil) + style:UIAlertActionStyleCancel + handler:alertActionHandler]; + [alert addAction:dismissAction]; + + [self presentViewController:alert animated:YES completion:nil]; } else if (status == AVAuthorizationStatusAuthorized) { permissionsGrantedCallback(); } else if (status == AVAuthorizationStatusNotDetermined) { diff --git a/Signal/src/view controllers/FingerprintViewController.m b/Signal/src/view controllers/FingerprintViewController.m index 257465a43..fca41dc7c 100644 --- a/Signal/src/view controllers/FingerprintViewController.m +++ b/Signal/src/view controllers/FingerprintViewController.m @@ -153,7 +153,8 @@ NS_ASSUME_NONNULL_BEGIN completion:nil]; [self.qrScanningController startCapture]; - }]; + } + alertActionHandler:nil]; } // pragma mark - OWSQRScannerDelegate diff --git a/Signal/src/view controllers/MessagesViewController.m b/Signal/src/view controllers/MessagesViewController.m index 9cdd1c794..8d955402b 100644 --- a/Signal/src/view controllers/MessagesViewController.m +++ b/Signal/src/view controllers/MessagesViewController.m @@ -1569,8 +1569,8 @@ typedef enum : NSUInteger { picker.allowsEditing = NO; picker.delegate = self; [self presentViewController:picker animated:YES completion:[UIUtil modalCompletionBlock]]; - - }]; + } + alertActionHandler:nil]; } - (void)chooseFromLibrary { if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { diff --git a/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m b/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m index 129317589..8ec8e9986 100644 --- a/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m +++ b/Signal/src/view controllers/OWSLinkedDevicesTableViewController.m @@ -255,9 +255,15 @@ int const OWSLinkedDevicesTableViewControllerSectionAddDevice = 1; { [self ows_askForCameraPermissions:^{ [self performSegueWithIdentifier:@"LinkDeviceSegue" sender:self]; - }]; + } + alertActionHandler:^{ + // HACK to unselect rows when swiping back + // http://stackoverflow.com/questions/19379510/uitableviewcell-doesnt-get-deselected-when-swiping-back-quickly + [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES]; + }]; } } + - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == OWSLinkedDevicesTableViewControllerSectionAddDevice) { diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 803eea0f7d218d50ea28b78fa54d4252b60d7fa8..0c2941be51640084415f11cf30ad7e21aa624f18 100644 GIT binary patch delta 386 zcmezOi22%6<_+Z@oA-P2DNf#hQEakoH;1$@gC|2U5PCBBF}O3tGdMFiGWasMG6XR= zPQDi_IaydhLN}5jpP`gNfuVq*h#{4sj3E=uFJ{PLs050p0L7Al>`aC{AS-3^ELKay zM21`-yNDr?K@X@R6sR)=$SwhjDFF3=Oe+Giih=B6uxRdNfmBh^5}*vkmVBUzsUXuB z^d@h(C_Q<;JkMm`e!{M8-y$|ySAb{o<0c{HM4%ZUQ;LBQ+16yBOQ5csY><<^Sv@;R zc(VU`zR9xBxMa&2GJqaQ29gRu#}ojy=Yh4C07X(kj-1TT#-XUipwGa?pv2(M5C9A+ nKVYy01L+VTgal*o
lf93~P3Hf=HTm^Bsm*KaE*1d*qN87&

delta 86
zcmccil=Lm3bk0Yx$y
ok{EI(8$61gyf%PmbF&AN;^g-^QJb%3CkapXZ*