From 2d05f938d904625a5581a426e02c21e426485a08 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 9 Nov 2015 14:53:54 +0100 Subject: [PATCH] FirstLogin: continue --- Classes/AssistantView.h | 2 + Classes/AssistantView.m | 44 ++--- Classes/FirstLoginView.h | 7 +- Classes/FirstLoginView.m | 49 +++++- Classes/FirstLoginView.xib | 202 ++++++++++++++++------ Classes/LinphoneUI/UIAddressTextField.h | 2 +- Classes/LinphoneUI/UIAssistantTextField.m | 15 +- Classes/PhoneMainView.h | 2 +- Classes/PhoneMainView.m | 2 +- Classes/Utils/Utils.h | 20 +++ Resources/linphonerc-factory | 4 + 11 files changed, 260 insertions(+), 89 deletions(-) diff --git a/Classes/AssistantView.h b/Classes/AssistantView.h index b98368a23..6b819dbde 100644 --- a/Classes/AssistantView.h +++ b/Classes/AssistantView.h @@ -49,6 +49,8 @@ @property(nonatomic, strong) IBOutlet UIButton *gotoLoginButton; @property(nonatomic, strong) IBOutlet UIButton *gotoRemoteProvisioningButton; ++ (NSString *)errorForStatus:(LinphoneAccountCreatorStatus)status; + - (void)reset; - (void)fillDefaultValues; diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index adf9af758..0ad7bf8c7 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -171,7 +171,7 @@ static UICompositeViewDescription *compositeDescription = nil; [historyViews removeAllObjects]; } -- (NSString *)errorForStatus:(LinphoneAccountCreatorStatus)status { ++ (NSString *)errorForStatus:(LinphoneAccountCreatorStatus)status { BOOL usePhoneNumber = [[LinphoneManager instance] lpConfigBoolForKey:@"use_phone_number" forSection:@"assistant"]; switch (status) { case LinphoneAccountCreatorEmailInvalid: @@ -408,21 +408,21 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)prepareErrorLabels { UIAssistantTextField *createUsername = [self findTextField:ViewElement_Username]; - [createUsername showError:[self errorForStatus:LinphoneAccountCreatorUsernameInvalid] + [createUsername showError:[AssistantView errorForStatus:LinphoneAccountCreatorUsernameInvalid] when:^BOOL(NSString *inputEntry) { - LinphoneAccountCreatorStatus s = - linphone_account_creator_set_username(account_creator, inputEntry.UTF8String); - createUsername.errorLabel.text = [self errorForStatus:s]; - return s != LinphoneAccountCreatorOK; + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_username(account_creator, inputEntry.UTF8String); + createUsername.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; }]; UIAssistantTextField *password = [self findTextField:ViewElement_Password]; - [password showError:[self errorForStatus:LinphoneAccountCreatorPasswordTooShort] + [password showError:[AssistantView errorForStatus:LinphoneAccountCreatorPasswordTooShort] when:^BOOL(NSString *inputEntry) { - LinphoneAccountCreatorStatus s = - linphone_account_creator_set_password(account_creator, inputEntry.UTF8String); - password.errorLabel.text = [self errorForStatus:s]; - return s != LinphoneAccountCreatorOK; + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_password(account_creator, inputEntry.UTF8String); + password.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; }]; UIAssistantTextField *password2 = [self findTextField:ViewElement_Password2]; @@ -432,21 +432,21 @@ static UICompositeViewDescription *compositeDescription = nil; }]; UIAssistantTextField *email = [self findTextField:ViewElement_Email]; - [email showError:[self errorForStatus:LinphoneAccountCreatorEmailInvalid] + [email showError:[AssistantView errorForStatus:LinphoneAccountCreatorEmailInvalid] when:^BOOL(NSString *inputEntry) { - LinphoneAccountCreatorStatus s = - linphone_account_creator_set_email(account_creator, inputEntry.UTF8String); - email.errorLabel.text = [self errorForStatus:s]; - return s != LinphoneAccountCreatorOK; + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_email(account_creator, inputEntry.UTF8String); + email.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; }]; UIAssistantTextField *domain = [self findTextField:ViewElement_Domain]; - [domain showError:[self errorForStatus:LinphoneAccountCreatorDomainInvalid] + [domain showError:[AssistantView errorForStatus:LinphoneAccountCreatorDomainInvalid] when:^BOOL(NSString *inputEntry) { - LinphoneAccountCreatorStatus s = - linphone_account_creator_set_domain(account_creator, inputEntry.UTF8String); - domain.errorLabel.text = [self errorForStatus:s]; - return s != LinphoneAccountCreatorOK; + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_domain(account_creator, inputEntry.UTF8String); + domain.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; }]; UIAssistantTextField *url = [self findTextField:ViewElement_URL]; @@ -616,7 +616,7 @@ void assistant_validation_tested(LinphoneAccountCreator *creator, LinphoneAccoun UIAssistantTextField *atf = (UIAssistantTextField *)textField; [atf textField:atf shouldChangeCharactersInRange:range replacementString:string]; if (atf.tag == ViewElement_Username && currentView == _createAccountView) { - textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string.lowercaseString]; + atf.text = [atf.text stringByReplacingCharactersInRange:range withString:string.lowercaseString]; [self shouldEnableNextButton]; return NO; } diff --git a/Classes/FirstLoginView.h b/Classes/FirstLoginView.h index 2b3e2c33a..25d54de97 100644 --- a/Classes/FirstLoginView.h +++ b/Classes/FirstLoginView.h @@ -20,8 +20,10 @@ #import #import "UICompositeView.h" +#import "UIAssistantTextField.h" @interface FirstLoginView : UIViewController { + LinphoneAccountCreator *account_creator; } - (IBAction)onLoginClick:(id)sender; @@ -29,8 +31,9 @@ @property(nonatomic, strong) IBOutlet UIButton *loginButton; @property(nonatomic, strong) IBOutlet UIButton *siteButton; -@property(nonatomic, strong) IBOutlet UITextField *usernameField; -@property(nonatomic, strong) IBOutlet UITextField *passwordField; +@property(nonatomic, strong) IBOutlet UIAssistantTextField *usernameField; +@property(nonatomic, strong) IBOutlet UIAssistantTextField *passwordField; @property(nonatomic, strong) IBOutlet UIView *waitView; +@property(weak, nonatomic) IBOutlet UIAssistantTextField *domainField; @end diff --git a/Classes/FirstLoginView.m b/Classes/FirstLoginView.m index aba233c3f..e71a5ae4a 100644 --- a/Classes/FirstLoginView.m +++ b/Classes/FirstLoginView.m @@ -66,6 +66,30 @@ static UICompositeViewDescription *compositeDescription = nil; [self registrationUpdate:linphone_proxy_config_get_state(config)]; } } + + [_usernameField showError:[AssistantView errorForStatus:LinphoneAccountCreatorUsernameInvalid] + when:^BOOL(NSString *inputEntry) { + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_username(account_creator, inputEntry.UTF8String); + _usernameField.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; + }]; + + [_passwordField showError:[AssistantView errorForStatus:LinphoneAccountCreatorPasswordTooShort] + when:^BOOL(NSString *inputEntry) { + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_password(account_creator, inputEntry.UTF8String); + _passwordField.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; + }]; + + [_domainField showError:[AssistantView errorForStatus:LinphoneAccountCreatorDomainInvalid] + when:^BOOL(NSString *inputEntry) { + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_domain(account_creator, inputEntry.UTF8String); + _domainField.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; + }]; } - (void)viewWillDisappear:(BOOL)animated { @@ -83,6 +107,15 @@ static UICompositeViewDescription *compositeDescription = nil; siteUrl = @"http://www.linphone.org"; } [_siteButton setTitle:siteUrl forState:UIControlStateNormal]; + account_creator = linphone_account_creator_new([LinphoneManager getLc], siteUrl.UTF8String); +} + +- (void)shouldEnableNextButton { + BOOL invalidInputs = NO; + for (UIAssistantTextField *field in @[ _usernameField, _passwordField, _domainField ]) { + invalidInputs |= (field.isInvalid || field.lastText.length == 0); + } + _loginButton.enabled = !invalidInputs; } #pragma mark - Event Functions @@ -91,8 +124,6 @@ static UICompositeViewDescription *compositeDescription = nil; [self registrationUpdate:[[notif.userInfo objectForKey:@"state"] intValue]]; } -#pragma mark - - - (void)registrationUpdate:(LinphoneRegistrationState)state { switch (state) { case LinphoneRegistrationOk: { @@ -175,4 +206,18 @@ static UICompositeViewDescription *compositeDescription = nil; return YES; } +- (void)textFieldDidEndEditing:(UITextField *)textField { + UIAssistantTextField *atf = (UIAssistantTextField *)textField; + [atf textFieldDidEndEditing:atf]; +} + +- (BOOL)textField:(UITextField *)textField + shouldChangeCharactersInRange:(NSRange)range + replacementString:(NSString *)string { + UIAssistantTextField *atf = (UIAssistantTextField *)textField; + [atf textField:atf shouldChangeCharactersInRange:range replacementString:string]; + [self shouldEnableNextButton]; + return YES; +} + @end diff --git a/Classes/FirstLoginView.xib b/Classes/FirstLoginView.xib index 7693bbc4d..eb1c8b447 100644 --- a/Classes/FirstLoginView.xib +++ b/Classes/FirstLoginView.xib @@ -1,94 +1,184 @@ - + - - + + - + - - - - + + + + - + - - - - - + + + + + + + + + + + + + - + + - + - - - + + + + + + + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + - \ No newline at end of file + diff --git a/Classes/LinphoneUI/UIAddressTextField.h b/Classes/LinphoneUI/UIAddressTextField.h index 62a3dd13b..d0c179654 100644 --- a/Classes/LinphoneUI/UIAddressTextField.h +++ b/Classes/LinphoneUI/UIAddressTextField.h @@ -19,6 +19,6 @@ #import -@interface UIAddressTextField : UITextField +@interface UIAddressTextField : UITextField @end diff --git a/Classes/LinphoneUI/UIAssistantTextField.m b/Classes/LinphoneUI/UIAssistantTextField.m index af674770b..c034d2bc4 100644 --- a/Classes/LinphoneUI/UIAssistantTextField.m +++ b/Classes/LinphoneUI/UIAssistantTextField.m @@ -7,9 +7,14 @@ // #import "UIAssistantTextField.h" +#import "Utils.h" @implementation UIAssistantTextField +INIT_WITH_COMMON { + self.delegate = self; +} + - (void)showError:(NSString *)msg { _errorLabel.text = msg; _lastText = self.text; @@ -32,6 +37,12 @@ self.layer.borderColor = _errorLabel.hidden ? [[UIColor clearColor] CGColor] : [[UIColor redColor] CGColor]; } +- (BOOL)isInvalid { + return _showErrorPredicate && _showErrorPredicate(_lastText); +} + +#pragma mark - UITextFieldDelegate Functions + - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { @@ -45,8 +56,4 @@ [self checkDisplayError]; } -- (BOOL)isInvalid { - return _showErrorPredicate && _showErrorPredicate(_lastText); -} - @end diff --git a/Classes/PhoneMainView.h b/Classes/PhoneMainView.h index 7caa75e7b..340ab5d40 100644 --- a/Classes/PhoneMainView.h +++ b/Classes/PhoneMainView.h @@ -35,11 +35,11 @@ #import "CallView.h" #import "CallIncomingView.h" #import "CallOutgoingView.h" +#import "FirstLoginView.h" #import "SettingsView.h" #import "SideMenuView.h" #import "AssistantView.h" #import "CallSideMenuView.h" -//#import "ChatConversationCreateView.h" #import "UIConfirmationDialog.h" #import "DTAlertView.h" #import "DTActionSheet.h" diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 7e3710cc9..4dd798502 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -418,7 +418,7 @@ static RootViewManager *rootViewManagerInstance = nil; if (linphone_core_get_global_state(core) != LinphoneGlobalOn) { [self changeCurrentView:DialerView.compositeViewDescription]; } else if ([[LinphoneManager instance] lpConfigBoolForKey:@"enable_first_login_view_preference"] == true) { - // TODO: Change to fist login view + [PhoneMainView.instance changeCurrentView:FirstLoginView.compositeViewDescription]; } else { // always start to dialer when testing // Change to default view diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index 6085eb8ea..54d8f4fd5 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -105,3 +105,23 @@ typedef enum { + (UIImage *)decodedImageWithImage:(UIImage *)image; @end + +/* Use that macro when you want to invoke a custom initialisation method on your class, + whatever is using it (xib, source code, etc., tableview cell) */ +#define INIT_WITH_COMMON \ + -(instancetype)init { \ + self = [super init]; \ + [self commonInit]; \ + return self; \ + } \ + -(instancetype)initWithCoder : (NSCoder *)aDecoder { \ + self = [super initWithCoder:aDecoder]; \ + [self commonInit]; \ + return self; \ + } \ + -(instancetype)initWithFrame : (CGRect)frame { \ + self = [super initWithFrame:frame]; \ + [self commonInit]; \ + return self; \ + } \ + -(void)commonInit diff --git a/Resources/linphonerc-factory b/Resources/linphonerc-factory index 1ab76677e..8e0485ca3 100644 --- a/Resources/linphonerc-factory +++ b/Resources/linphonerc-factory @@ -17,6 +17,10 @@ display_filter_auto_rotate=0 #contact_filter_on_default_domain=1 #use_phone_number=0 send_logs_include_linphonerc_and_chathistory=0 +enable_first_login_view_preference=1 + +[assistant] +username_regex=^[a-z0-9_.\-]*$ [in_app_purchase] enabled=0 \ No newline at end of file