From ffb4b3f9d2964838c227617a56d0374d1ef2dadd Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Tue, 15 Aug 2017 17:55:07 -0400 Subject: [PATCH] Add profile view to registration workflow. // FREEBIE --- .../AppSettingsViewController.m | 1 + .../CodeVerificationViewController.m | 19 ++-- .../ViewControllers/ProfileViewController.h | 8 ++ .../ViewControllers/ProfileViewController.m | 104 +++++++++++++++--- .../translations/en.lproj/Localizable.strings | 3 + 5 files changed, 110 insertions(+), 25 deletions(-) diff --git a/Signal/src/ViewControllers/AppSettingsViewController.m b/Signal/src/ViewControllers/AppSettingsViewController.m index fd1b6366c..44f107faf 100644 --- a/Signal/src/ViewControllers/AppSettingsViewController.m +++ b/Signal/src/ViewControllers/AppSettingsViewController.m @@ -317,6 +317,7 @@ - (void)showProfile { ProfileViewController *vc = [[ProfileViewController alloc] init]; + vc.profileViewMode = ProfileViewMode_AppSettings; [self.navigationController pushViewController:vc animated:YES]; } diff --git a/Signal/src/ViewControllers/CodeVerificationViewController.m b/Signal/src/ViewControllers/CodeVerificationViewController.m index 505fbd4d8..837a4b3ae 100644 --- a/Signal/src/ViewControllers/CodeVerificationViewController.m +++ b/Signal/src/ViewControllers/CodeVerificationViewController.m @@ -3,10 +3,8 @@ // #import "CodeVerificationViewController.h" -#import "AppDelegate.h" +#import "ProfileViewController.h" #import "Signal-Swift.h" -#import "SignalsNavigationController.h" -#import "SignalsViewController.h" #import "StringUtil.h" #import "UIViewController+OWS.h" #import @@ -269,14 +267,7 @@ NS_ASSUME_NONNULL_BEGIN DDLogInfo(@"%@ Successfully registered Signal account.", weakSelf.tag); dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf stopActivityIndicator]; - - SignalsViewController *homeView = [SignalsViewController new]; - homeView.newlyRegisteredUser = YES; - SignalsNavigationController *navigationController = - [[SignalsNavigationController alloc] initWithRootViewController:homeView]; - AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; - appDelegate.window.rootViewController = navigationController; - OWSAssert([navigationController.topViewController isKindOfClass:[SignalsViewController class]]); + [weakSelf vericationWasCompleted]; }); }) .catch(^(NSError *_Nonnull error) { @@ -290,6 +281,12 @@ NS_ASSUME_NONNULL_BEGIN }); } +- (void)vericationWasCompleted +{ + ProfileViewController *vc = [[ProfileViewController alloc] init]; + vc.profileViewMode = ProfileViewMode_Registration; + [self.navigationController pushViewController:vc animated:YES]; +} - (void)presentAlertWithVerificationError:(NSError *)error { diff --git a/Signal/src/ViewControllers/ProfileViewController.h b/Signal/src/ViewControllers/ProfileViewController.h index 16471c80f..d366ac026 100644 --- a/Signal/src/ViewControllers/ProfileViewController.h +++ b/Signal/src/ViewControllers/ProfileViewController.h @@ -6,8 +6,16 @@ NS_ASSUME_NONNULL_BEGIN +typedef NS_ENUM(NSInteger, ProfileViewMode) { + ProfileViewMode_AppSettings = 0, + ProfileViewMode_Registration, + ProfileViewMode_UpgradeOrNag, +}; + @interface ProfileViewController : OWSTableViewController +@property (nonatomic) ProfileViewMode profileViewMode; + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index 350bbfd04..a122a3fe9 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -3,9 +3,12 @@ // #import "ProfileViewController.h" +#import "AppDelegate.h" #import "AvatarViewHelper.h" #import "OWSProfileManager.h" #import "Signal-Swift.h" +#import "SignalsNavigationController.h" +#import "SignalsViewController.h" #import "UIColor+OWS.h" #import "UIFont+OWS.h" #import "UIView+OWS.h" @@ -42,8 +45,6 @@ NS_ASSUME_NONNULL_BEGIN self.view.backgroundColor = [UIColor whiteColor]; [self.navigationController.navigationBar setTranslucent:NO]; self.title = NSLocalizedString(@"PROFILE_VIEW_TITLE", @"Title for the profile view."); - self.navigationItem.leftBarButtonItem = - [self createOWSBackButtonWithTarget:self selector:@selector(backButtonPressed:)]; _avatarViewHelper = [AvatarViewHelper new]; _avatarViewHelper.delegate = self; @@ -51,6 +52,7 @@ NS_ASSUME_NONNULL_BEGIN _avatar = [OWSProfileManager.sharedManager localProfileAvatarImage]; [self createViews]; + [self updateNavigationItem]; } - (void)createViews @@ -164,11 +166,20 @@ NS_ASSUME_NONNULL_BEGIN - (void)backButtonPressed:(id)sender { + [self leaveViewCheckingForUnsavedChanges:^{ + [self.navigationController popViewControllerAnimated:YES]; + }]; +} + +- (void)leaveViewCheckingForUnsavedChanges:(void (^_Nonnull)())leaveViewBlock +{ + OWSAssert(leaveViewBlock); + [self.nameTextField resignFirstResponder]; if (!self.hasUnsavedChanges) { // If user made no changes, return to conversation settings view. - [self.navigationController popViewControllerAnimated:YES]; + leaveViewBlock(); return; } @@ -185,7 +196,7 @@ NS_ASSUME_NONNULL_BEGIN @"The label for the 'discard' button in alerts and action sheets.") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) { - [self.navigationController popViewControllerAnimated:YES]; + leaveViewBlock(); }]]; [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil) style:UIAlertActionStyleCancel @@ -204,15 +215,43 @@ NS_ASSUME_NONNULL_BEGIN { _hasUnsavedChanges = hasUnsavedChanges; - if (hasUnsavedChanges) { - self.navigationItem.rightBarButtonItem = (self.hasUnsavedChanges - ? [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_GROUP_UPDATE_BUTTON", - @"The title for the 'update group' button.") - style:UIBarButtonItemStylePlain - target:self - action:@selector(updatePressed)] - : nil); + [self updateNavigationItem]; +} + +- (void)updateNavigationItem +{ + // The navigation bar is hidden in the registration workflow. + [self.navigationController setNavigationBarHidden:NO animated:YES]; + + UIBarButtonItem *rightItem = nil; + switch (self.profileViewMode) { + case ProfileViewMode_AppSettings: + self.navigationItem.leftBarButtonItem = + [self createOWSBackButtonWithTarget:self selector:@selector(backButtonPressed:)]; + break; + case ProfileViewMode_Registration: + case ProfileViewMode_UpgradeOrNag: + // Registration and "upgrade or nag" mode don't need a back button. + self.navigationItem.hidesBackButton = YES; + + // Registration and "upgrade or nag" mode have "skip" or "update". + // + // TODO: Should this be some other verb instead of "update"? + rightItem = [[UIBarButtonItem alloc] + initWithTitle:NSLocalizedString(@"NAVIGATION_ITEM_SKIP_BUTTON", @"A button to skip a view.") + style:UIBarButtonItemStylePlain + target:self + action:@selector(skipPressed)]; + break; } + if (self.hasUnsavedChanges) { + rightItem = [[UIBarButtonItem alloc] + initWithTitle:NSLocalizedString(@"EDIT_GROUP_UPDATE_BUTTON", @"The title for the 'update group' button.") + style:UIBarButtonItemStylePlain + target:self + action:@selector(updatePressed)]; + } + self.navigationItem.rightBarButtonItem = rightItem; } - (void)updatePressed @@ -239,8 +278,7 @@ NS_ASSUME_NONNULL_BEGIN success:^{ [alertController dismissViewControllerAnimated:NO completion:^{ - [weakSelf.navigationController - popViewControllerAnimated:YES]; + [weakSelf updateProfileCompleted]; }]; } failure:^{ @@ -265,6 +303,44 @@ NS_ASSUME_NONNULL_BEGIN return [self.nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; } +- (void)updateProfileCompleted +{ + [self profileCompletedOrSkipped]; +} + +- (void)skipPressed +{ + [self leaveViewCheckingForUnsavedChanges:^{ + [self profileCompletedOrSkipped]; + }]; +} + +- (void)profileCompletedOrSkipped +{ + switch (self.profileViewMode) { + case ProfileViewMode_AppSettings: + [self.navigationController popViewControllerAnimated:YES]; + break; + case ProfileViewMode_Registration: + [self showHomeView]; + break; + case ProfileViewMode_UpgradeOrNag: + [self dismissViewControllerAnimated:YES completion:nil]; + break; + } +} + +- (void)showHomeView +{ + SignalsViewController *homeView = [SignalsViewController new]; + homeView.newlyRegisteredUser = YES; + SignalsNavigationController *navigationController = + [[SignalsNavigationController alloc] initWithRootViewController:homeView]; + AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; + appDelegate.window.rootViewController = navigationController; + OWSAssert([navigationController.topViewController isKindOfClass:[SignalsViewController class]]); +} + #pragma mark - UITextFieldDelegate - (BOOL)textField:(UITextField *)textField diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 4b924e6ea..4da0fd5b3 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -861,6 +861,9 @@ /* An explanation of the consequences of muting a thread. */ "MUTE_BEHAVIOR_EXPLANATION" = "You will not receive notifications for muted conversations."; +/* A button to skip a view. */ +"NAVIGATION_ITEM_SKIP_BUTTON" = "Skip"; + /* No comment provided by engineer. */ "NETWORK_ERROR_RECOVERY" = "Please check you're online and try again.";