assistant error handling bis

This commit is contained in:
Gautier Pelloux-Prayer 2015-10-01 17:31:08 +02:00
parent 787004c26a
commit affbf01a93
10 changed files with 63 additions and 76 deletions

View file

@ -36,9 +36,8 @@ typedef enum _ViewElement {
ViewElement_Email = 103,
ViewElement_Domain = 104,
ViewElement_Transport = 105,
ViewElement_Username_Label = 106,
ViewElement_NextButton = 130,
ViewElement_Label = 200,
ViewElement_Error = 201,
} ViewElement;
@implementation AssistantView
@ -135,6 +134,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[LinphoneManager getLc],
[LinphoneManager.instance lpConfigStringForKey:@"xmlrpc_url" forSection:@"assistant" withDefault:@""]
.UTF8String);
linphone_account_creator_set_user_data(account_creator, (__bridge void *)(self));
linphone_account_creator_cbs_set_existence_tested(linphone_account_creator_get_callbacks(account_creator),
assistant_existence_tested);
linphone_account_creator_cbs_set_create_account(linphone_account_creator_get_callbacks(account_creator),
@ -341,7 +341,7 @@ static UICompositeViewDescription *compositeDescription = nil;
BOOL usePhoneNumber = [LinphoneManager.instance lpConfigBoolForKey:@"use_phone_number"];
NSString *label = usePhoneNumber ? NSLocalizedString(@"PHONE NUMBER", nil) : NSLocalizedString(@"USERNAME", nil);
[self findLabel:ViewElement_Username].text = label;
[self findLabel:ViewElement_Username_Label].text = label;
UITextField *text = [self findTextField:ViewElement_Username];
if (usePhoneNumber) {
@ -353,8 +353,9 @@ static UICompositeViewDescription *compositeDescription = nil;
}
+ (void)cleanTextField:(UIView *)view {
if ([view isKindOfClass:[UITextField class]]) {
[(UITextField *)view setText:@""];
if ([view isKindOfClass:UIAssistantTextField.class]) {
[(UIAssistantTextField *)view setText:@""];
((UIAssistantTextField *)view).canShowError = NO;
} else {
for (UIView *subview in view.subviews) {
[AssistantView cleanTextField:subview];
@ -396,30 +397,21 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)prepareErrorLabels {
UIAssistantTextField *createUsername = [self findTextField:ViewElement_Username];
[createUsername
showError:NSLocalizedString(@"Invalid entry", nil)
when:^BOOL(NSString *inputEntry) {
NSString *oldRegex =
[LinphoneManager.instance lpConfigStringForKey:@"username_regex" forSection:@"assistant"];
// new account for linphone accounts must follow a specific regex
if (currentView == _createAccountView) {
[LinphoneManager.instance lpConfigSetString:@"^[a-z0-9-_\\.]*$"
forKey:@"username_regex"
forSection:@"assistant"];
}
LinphoneAccountCreatorStatus s =
linphone_account_creator_set_username(account_creator, inputEntry.UTF8String);
[LinphoneManager.instance lpConfigSetString:oldRegex forKey:@"username_regex" forSection:@"assistant"];
createUsername.errorLabel.text = [self errorForStatus:s];
return s != LinphoneAccountCreatorOk;
}];
[createUsername showError:[self 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;
}];
UIAssistantTextField *password = [self findTextField:ViewElement_Password];
[password showError:NSLocalizedString(@"Password is too short.", nil)
[password showError:[self errorForStatus:LinphoneAccountCreatorPasswordTooShort]
when:^BOOL(NSString *inputEntry) {
NSInteger password_length =
[[LinphoneManager instance] lpConfigIntForKey:@"password_length" forSection:@"assistant"];
return password_length > 0 && inputEntry.length < password_length;
LinphoneAccountCreatorStatus s =
linphone_account_creator_set_password(account_creator, inputEntry.UTF8String);
password.errorLabel.text = [self errorForStatus:s];
return s != LinphoneAccountCreatorOk;
}];
UIAssistantTextField *password2 = [self findTextField:ViewElement_Password2];
@ -429,11 +421,12 @@ static UICompositeViewDescription *compositeDescription = nil;
}];
UIAssistantTextField *email = [self findTextField:ViewElement_Email];
[email showError:NSLocalizedString(@"Invalid email address.", nil)
[email showError:[self errorForStatus:LinphoneAccountCreatorEmailInvalid]
when:^BOOL(NSString *inputEntry) {
NSPredicate *emailTest =
[NSPredicate predicateWithFormat:@"SELF MATCHES %@", @".+@.+\\.[A-Za-z]{2}[A-Za-z]*"];
return ![emailTest evaluateWithObject:inputEntry];
LinphoneAccountCreatorStatus s =
linphone_account_creator_set_email(account_creator, inputEntry.UTF8String);
email.errorLabel.text = [self errorForStatus:s];
return s != LinphoneAccountCreatorOk;
}];
[self shouldEnableNextButton];
@ -524,12 +517,10 @@ static UICompositeViewDescription *compositeDescription = nil;
void assistant_existence_tested(LinphoneAccountCreator *creator, LinphoneAccountCreatorStatus status) {
AssistantView *thiz = (__bridge AssistantView *)(linphone_account_creator_get_user_data(creator));
thiz.waitView.hidden = YES;
if (status == LinphoneAccountCreatorOk) {
thiz.waitView.hidden = YES;
[[thiz findTextField:ViewElement_Username] showError:NSLocalizedString(@"This name is already taken.", nil)];
[thiz findButton:ViewElement_NextButton].enabled = NO;
} else {
thiz.waitView.hidden = NO;
}
}
@ -563,10 +554,10 @@ void assistant_validation_tested(LinphoneAccountCreator *creator, LinphoneAccoun
initWithTitle:NSLocalizedString(@"Account validation failed.", nil)
message:
NSLocalizedString(
@"Your account could not be verified yet. You can skip this validation or try again later.",
@"Your account could not be checked yet. You can skip this validation or try again later.",
nil)];
[alert addCancelButtonWithTitle:NSLocalizedString(@"Try again", nil) block:nil];
[alert addButtonWithTitle:NSLocalizedString(@"Ignore", nil)
[alert addCancelButtonWithTitle:NSLocalizedString(@"Cancel", nil) block:nil];
[alert addButtonWithTitle:NSLocalizedString(@"Skip verification", nil)
block:^{
[thiz addProxyConfig:linphone_account_creator_configure(creator)];
[PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription];

View file

@ -145,6 +145,13 @@
<nil key="highlightedColor"/>
<size key="shadowOffset" width="-1" height="-1"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" tag="106" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="ZSJ-Lv-n60" userLabel="usernameLabel">
<rect key="frame" x="38" y="165" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.50196078430000002" green="0.50196078430000002" blue="0.50196078430000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" tag="100" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" adjustsFontSizeToFit="NO" minimumFontSize="10" id="74" userLabel="usernameField" customClass="UIAssistantTextField">
<rect key="frame" x="38" y="187" width="299" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
@ -156,9 +163,9 @@
<outlet property="delegate" destination="-1" id="80"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="ZSJ-Lv-n60" userLabel="usernameLabel">
<rect key="frame" x="38" y="165" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PASSWORD" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="RIQ-aB-k0Y" userLabel="passwordLabel">
<rect key="frame" x="38" y="226" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.50196078430000002" green="0.50196078430000002" blue="0.50196078430000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
@ -174,8 +181,8 @@
<outlet property="delegate" destination="-1" id="82"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PASSWORD" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="RIQ-aB-k0Y" userLabel="passwordLabel">
<rect key="frame" x="38" y="226" width="299" height="14"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PASSWORD CONFIRMATION" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="yyK-OU-HXT" userLabel="password2Label">
<rect key="frame" x="38" y="293" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.50196078430000002" green="0.50196078430000002" blue="0.50196078430000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@ -192,8 +199,8 @@
<outlet property="delegate" destination="-1" id="83"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PASSWORD CONFIRMATION" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="yyK-OU-HXT" userLabel="password2Label">
<rect key="frame" x="38" y="293" width="299" height="14"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="EMAIL" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Syg-X5-YFX" userLabel="emailLabel">
<rect key="frame" x="38" y="358" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.50196078430000002" green="0.50196078430000002" blue="0.50196078430000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@ -210,13 +217,6 @@
<outlet property="delegate" destination="-1" id="84"/>
</connections>
</textField>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="EMAIL" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Syg-X5-YFX" userLabel="emailLabel">
<rect key="frame" x="38" y="358" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
<color key="textColor" red="0.50196078430000002" green="0.50196078430000002" blue="0.50196078430000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" tag="130" contentMode="scaleToFill" enabled="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" adjustsImageWhenHighlighted="NO" lineBreakMode="middleTruncation" id="K99-0e-fHC" userLabel="createAccountButton" customClass="UIRoundBorderedButton">
<rect key="frame" x="38" y="418" width="299" height="71"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
@ -325,7 +325,7 @@
<nil key="highlightedColor"/>
<size key="shadowOffset" width="-1" height="-1"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="zRE-5W-snR" userLabel="usernameLabel">
<label opaque="NO" userInteractionEnabled="NO" tag="106" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="zRE-5W-snR" userLabel="usernameLabel">
<rect key="frame" x="38" y="165" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
@ -406,7 +406,7 @@
<nil key="highlightedColor"/>
<size key="shadowOffset" width="-1" height="-1"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="tAv-f7-kDI" userLabel="usernameLabel">
<label opaque="NO" userInteractionEnabled="NO" tag="106" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="tAv-f7-kDI" userLabel="usernameLabel">
<rect key="frame" x="38" y="165" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>
@ -525,7 +525,7 @@
<nil key="highlightedColor"/>
<size key="shadowOffset" width="-1" height="-1"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2tf-jf-LQL" userLabel="usernameLabel">
<label opaque="NO" userInteractionEnabled="NO" tag="106" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="USERNAME" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="2tf-jf-LQL" userLabel="usernameLabel">
<rect key="frame" x="38" y="165" width="299" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="13"/>

View file

@ -15,7 +15,8 @@ typedef BOOL (^UIDisplayError)(NSString *inputEntry);
@property(nonatomic) UILabel *errorLabel;
@property(nonatomic, readonly) UIDisplayError showErrorPredicate;
@property(nonatomic, readonly) NSString *lastText;
@property(atomic, readonly) BOOL canShowError;
// we should show error only when user finished editted the field at least once
@property(atomic) BOOL canShowError;
- (void)showError:(NSString *)msg when:(UIDisplayError)pred;
- (void)showError:(NSString *)msg;

View file

@ -11,8 +11,9 @@
<entry name="dial_escape_plus" overwrite="true">0</entry>
</section>
<section name="wizard">
<entry name="service_url" overwrite="true"></entry>
<section name="assistant">
<entry name="xmlrpc_url" overwrite="true"></entry>
<entry name="sharing_server" overwrite="true"></entry>
</section>
<section name="app">

View file

@ -16,8 +16,11 @@
<entry name="realm" overwrite="true">sip.linphone.org</entry>
</section>
<section name="wizard">
<entry name="service_url" overwrite="true">https://www.linphone.org/wizard.php</entry>
<section name="assistant">
<entry name="username_regex" overwrite="true">^[a-z0-9-_\\.]*$</entry>
<entry name="domain" overwrite="true">sip.linphone.org</entry>
<entry name="xmlrpc_url" overwrite="true">https://www.linphone.org/assistant.php</entry>
<entry name="sharing_server" overwrite="true">https://www.linphone.org:444/lft.php</entry>
</section>
<section name="app">

View file

@ -16,8 +16,11 @@
<entry name="realm" overwrite="true">sip.linphone.org</entry>
</section>
<section name="wizard">
<entry name="service_url" overwrite="true"></entry>
<section name="assistant">
<entry name="username_regex" overwrite="true">^[a-z0-9-_\\.]*$</entry>
<entry name="domain" overwrite="true">sip.linphone.org</entry>
<entry name="xmlrpc_url" overwrite="true">https://www.linphone.org/assistant.php</entry>
<entry name="sharing_server" overwrite="true">https://www.linphone.org:444/lft.php</entry>
</section>
<section name="app">

View file

@ -10,10 +10,10 @@
<entry name="publish" overwrite="true">0</entry>
<entry name="dial_escape_plus" overwrite="true">0</entry>
</section>
<section name="wizard">
<entry name="service_url" overwrite="true"></entry>
<section name="assistant">
<entry name="xmlrpc_url" overwrite="true"></entry>
<entry name="sharing_server" overwrite="true"></entry>
</section>
<section name="app">
<entry name="pushnotification_preference" overwrite="true">0</entry>
<entry name="ice_preference" overwrite="true"></entry>

View file

@ -63,15 +63,9 @@ enable_log_collect=0
reg_expires=600
[assistant]
service_url=https://www.linphone.org/assistant.php
domain=sip.linphone.org
proxy=sip.linphone.org
password_min_length=6
username_min_length=4
expires=1314000
push_notification=1
transport=tls
sharing_server=https://www.linphone.org:444/lft.php
ice=1
stun=stun.linphone.org

View file

@ -63,15 +63,9 @@ enable_log_collect=0
reg_expires=600
[assistant]
service_url=https://www.linphone.org/assistant.php
domain=sip.linphone.org
proxy=sip.linphone.org
password_min_length=6
username_min_length=4
expires=1314000
push_notification=1
transport=tls
sharing_server=https://www.linphone.org:444/lft.php
ice=1
stun=stun.linphone.org

@ -1 +1 @@
Subproject commit 53a0f0399996f3be03c31b2e6939f4297bec4d66
Subproject commit 8e3f9a337a7adae4e203653c8e1ff85989db9bda