From 3ecd415b84ce597a5eebd015f2ce2ec61883ad92 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 16 Aug 2017 11:06:22 -0400 Subject: [PATCH] Show activity indicator during profile update; trim whitespace from profile names. // FREEBIE --- .../ViewControllers/ProfileViewController.m | 42 +++++++++++++------ .../translations/en.lproj/Localizable.strings | 3 ++ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 671b3f48b..2ea3cee13 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -223,22 +223,40 @@ NS_ASSUME_NONNULL_BEGIN - (void)updateProfile { __weak ProfileViewController *weakSelf = self; - [OWSProfileManager.sharedManager updateLocalProfileName:self.nameTextField.text - avatarImage:self.avatar - success:^{ - [weakSelf.navigationController popViewControllerAnimated:YES]; - } - failure:^{ - [OWSAlerts showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"") - message:NSLocalizedString(@"PROFILE_VIEW_ERROR_UPDATE_FAILED", - @"Error message shown when a profile update fails.")]; - }]; + + // Show an activity indicator to block the UI during the profile upload. + UIAlertController *alertController = + [UIAlertController alertControllerWithTitle:NSLocalizedString(@"PROFILE_VIEW_SAVING", + @"Indicates that the user's profile view is being saved.") + message:nil + preferredStyle:UIAlertControllerStyleAlert]; + + [self presentViewController:alertController + animated:YES + completion:^{ + [alertController dismissViewControllerAnimated:NO completion:nil]; + + [OWSProfileManager.sharedManager updateLocalProfileName:[self normalizedProfileName] + avatarImage:self.avatar + success:^{ + [weakSelf.navigationController popViewControllerAnimated:YES]; + } + failure:^{ + [OWSAlerts + showAlertWithTitle:NSLocalizedString(@"ALERT_ERROR_TITLE", @"") + message:NSLocalizedString(@"PROFILE_VIEW_ERROR_UPDATE_FAILED", + @"Error message shown when a profile update fails.")]; + }]; + }]; +} + +- (NSString *)normalizedProfileName +{ + return [self.nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; } #pragma mark - UITextFieldDelegate -// TODO: This logic resides in both RegistrationViewController and here. -// We should refactor it out into a utility function. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)insertionText diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 2789571a4..94db53ef8 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1081,6 +1081,9 @@ /* Label for the profile name field of the profile view. */ "PROFILE_VIEW_NAME_SECTION_HEADER" = "Profile Name"; +/* Indicates that the user's profile view is being saved. */ +"PROFILE_VIEW_SAVING" = "Saving..."; + /* Title for the profile view. */ "PROFILE_VIEW_TITLE" = "Profile";