From 7d86b9bd88431db5452f615bef5d7bb81ae3e952 Mon Sep 17 00:00:00 2001 From: REIS Benjamin Date: Thu, 6 Oct 2016 16:58:38 +0200 Subject: [PATCH] Assistant Link view contorl phone number --- Classes/AssistantLinkView.h | 2 +- Classes/AssistantLinkView.m | 18 ++++++++++++++++++ Classes/AssistantView.m | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Classes/AssistantLinkView.h b/Classes/AssistantLinkView.h index fc822f1cd..20131201a 100644 --- a/Classes/AssistantLinkView.h +++ b/Classes/AssistantLinkView.h @@ -9,7 +9,7 @@ #import "PhoneMainView.h" #import -@interface AssistantLinkView : UIViewController +@interface AssistantLinkView : UIViewController @property(weak, nonatomic) IBOutlet UIView *linkAccountView; @property(weak, nonatomic) IBOutlet UIView *activateSMSView; diff --git a/Classes/AssistantLinkView.m b/Classes/AssistantLinkView.m index d2ac46d9d..ba62ffca1 100644 --- a/Classes/AssistantLinkView.m +++ b/Classes/AssistantLinkView.m @@ -11,6 +11,7 @@ #import "AssistantLinkView.h" #import "UITextField+DoneButton.h" +#import "UIAssistantTextField.h" @implementation AssistantLinkView { LinphoneAccountCreator *account_creator; @@ -20,6 +21,7 @@ [super viewDidLoad]; // every UITextField subviews with phone keyboard must be tweaked to have a done button [self addDoneButtonRecursivelyInView:self.view]; + self.phoneField.delegate = self; } - (void)addDoneButtonRecursivelyInView:(UIView *)subview { @@ -230,4 +232,20 @@ void assistant_activate_phone_number_link(LinphoneAccountCreator *creator, Linph _countryCodeField.text = [country objectForKey:@"code"]; } +#pragma mark - UITextFieldDelegate Functions + +- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { + LinphoneAccountCreatorStatus status = linphone_account_creator_set_phone_number(account_creator, [_phoneField.text UTF8String], [_countryCodeField.text UTF8String]); + if (status == LinphoneAccountCreatorPhoneNumberTooLong || self.phoneField.text.length < 8 || status == LinphoneAccountCreatorPhoneNumberInvalid) { + self.phoneField.layer.borderWidth = .8; + self.phoneField.layer.cornerRadius = 4.f; + self.phoneField.layer.borderColor = [[UIColor redColor] CGColor]; + self.linkAccountButton.enabled = FALSE; + } else { + self.phoneField.layer.borderColor = [[UIColor clearColor] CGColor]; + self.linkAccountButton.enabled = TRUE; + } + return YES; +} + @end diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index 25954154e..563efb4f6 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -531,7 +531,7 @@ static UICompositeViewDescription *compositeDescription = nil; }]; UIAssistantTextField *password2 = [self findTextField:ViewElement_Password2]; - [password2 showError:NSLocalizedString(@"Passwords do not match.", nil) + [password2 showError:NSLocalizedString(@"The confirmation code is invalid. \nPlease check your SMS and try again.", nil) when:^BOOL(NSString *inputEntry) { return ![inputEntry isEqualToString:[self findTextField:ViewElement_Password].text]; }];