Add profile view to registration workflow.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 26f9c7ad00
commit ffb4b3f9d2

@ -317,6 +317,7 @@
- (void)showProfile - (void)showProfile
{ {
ProfileViewController *vc = [[ProfileViewController alloc] init]; ProfileViewController *vc = [[ProfileViewController alloc] init];
vc.profileViewMode = ProfileViewMode_AppSettings;
[self.navigationController pushViewController:vc animated:YES]; [self.navigationController pushViewController:vc animated:YES];
} }

@ -3,10 +3,8 @@
// //
#import "CodeVerificationViewController.h" #import "CodeVerificationViewController.h"
#import "AppDelegate.h" #import "ProfileViewController.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "SignalsNavigationController.h"
#import "SignalsViewController.h"
#import "StringUtil.h" #import "StringUtil.h"
#import "UIViewController+OWS.h" #import "UIViewController+OWS.h"
#import <PromiseKit/AnyPromise.h> #import <PromiseKit/AnyPromise.h>
@ -269,14 +267,7 @@ NS_ASSUME_NONNULL_BEGIN
DDLogInfo(@"%@ Successfully registered Signal account.", weakSelf.tag); DDLogInfo(@"%@ Successfully registered Signal account.", weakSelf.tag);
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf stopActivityIndicator]; [weakSelf stopActivityIndicator];
[weakSelf vericationWasCompleted];
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]]);
}); });
}) })
.catch(^(NSError *_Nonnull error) { .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 - (void)presentAlertWithVerificationError:(NSError *)error
{ {

@ -6,8 +6,16 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, ProfileViewMode) {
ProfileViewMode_AppSettings = 0,
ProfileViewMode_Registration,
ProfileViewMode_UpgradeOrNag,
};
@interface ProfileViewController : OWSTableViewController @interface ProfileViewController : OWSTableViewController
@property (nonatomic) ProfileViewMode profileViewMode;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -3,9 +3,12 @@
// //
#import "ProfileViewController.h" #import "ProfileViewController.h"
#import "AppDelegate.h"
#import "AvatarViewHelper.h" #import "AvatarViewHelper.h"
#import "OWSProfileManager.h" #import "OWSProfileManager.h"
#import "Signal-Swift.h" #import "Signal-Swift.h"
#import "SignalsNavigationController.h"
#import "SignalsViewController.h"
#import "UIColor+OWS.h" #import "UIColor+OWS.h"
#import "UIFont+OWS.h" #import "UIFont+OWS.h"
#import "UIView+OWS.h" #import "UIView+OWS.h"
@ -42,8 +45,6 @@ NS_ASSUME_NONNULL_BEGIN
self.view.backgroundColor = [UIColor whiteColor]; self.view.backgroundColor = [UIColor whiteColor];
[self.navigationController.navigationBar setTranslucent:NO]; [self.navigationController.navigationBar setTranslucent:NO];
self.title = NSLocalizedString(@"PROFILE_VIEW_TITLE", @"Title for the profile view."); self.title = NSLocalizedString(@"PROFILE_VIEW_TITLE", @"Title for the profile view.");
self.navigationItem.leftBarButtonItem =
[self createOWSBackButtonWithTarget:self selector:@selector(backButtonPressed:)];
_avatarViewHelper = [AvatarViewHelper new]; _avatarViewHelper = [AvatarViewHelper new];
_avatarViewHelper.delegate = self; _avatarViewHelper.delegate = self;
@ -51,6 +52,7 @@ NS_ASSUME_NONNULL_BEGIN
_avatar = [OWSProfileManager.sharedManager localProfileAvatarImage]; _avatar = [OWSProfileManager.sharedManager localProfileAvatarImage];
[self createViews]; [self createViews];
[self updateNavigationItem];
} }
- (void)createViews - (void)createViews
@ -164,11 +166,20 @@ NS_ASSUME_NONNULL_BEGIN
- (void)backButtonPressed:(id)sender - (void)backButtonPressed:(id)sender
{ {
[self leaveViewCheckingForUnsavedChanges:^{
[self.navigationController popViewControllerAnimated:YES];
}];
}
- (void)leaveViewCheckingForUnsavedChanges:(void (^_Nonnull)())leaveViewBlock
{
OWSAssert(leaveViewBlock);
[self.nameTextField resignFirstResponder]; [self.nameTextField resignFirstResponder];
if (!self.hasUnsavedChanges) { if (!self.hasUnsavedChanges) {
// If user made no changes, return to conversation settings view. // If user made no changes, return to conversation settings view.
[self.navigationController popViewControllerAnimated:YES]; leaveViewBlock();
return; return;
} }
@ -185,7 +196,7 @@ NS_ASSUME_NONNULL_BEGIN
@"The label for the 'discard' button in alerts and action sheets.") @"The label for the 'discard' button in alerts and action sheets.")
style:UIAlertActionStyleDestructive style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) { handler:^(UIAlertAction *action) {
[self.navigationController popViewControllerAnimated:YES]; leaveViewBlock();
}]]; }]];
[controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil) [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil)
style:UIAlertActionStyleCancel style:UIAlertActionStyleCancel
@ -204,15 +215,43 @@ NS_ASSUME_NONNULL_BEGIN
{ {
_hasUnsavedChanges = hasUnsavedChanges; _hasUnsavedChanges = hasUnsavedChanges;
if (hasUnsavedChanges) { [self updateNavigationItem];
self.navigationItem.rightBarButtonItem = (self.hasUnsavedChanges }
? [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"EDIT_GROUP_UPDATE_BUTTON",
@"The title for the 'update group' button.") - (void)updateNavigationItem
style:UIBarButtonItemStylePlain {
target:self // The navigation bar is hidden in the registration workflow.
action:@selector(updatePressed)] [self.navigationController setNavigationBarHidden:NO animated:YES];
: nil);
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 - (void)updatePressed
@ -239,8 +278,7 @@ NS_ASSUME_NONNULL_BEGIN
success:^{ success:^{
[alertController dismissViewControllerAnimated:NO [alertController dismissViewControllerAnimated:NO
completion:^{ completion:^{
[weakSelf.navigationController [weakSelf updateProfileCompleted];
popViewControllerAnimated:YES];
}]; }];
} }
failure:^{ failure:^{
@ -265,6 +303,44 @@ NS_ASSUME_NONNULL_BEGIN
return [self.nameTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 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 #pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField - (BOOL)textField:(UITextField *)textField

@ -861,6 +861,9 @@
/* An explanation of the consequences of muting a thread. */ /* An explanation of the consequences of muting a thread. */
"MUTE_BEHAVIOR_EXPLANATION" = "You will not receive notifications for muted conversations."; "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. */ /* No comment provided by engineer. */
"NETWORK_ERROR_RECOVERY" = "Please check you're online and try again."; "NETWORK_ERROR_RECOVERY" = "Please check you're online and try again.";

Loading…
Cancel
Save