From b47337c0bad49f60778766b64a0690420f515cad Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 8 May 2017 13:29:10 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- Signal/src/AppDelegate.m | 63 +++++++++---------- .../ViewControllers/MessagesViewController.m | 31 +++++---- .../SelectRecipientViewController.m | 2 +- .../UpdateGroupViewController.m | 3 +- .../src/ViewControllers/ViewControllerUtils.h | 8 --- .../src/ViewControllers/ViewControllerUtils.m | 24 ------- Signal/src/views/OWSAlerts.swift | 12 ++++ .../translations/en.lproj/Localizable.strings | 16 ++--- 8 files changed, 72 insertions(+), 87 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 3d1616423..0a991e47c 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -270,25 +270,23 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; NSString *filename = url.lastPathComponent; if ([filename stringByDeletingPathExtension].length < 1) { DDLogError(@"Application opened with URL invalid filename: %@", url); - [ViewControllerUtils - showAlertWithTitle: - NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", - @"Title for the alert indicating the 'export with signal' attachment had an error.") - message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_INVALID_FILENAME", - @"Message for the alert indicating the 'export with signal' file had an " - @"invalid filename.")]; + [OWSAlerts showAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_INVALID_FILENAME", + @"Message for the alert indicating the 'export with signal' file had an " + @"invalid filename.")]; return NO; } NSString *fileExtension = [filename pathExtension]; if (fileExtension.length < 1) { DDLogError(@"Application opened with URL missing file extension: %@", url); - [ViewControllerUtils - showAlertWithTitle: - NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", - @"Title for the alert indicating the 'export with signal' attachment had an error.") - message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE", - @"Message for the alert indicating the 'export with signal' file had " - @"unknown type.")]; + [OWSAlerts showAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_UNKNOWN_TYPE", + @"Message for the alert indicating the 'export with signal' file had " + @"unknown type.")]; return NO; } @@ -320,7 +318,7 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; } else if ([isDirectory boolValue]) { DDLogInfo(@"%@ User picked directory at url: %@", self.tag, url); DDLogError(@"Application opened with URL of unknown UTI type: %@", url); - [ViewControllerUtils + [OWSAlerts showAlertWithTitle: NSLocalizedString(@"ATTACHMENT_PICKER_DOCUMENTS_PICKED_DIRECTORY_FAILED_ALERT_TITLE", @"Alert title when picking a document fails because user picked a directory/bundle") @@ -333,34 +331,31 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; NSData *data = [NSData dataWithContentsOfURL:url]; if (!data) { DDLogError(@"Application opened with URL with unloadable content: %@", url); - [ViewControllerUtils - showAlertWithTitle: - NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", - @"Title for the alert indicating the 'export with signal' attachment had an error.") - message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA", - @"Message for the alert indicating the 'export with signal' data " - @"couldn't be loaded.")]; + [OWSAlerts showAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_DATA", + @"Message for the alert indicating the 'export with signal' data " + @"couldn't be loaded.")]; return NO; } SignalAttachment *attachment = [SignalAttachment attachmentWithData:data dataUTI:utiType filename:filename]; if (!attachment) { DDLogError(@"Application opened with URL with invalid content: %@", url); - [ViewControllerUtils - showAlertWithTitle: - NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", - @"Title for the alert indicating the 'export with signal' attachment had an error.") - message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_ATTACHMENT", - @"Message for the alert indicating the 'export with signal' attachment " - @"couldn't be loaded.")]; + [OWSAlerts showAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_MESSAGE_MISSING_ATTACHMENT", + @"Message for the alert indicating the 'export with signal' attachment " + @"couldn't be loaded.")]; return NO; } if ([attachment hasError]) { DDLogError(@"Application opened with URL with content error: %@ %@", url, [attachment errorName]); - [ViewControllerUtils - showAlertWithTitle: - NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", - @"Title for the alert indicating the 'export with signal' attachment had an error.") - message:[attachment errorName]]; + [OWSAlerts showAlertWithTitle: + NSLocalizedString(@"EXPORT_WITH_SIGNAL_ERROR_TITLE", + @"Title for the alert indicating the 'export with signal' attachment had an error.") + message:[attachment errorName]]; return NO; } DDLogInfo(@"Application opened with URL: %@", url); diff --git a/Signal/src/ViewControllers/MessagesViewController.m b/Signal/src/ViewControllers/MessagesViewController.m index c698c8df8..5d48fce60 100644 --- a/Signal/src/ViewControllers/MessagesViewController.m +++ b/Signal/src/ViewControllers/MessagesViewController.m @@ -207,7 +207,7 @@ typedef enum : NSUInteger { forState:UIControlStateNormal]; button.imageView.tintColor = [UIColor ows_materialBlueColor]; - // We want to be permissive about the voice memo gesture, so we: + // We want to be permissive about the voice message gesture, so we: // // * Add the gesture recognizer to the button's superview instead of the button. // * Filter the touches that the gesture recognizer receives by serving as its @@ -269,18 +269,18 @@ typedef enum : NSUInteger { case UIGestureRecognizerStateCancelled: case UIGestureRecognizerStateFailed: if (self.isRecordingVoiceMemo) { - // Cancel voice memo if necessary. + // Cancel voice message if necessary. self.isRecordingVoiceMemo = NO; [self.delegate voiceMemoGestureDidCancel]; } break; case UIGestureRecognizerStateBegan: if (self.isRecordingVoiceMemo) { - // Cancel voice memo if necessary. + // Cancel voice message if necessary. self.isRecordingVoiceMemo = NO; [self.delegate voiceMemoGestureDidCancel]; } - // Start voice memo. + // Start voice message. [self.textView resignFirstResponder]; self.isRecordingVoiceMemo = YES; self.voiceMemoGestureStartLocation = [sender locationInView:self]; @@ -306,7 +306,7 @@ typedef enum : NSUInteger { break; case UIGestureRecognizerStateEnded: if (self.isRecordingVoiceMemo) { - // End voice memo. + // End voice message. self.isRecordingVoiceMemo = NO; [self.delegate voiceMemoGestureDidEnd]; } @@ -325,7 +325,7 @@ typedef enum : NSUInteger { - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { - // We want to be permissive about the voice memo gesture, so we accept + // We want to be permissive about the voice message gesture, so we accept // gesture that begin within N points of the CGFloat kVoiceMemoGestureTolerancePoints = 10; CGPoint location = [touch locationInView:self.voiceMemoButton]; @@ -399,7 +399,8 @@ typedef enum : NSUInteger { UILabel *cancelLabel = [UILabel new]; cancelLabel.textColor = [UIColor ows_destructiveRedColor]; cancelLabel.font = [UIFont ows_mediumFontWithSize:14.f]; - cancelLabel.text = NSLocalizedString(@"VOICE_MEMO_CANCEL_INSTRUCTIONS", @"Indicates how to cancel a voice memo."); + cancelLabel.text + = NSLocalizedString(@"VOICE_MESSAGE_CANCEL_INSTRUCTIONS", @"Indicates how to cancel a voice message."); [self.voiceMemoUI addSubview:cancelLabel]; [imageView autoVCenterInSuperview]; @@ -484,7 +485,7 @@ typedef enum : NSUInteger { { OWSAssert([NSThread isMainThread]); - // Fade out the voice memo views as the cancel gesture + // Fade out the voice message views as the cancel gesture // proceeds as feedback. for (UIView *subview in self.voiceMemoUI.subviews) { subview.layer.opacity = MAX(0.f, MIN(1.f, 1.f - (float)cancelAlpha)); @@ -3132,8 +3133,16 @@ typedef enum : NSUInteger { const NSTimeInterval kMinimumRecordingTimeSeconds = 1.f; if (currentTime < kMinimumRecordingTimeSeconds) { - DDLogInfo(@"Discarding voice memo; too short."); + DDLogInfo(@"Discarding voice message; too short."); self.audioRecorder = nil; + + [OWSAlerts + showAlertWithTitle: + NSLocalizedString(@"VOICE_MESSAGE_TOO_SHORT_ALERT_TITLE", + @"Title for the alert indicating the 'voice message' needs to be held to be held down to record.") + message:NSLocalizedString(@"VOICE_MESSAGE_TOO_SHORT_ALERT_MESSAGE", + @"Message for the alert indicating the 'voice message' needs to be held to be held " + @"down to record.")]; return; } @@ -3148,7 +3157,7 @@ typedef enum : NSUInteger { self.audioRecorder = nil; - NSString *filename = [NSLocalizedString(@"VOICE_MEMO_FILE_NAME", @"Filename for voice memos.") + NSString *filename = [NSLocalizedString(@"VOICE_MESSAGE_FILE_NAME", @"Filename for voice messages.") stringByAppendingPathExtension:[MIMETypeUtil fileExtensionForUTIType:(NSString *)kUTTypeMPEG4Audio]]; SignalAttachment *attachment = @@ -3524,7 +3533,7 @@ typedef enum : NSUInteger { { // Override. // - // We want to show the "voice memo" button if the text input is empty + // We want to show the "voice message" button if the text input is empty // and the "send" button if it isn't. [((OWSMessagesToolbarContentView *)self.inputToolbar.contentView)ensureEnabling]; } diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index e530ff5a4..62a104da9 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -310,7 +310,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien } [activityAlert dismissViewControllerAnimated:NO completion:^{ - [ViewControllerUtils + [OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"Title for a generic error alert.") message:error.localizedDescription]; diff --git a/Signal/src/ViewControllers/UpdateGroupViewController.m b/Signal/src/ViewControllers/UpdateGroupViewController.m index 679c3d1e2..7bbf619b9 100644 --- a/Signal/src/ViewControllers/UpdateGroupViewController.m +++ b/Signal/src/ViewControllers/UpdateGroupViewController.m @@ -12,6 +12,7 @@ #import "OWSContactsManager.h" #import "OWSTableViewController.h" #import "SecurityUtils.h" +#import "Signal-Swift.h" #import "SignalKeyingStorage.h" #import "TSOutgoingMessage.h" #import "UIUtil.h" @@ -307,7 +308,7 @@ NS_ASSUME_NONNULL_BEGIN [weakSelf showUnblockAlertForRecipientId:recipientId]; } } else { - [ViewControllerUtils + [OWSAlerts showAlertWithTitle: NSLocalizedString(@"UPDATE_GROUP_CANT_REMOVE_MEMBERS_ALERT_TITLE", @"Title for alert indicating that group members can't be removed.") diff --git a/Signal/src/ViewControllers/ViewControllerUtils.h b/Signal/src/ViewControllers/ViewControllerUtils.h index 64ac8e175..436bd13b7 100644 --- a/Signal/src/ViewControllers/ViewControllerUtils.h +++ b/Signal/src/ViewControllers/ViewControllerUtils.h @@ -22,12 +22,4 @@ + (NSString *)formatDurationSeconds:(long)timeSeconds; -#pragma mark - Alerts - -+ (UIAlertController *)showAlertWithTitle:(NSString *)title message:(NSString *)message; - -+ (UIAlertController *)showAlertWithTitle:(NSString *)title - message:(NSString *)message - buttonLabel:(NSString *)buttonLabel; - @end diff --git a/Signal/src/ViewControllers/ViewControllerUtils.m b/Signal/src/ViewControllers/ViewControllerUtils.m index d082d9b29..ef41ef1fb 100644 --- a/Signal/src/ViewControllers/ViewControllerUtils.m +++ b/Signal/src/ViewControllers/ViewControllerUtils.m @@ -115,30 +115,6 @@ NS_ASSUME_NONNULL_BEGIN } } -#pragma mark - Alerts - -+ (UIAlertController *)showAlertWithTitle:(NSString *)title message:(NSString *)message -{ - return [self showAlertWithTitle:title message:message buttonLabel:NSLocalizedString(@"OK", nil)]; -} - -+ (UIAlertController *)showAlertWithTitle:(NSString *)title - message:(NSString *)message - buttonLabel:(NSString *)buttonLabel -{ - OWSAssert(title.length > 0); - OWSAssert(message.length > 0); - - UIAlertController *alert = - [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; - - [alert addAction:[UIAlertAction actionWithTitle:buttonLabel style:UIAlertActionStyleDefault handler:nil]]; - - [[UIApplication sharedApplication].frontmostViewController presentViewController:alert animated:YES completion:nil]; - - return alert; -} - #pragma mark - Logging + (NSString *)tag diff --git a/Signal/src/views/OWSAlerts.swift b/Signal/src/views/OWSAlerts.swift index 815184a9c..24ebf0141 100644 --- a/Signal/src/views/OWSAlerts.swift +++ b/Signal/src/views/OWSAlerts.swift @@ -22,4 +22,16 @@ import Foundation alertController.addAction(settingsAction) UIApplication.shared.frontmostViewController?.present(alertController, animated: true, completion: nil) } + + public class func showAlert(withTitle title: String, message: String) { + self.showAlert(withTitle: title, message: message, buttonLabel: NSLocalizedString("OK", comment: "")) + } + + public class func showAlert(withTitle title: String, message: String, buttonLabel: String) { + assert(title.characters.count > 0) + assert(message.characters.count > 0) + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: buttonLabel, style: .default, handler: nil)) + UIApplication.shared.frontmostViewController?.present(alert, animated: true, completion: nil) + } } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 5e00ae9cc..6d2f1589b 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1277,17 +1277,17 @@ /* table cell label in conversation settings */ "VERIFY_PRIVACY" = "Verify Safety Number"; -/* Indicates how to cancel a voice memo. */ -"VOICE_MEMO_CANCEL_INSTRUCTIONS" = "Slide to Cancel"; +/* Indicates how to cancel a voice message. */ +"VOICE_MESSAGE_CANCEL_INSTRUCTIONS" = "Slide to Cancel"; -/* Filename for voice memos. */ -"VOICE_MEMO_FILE_NAME" = "Voice Memo"; +/* Filename for voice messages. */ +"VOICE_MESSAGE_FILE_NAME" = "Voice Message"; -/* Message of the 'voice memo needs recording permission' alert. */ -"VOICE_MEMO_NEEDS_RECORDING_PERMISSION_ALERT_MESSAGE" = "You can grant Signal access to your microphone in the Settings App >> Privacy >> Microphone >> Signal."; +/* Message for the alert indicating the 'voice message' needs to be held to be held down to record. */ +"VOICE_MESSAGE_TOO_SHORT_ALERT_MESSAGE" = "Tap and hold to record a voice message."; -/* Title of the 'voice memo needs recording permission' alert. */ -"VOICE_MEMO_NEEDS_RECORDING_PERMISSION_ALERT_TITLE" = "Can't Record"; +/* Title for the alert indicating the 'voice message' needs to be held to be held down to record. */ +"VOICE_MESSAGE_TOO_SHORT_ALERT_TITLE" = "Voice Message"; /* Activity indicator title, shown upon returning to the device manager, until you complete the provisioning process on desktop */ "WAITING_TO_COMPLETE_DEVICE_LINK_TEXT" = "Complete setup on Signal Desktop.";