WizardView: add possibliity to use phone number instead of SIP address

This commit is contained in:
Gautier Pelloux-Prayer 2015-04-30 11:25:00 +02:00
parent 3947a32127
commit ab50ed8cfe
5 changed files with 57 additions and 25 deletions

View file

@ -10,10 +10,13 @@
<outlet property="choiceView" destination="33" id="40"/>
<outlet property="choiceViewLogoImageView" destination="128" id="136"/>
<outlet property="connectAccountButton" destination="38" id="134"/>
<outlet property="connectAccountUsername" destination="68" id="9qb-9c-Y0k"/>
<outlet property="connectAccountView" destination="52" id="71"/>
<outlet property="createAccountButton" destination="36" id="135"/>
<outlet property="createAccountUsername" destination="74" id="ptL-W1-8vl"/>
<outlet property="createAccountView" destination="44" id="70"/>
<outlet property="externalAccountButton" destination="39" id="133"/>
<outlet property="externalAccountUsername" destination="59" id="2bn-uT-cSf"/>
<outlet property="externalAccountView" destination="56" id="72"/>
<outlet property="provisionedAccountView" destination="xVK-hL-6pe" id="jZM-mc-m1Q"/>
<outlet property="provisionedDomain" destination="wRB-Sh-K8J" id="Ieb-x8-yL4"/>
@ -455,7 +458,7 @@
</connections>
</button>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="These parameters were retrieved from a remote provisioning profile." textAlignment="center" lineBreakMode="wordWrap" numberOfLines="7" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="RHE-hi-dfB" userLabel="remoteParamsLabel">
<rect key="frame" x="34" y="414.00000272146076" width="254" height="82"/>
<rect key="frame" x="34" y="414" width="254" height="82"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="11"/>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>

View file

@ -20,6 +20,7 @@
#import <UIKit/UIKit.h>
#import <XMLRPCConnectionDelegate.h>
#import "UICompositeViewController.h"
#import "UILinphoneTextField.h"
@interface WizardViewController : TPMultiLayoutViewController
<UITextFieldDelegate,
@ -54,6 +55,10 @@
@property (nonatomic, retain) IBOutlet UIButton *externalAccountButton;
@property (retain, nonatomic) IBOutlet UIButton *remoteProvisioningButton;
@property (retain, nonatomic) IBOutlet UILinphoneTextField *createAccountUsername;
@property (retain, nonatomic) IBOutlet UILinphoneTextField *connectAccountUsername;
@property (retain, nonatomic) IBOutlet UILinphoneTextField *externalAccountUsername;
@property (retain, nonatomic) IBOutlet UITextField *provisionedUsername;
@property (retain, nonatomic) IBOutlet UITextField *provisionedPassword;
@property (retain, nonatomic) IBOutlet UITextField *provisionedDomain;

View file

@ -113,6 +113,9 @@ typedef enum _ViewElement {
[provisionedPassword release];
[provisionedDomain release];
[_transportChooser release];
[_createAccountUsername release];
[_connectAccountUsername release];
[_externalAccountUsername release];
[super dealloc];
}
@ -196,6 +199,18 @@ static UICompositeViewDescription *compositeDescription = nil;
[LinphoneUtils adjustFontSize:validateAccountView mult:2.22f];
[LinphoneUtils adjustFontSize:provisionedAccountView mult:2.22f];
}
BOOL usePhoneNumber = [[LinphoneManager instance] lpConfigStringForKey:@"use_phone_number"];
for (UILinphoneTextField* text in [NSArray arrayWithObjects:provisionedUsername, _createAccountUsername,
_connectAccountUsername, _externalAccountUsername, nil]) {
if (usePhoneNumber) {
text.keyboardType = UIKeyboardTypePhonePad;
text.placeholder = NSLocalizedString(@"Phone number", nil);
} else {
text.keyboardType = UIKeyboardTypeDefault;
text.placeholder = NSLocalizedString(@"Username", nil);
}
}
}
@ -633,32 +648,40 @@ static UICompositeViewDescription *compositeDescription = nil;
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// only validate the username when creating a new account
if( (textField.tag == ViewElement_Username) && (currentView == createAccountView) ){
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"^[a-z0-9-_\\.]*$"
options:NSRegularExpressionCaseInsensitive
error:nil];
NSArray* matches = [regex matchesInString:string options:0 range:NSMakeRange(0, [string length])];
if ([matches count] == 0) {
UILabel* error = [WizardViewController findLabel:ViewElement_Username_Error view:contentView];
// only validate the username when creating a new account
if( (textField.tag == ViewElement_Username) && (currentView == createAccountView) ){
BOOL isValidUsername = YES;
BOOL usePhoneNumber = [[LinphoneManager instance] lpConfigStringForKey:@"use_phone_number"];
if (usePhoneNumber) {
isValidUsername = linphone_proxy_config_is_phone_number(NULL, [string UTF8String]);
} else {
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"^[a-z0-9-_\\.]*$"
options:NSRegularExpressionCaseInsensitive
error:nil];
// show error with fade animation
[error setText:[NSString stringWithFormat:NSLocalizedString(@"Illegal character in username: %@", nil), string]];
error.alpha = 0;
error.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
error.alpha = 1;
}];
NSArray* matches = [regex matchesInString:string options:0 range:NSMakeRange(0, [string length])];
isValidUsername = ([matches count] != 0);
}
// hide again in 2s
[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(hideError:) userInfo:nil repeats:NO];
if (!isValidUsername) {
UILabel* error = [WizardViewController findLabel:ViewElement_Username_Error view:contentView];
// show error with fade animation
[error setText:[NSString stringWithFormat:NSLocalizedString(@"Illegal character in %@: %@", nil),
usePhoneNumber ? NSLocalizedString(@"phone number",nil) : NSLocalizedString(@"username", nil), string]];
error.alpha = 0;
error.hidden = NO;
[UIView animateWithDuration:0.3 animations:^{
error.alpha = 1;
}];
return NO;
}
}
return YES;
// hide again in 2s
[NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(hideError:) userInfo:nil repeats:NO];
return NO;
}
}
return YES;
}
- (void)hideError:(NSTimer*)timer {
UILabel* error_label =[WizardViewController findLabel:ViewElement_Username_Error view:contentView];

View file

@ -16,4 +16,5 @@ display_filter_auto_rotate=0
[app]
#contact_display_username_only=1
#contact_filter_on_default_domain=1
#contact_filter_on_default_domain=1
#use_phone_number=0

@ -1 +1 @@
Subproject commit 42b997277057e0e9084b9fed2e39609fe8e4d07d
Subproject commit 02b967955148eed300e26cd3605eb1587422952c