From ea9dc3fe7764716790f00c0fad0b3dd619d4bb9c Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 19 May 2017 23:19:17 -0400 Subject: [PATCH] Rationalize the segues between registration view and country code view. // FREEBIE --- .../src/Storyboards/Registration.storyboard | 18 ++---- .../CountryCodeViewController.h | 11 +--- .../CountryCodeViewController.m | 36 +++++++----- .../RegistrationViewController.h | 23 ++++---- .../RegistrationViewController.m | 57 +++++++++++++------ .../SelectRecipientViewController.m | 1 - 6 files changed, 80 insertions(+), 66 deletions(-) diff --git a/Signal/src/Storyboards/Registration.storyboard b/Signal/src/Storyboards/Registration.storyboard index 6ea413e55..dada992f3 100644 --- a/Signal/src/Storyboards/Registration.storyboard +++ b/Signal/src/Storyboards/Registration.storyboard @@ -1,11 +1,11 @@ - - + + - + @@ -75,9 +75,6 @@ - - - @@ -228,6 +222,7 @@ + @@ -282,7 +277,7 @@ - + diff --git a/Signal/src/ViewControllers/CountryCodeViewController.h b/Signal/src/ViewControllers/CountryCodeViewController.h index ef13036ff..c78134404 100644 --- a/Signal/src/ViewControllers/CountryCodeViewController.h +++ b/Signal/src/ViewControllers/CountryCodeViewController.h @@ -15,15 +15,10 @@ @end -@interface CountryCodeViewController - : UIViewController +#pragma mark - + +@interface CountryCodeViewController : UIViewController -@property (nonatomic) IBOutlet UITableView *countryCodeTableView; -@property (nonatomic) IBOutlet UISearchBar *searchBar; @property (nonatomic, weak) id delegate; -@property (nonatomic) NSString *countryCodeSelected; -@property (nonatomic) NSString *callingCodeSelected; -@property (nonatomic) NSString *countryNameSelected; -@property (nonatomic) BOOL shouldDismissWithoutSegue; @end diff --git a/Signal/src/ViewControllers/CountryCodeViewController.m b/Signal/src/ViewControllers/CountryCodeViewController.m index 4fa7e2df7..d2c5f98eb 100644 --- a/Signal/src/ViewControllers/CountryCodeViewController.m +++ b/Signal/src/ViewControllers/CountryCodeViewController.m @@ -2,33 +2,45 @@ // Copyright (c) 2017 Open Whisper Systems. All rights reserved. // -#import "CountryCodeTableViewCell.h" #import "CountryCodeViewController.h" -#import "PhoneNumberUtil.h" +#import "CountryCodeTableViewCell.h" #import "FunctionalUtil.h" +#import "PhoneNumberUtil.h" +#import "UIView+OWS.h" static NSString *const CONTRY_CODE_TABLE_CELL_IDENTIFIER = @"CountryCodeTableViewCell"; -static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryCodeWasSelectedSegue"; -@interface CountryCodeViewController () { +@interface CountryCodeViewController () { NSArray *_countryCodes; } +@property (nonatomic) IBOutlet UITableView *countryCodeTableView; +@property (nonatomic) IBOutlet UISearchBar *searchBar; + +@property (nonatomic) NSString *countryCodeSelected; +@property (nonatomic) NSString *callingCodeSelected; +@property (nonatomic) NSString *countryNameSelected; + @end @implementation CountryCodeViewController - (void)viewDidLoad { [super viewDidLoad]; + self.view.backgroundColor = [UIColor whiteColor]; + [self.view addRedBorder]; [self.navigationController.navigationBar setTranslucent:NO]; _countryCodes = [PhoneNumberUtil countryCodesForSearchTerm:nil]; self.title = NSLocalizedString(@"COUNTRYCODE_SELECT_TITLE", @""); self.searchBar.delegate = self; - if (self.shouldDismissWithoutSegue) { - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop - target:self - action:@selector(dismissWasPressed:)]; - } + + self.navigationItem.leftBarButtonItem = + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop + target:self + action:@selector(dismissWasPressed:)]; } #pragma mark - UITableViewDelegate @@ -66,11 +78,7 @@ static NSString *const kUnwindToCountryCodeWasSelectedSegue = @"UnwindToCountryC countryName:_countryNameSelected callingCode:_callingCodeSelected]; [self.searchBar resignFirstResponder]; - if (self.shouldDismissWithoutSegue) { - [self dismissViewControllerAnimated:YES completion:nil]; - } else { - [self performSegueWithIdentifier:kUnwindToCountryCodeWasSelectedSegue sender:self]; - } + [self dismissViewControllerAnimated:YES completion:nil]; } - (void)dismissWasPressed:(id)sender { diff --git a/Signal/src/ViewControllers/RegistrationViewController.h b/Signal/src/ViewControllers/RegistrationViewController.h index dbc25963b..d671fa59e 100644 --- a/Signal/src/ViewControllers/RegistrationViewController.h +++ b/Signal/src/ViewControllers/RegistrationViewController.h @@ -1,9 +1,5 @@ // -// RegistrationViewController.h -// Signal -// -// Created by Dylan Bourgeois on 13/11/14. -// Copyright (c) 2014 Open Whisper Systems. All rights reserved. +// Copyright (c) 2017 Open Whisper Systems. All rights reserved. // #import @@ -13,18 +9,19 @@ @interface RegistrationViewController : UIViewController // Country code -@property (nonatomic, strong) IBOutlet UIButton *countryNameButton; -@property (nonatomic, strong) IBOutlet UIButton *countryCodeButton; +@property (nonatomic) IBOutlet UIButton *countryNameButton; +@property (nonatomic) IBOutlet UIButton *countryCodeButton; +@property (nonatomic) IBOutlet UIView *countryCodeRow; // Phone number -@property (nonatomic, strong) IBOutlet UITextField *phoneNumberTextField; -@property (nonatomic, strong) IBOutlet UIButton *phoneNumberButton; -@property (nonatomic, strong) IBOutlet UILabel *titleLabel; +@property (nonatomic) IBOutlet UITextField *phoneNumberTextField; +@property (nonatomic) IBOutlet UIButton *phoneNumberButton; +@property (nonatomic) IBOutlet UILabel *titleLabel; // Button -@property (nonatomic, strong) IBOutlet UIButton *sendCodeButton; -@property (nonatomic, strong) IBOutlet UIButton *existingUserButton; +@property (nonatomic) IBOutlet UIButton *sendCodeButton; +@property (nonatomic) IBOutlet UIButton *existingUserButton; -@property (nonatomic, strong) IBOutlet UIActivityIndicatorView *spinnerView; +@property (nonatomic) IBOutlet UIActivityIndicatorView *spinnerView; @property (nonatomic) IBOutlet UIImageView *signalLogo; @property (nonatomic) IBOutlet UIView *registrationHeader; diff --git a/Signal/src/ViewControllers/RegistrationViewController.m b/Signal/src/ViewControllers/RegistrationViewController.m index 79b4f1ee7..eb509661f 100644 --- a/Signal/src/ViewControllers/RegistrationViewController.m +++ b/Signal/src/ViewControllers/RegistrationViewController.m @@ -16,7 +16,7 @@ static NSString *const kCodeSentSegue = @"codeSent"; -@interface RegistrationViewController () +@interface RegistrationViewController () @property (nonatomic) NSString *callingCode; @@ -48,6 +48,16 @@ static NSString *const kCodeSentSegue = @"codeSent"; [_sendCodeButton setTitle:NSLocalizedString(@"REGISTRATION_VERIFY_DEVICE", @"") forState:UIControlStateNormal]; [_existingUserButton setTitle:NSLocalizedString(@"ALREADY_HAVE_ACCOUNT_BUTTON", @"registration button text") forState:UIControlStateNormal]; + + [self.countryNameButton addTarget:self + action:@selector(changeCountryCodeTapped) + forControlEvents:UIControlEventTouchUpInside]; + [self.countryCodeButton addTarget:self + action:@selector(changeCountryCodeTapped) + forControlEvents:UIControlEventTouchUpInside]; + [self.countryCodeRow + addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(countryCodeRowWasTapped:)]]; } - (void)viewWillAppear:(BOOL)animated { @@ -175,9 +185,21 @@ static NSString *const kCodeSentSegue = @"codeSent"; smsVerification:YES]; } -- (IBAction)changeCountryCodeTapped { - CountryCodeViewController *countryCodeController = [CountryCodeViewController new]; - [self presentViewController:countryCodeController animated:YES completion:[UIUtil modalCompletionBlock]]; +- (void)countryCodeRowWasTapped:(UIGestureRecognizer *)sender +{ + if (sender.state == UIGestureRecognizerStateRecognized) { + [self changeCountryCodeTapped]; + } +} + +- (void)changeCountryCodeTapped +{ + CountryCodeViewController *countryCodeController = [[UIStoryboard storyboardWithName:@"Registration" bundle:NULL] + instantiateViewControllerWithIdentifier:@"CountryCodeViewController"]; + countryCodeController.delegate = self; + UINavigationController *navigationController = + [[UINavigationController alloc] initWithRootViewController:countryCodeController]; + [self presentViewController:navigationController animated:YES completion:[UIUtil modalCompletionBlock]]; } - (void)presentInvalidCountryCodeError { @@ -187,6 +209,20 @@ static NSString *const kCodeSentSegue = @"codeSent"; @"DISMISS_BUTTON_TEXT", @"Generic short text for button to dismiss a dialog")]; } +#pragma mark - CountryCodeViewControllerDelegate + +- (void)countryCodeViewController:(CountryCodeViewController *)vc + didSelectCountryCode:(NSString *)countryCode + countryName:(NSString *)countryName + callingCode:(NSString *)callingCode +{ + + [self updateCountryWithName:countryName callingCode:callingCode countryCode:countryCode]; + + // Trigger the formatting logic with a no-op edit. + [self textField:self.phoneNumberTextField shouldChangeCharactersInRange:NSMakeRange(0, 0) replacementString:@""]; +} + #pragma mark - Keyboard notifications - (void)initializeKeyboardHandlers { @@ -224,19 +260,6 @@ static NSString *const kCodeSentSegue = @"codeSent"; - (IBAction)unwindToChangeNumber:(UIStoryboardSegue *)sender { } -- (IBAction)unwindToCountryCodeSelectionCancelled:(UIStoryboardSegue *)segue { -} - -- (IBAction)unwindToCountryCodeWasSelected:(UIStoryboardSegue *)segue { - CountryCodeViewController *vc = [segue sourceViewController]; - [self updateCountryWithName:vc.countryNameSelected - callingCode:vc.callingCodeSelected - countryCode:vc.countryCodeSelected]; - - // Reformat phone number - [self textField:_phoneNumberTextField shouldChangeCharactersInRange:NSMakeRange(0, 0) replacementString:@""]; -} - #pragma mark iPhone 5s or shorter - (void)adjustScreenSizes diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index f7413ae45..9a7dcacf6 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -287,7 +287,6 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien CountryCodeViewController *countryCodeController = [[UIStoryboard storyboardWithName:@"Registration" bundle:NULL] instantiateViewControllerWithIdentifier:@"CountryCodeViewController"]; countryCodeController.delegate = self; - countryCodeController.shouldDismissWithoutSegue = YES; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:countryCodeController]; [self presentViewController:navigationController animated:YES completion:[UIUtil modalCompletionBlock]];