From ddaa3cef89aed8d8c20d28a56db23852d75235d1 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 23 Nov 2015 15:31:28 +0100 Subject: [PATCH] Settings&Assistant: rework proxies management to avoid auth popup as much as possible --- Classes/AssistantView.m | 51 ++++--- Classes/Base.lproj/AssistantViewScreens.xib | 86 ++++++++++-- Classes/FirstLoginView.m | 1 + Classes/LaunchScreen.xib | 2 +- Classes/LinphoneCoreSettingsStore.m | 61 ++++----- Classes/LinphoneManager.m | 25 ++-- Classes/LinphoneUI/Base.lproj/TabBarView.xib | 125 +++++++++++++++++- .../LinphoneUI/Base.lproj/UICompositeView.xib | 2 +- Classes/LinphoneUI/StatusBarView.m | 11 +- Classes/SettingsView.m | 2 + Classes/SideMenuView.m | 2 +- Settings/InAppSettings.bundle/Account.plist | 30 ++++- 12 files changed, 310 insertions(+), 88 deletions(-) diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index b730aaa5b..7748df265 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -36,6 +36,7 @@ typedef enum _ViewElement { ViewElement_Email = 103, ViewElement_Domain = 104, ViewElement_URL = 105, + ViewElement_DisplayName = 106, ViewElement_TextFieldCount = 6, ViewElement_Transport = 110, ViewElement_Username_Label = 120, @@ -212,25 +213,28 @@ static UICompositeViewDescription *compositeDescription = nil; return nil; } -- (BOOL)addProxyConfig:(LinphoneProxyConfig *)proxy { +- (void)configureProxyConfig { LinphoneCore *lc = [LinphoneManager getLc]; LinphoneManager *lm = [LinphoneManager instance]; - if (new_config != NULL && proxy != new_config) { + // remove previous proxy config, if any + if (new_config != NULL) { const LinphoneAuthInfo *auth = linphone_proxy_config_find_auth_info(new_config); linphone_core_remove_proxy_config(lc, new_config); if (auth) { linphone_core_remove_auth_info(lc, auth); } } - new_config = proxy; - [lm configurePushTokenForProxyConfig:proxy]; - linphone_core_set_default_proxy_config(lc, proxy); - // reload address book to prepend proxy config domain to contacts' phone number - // todo: STOP doing that! - [[[LinphoneManager instance] fastAddressBook] reload]; - return TRUE; + new_config = linphone_account_creator_configure(account_creator); + + if (new_config) { + [lm configurePushTokenForProxyConfig:new_config]; + linphone_core_set_default_proxy_config(lc, new_config); + // reload address book to prepend proxy config domain to contacts' phone number + // todo: STOP doing that! + [[[LinphoneManager instance] fastAddressBook] reload]; + } } #pragma mark - UI update @@ -300,6 +304,15 @@ static UICompositeViewDescription *compositeDescription = nil; [view setFrame:[_contentView bounds]]; [_contentView setContentSize:[view bounds].size]; + // Resize next button to fix text length + UIButton *button = [self findButton:ViewElement_NextButton]; + CGSize size = [button.titleLabel.text sizeWithFont:button.titleLabel.font]; + size.width += 60; + CGRect frame = button.frame; + frame.origin.x += (button.frame.size.width - size.width) / 2; + frame.size.width = size.width; + [button setFrame:frame]; + [self prepareErrorLabels]; } @@ -462,6 +475,15 @@ static UICompositeViewDescription *compositeDescription = nil; return TRUE; }]; + UIAssistantTextField *displayName = [self findTextField:ViewElement_DisplayName]; + [displayName showError:[AssistantView errorForStatus:LinphoneAccountCreatorDisplayNameInvalid] + when:^BOOL(NSString *inputEntry) { + LinphoneAccountCreatorStatus s = + linphone_account_creator_set_display_name(account_creator, inputEntry.UTF8String); + displayName.errorLabel.text = [AssistantView errorForStatus:s]; + return s != LinphoneAccountCreatorOK; + }]; + [self shouldEnableNextButton]; } @@ -504,7 +526,6 @@ static UICompositeViewDescription *compositeDescription = nil; cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; - linphone_core_remove_proxy_config([LinphoneManager getLc], new_config); break; } case LinphoneRegistrationProgress: { @@ -580,7 +601,7 @@ void assistant_validation_tested(LinphoneAccountCreator *creator, LinphoneAccoun AssistantView *thiz = (__bridge AssistantView *)(linphone_account_creator_get_user_data(creator)); thiz.waitView.hidden = YES; if (status == LinphoneAccountCreatorAccountValidated) { - [thiz addProxyConfig:linphone_account_creator_configure(creator)]; + [thiz configureProxyConfig]; } else if (status == LinphoneAccountCreatorAccountNotValidated) { DTAlertView *alert = [[DTAlertView alloc] initWithTitle:NSLocalizedString(@"Account validation failed", nil) @@ -591,7 +612,7 @@ void assistant_validation_tested(LinphoneAccountCreator *creator, LinphoneAccoun [alert addCancelButtonWithTitle:NSLocalizedString(@"Back", nil) block:nil]; [alert addButtonWithTitle:NSLocalizedString(@"Skip verification", nil) block:^{ - [thiz addProxyConfig:linphone_account_creator_configure(creator)]; + [thiz configureProxyConfig]; [PhoneMainView.instance changeCurrentView:DialerView.compositeViewDescription]; }]; [alert show]; @@ -660,18 +681,18 @@ void assistant_validation_tested(LinphoneAccountCreator *creator, LinphoneAccoun - (IBAction)onLinphoneLoginClick:(id)sender { _waitView.hidden = NO; - [self addProxyConfig:linphone_account_creator_configure(account_creator)]; + [self configureProxyConfig]; } - (IBAction)onLoginClick:(id)sender { _waitView.hidden = NO; - [self addProxyConfig:linphone_account_creator_configure(account_creator)]; + [self configureProxyConfig]; } - (IBAction)onRemoteProvisioningLoginClick:(id)sender { _waitView.hidden = NO; [[LinphoneManager instance] lpConfigSetInt:1 forKey:@"transient_provisioning" forSection:@"misc"]; - [self addProxyConfig:linphone_account_creator_configure(account_creator)]; + [self configureProxyConfig]; } - (IBAction)onRemoteProvisioningDownloadClick:(id)sender { diff --git a/Classes/Base.lproj/AssistantViewScreens.xib b/Classes/Base.lproj/AssistantViewScreens.xib index f89624285..7215ccf07 100644 --- a/Classes/Base.lproj/AssistantViewScreens.xib +++ b/Classes/Base.lproj/AssistantViewScreens.xib @@ -46,7 +46,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/LinphoneUI/Base.lproj/UICompositeView.xib b/Classes/LinphoneUI/Base.lproj/UICompositeView.xib index fe0dcf88e..b6eac808b 100644 --- a/Classes/LinphoneUI/Base.lproj/UICompositeView.xib +++ b/Classes/LinphoneUI/Base.lproj/UICompositeView.xib @@ -72,7 +72,7 @@ - + diff --git a/Classes/LinphoneUI/StatusBarView.m b/Classes/LinphoneUI/StatusBarView.m index 32ecb5e26..46a044472 100644 --- a/Classes/LinphoneUI/StatusBarView.m +++ b/Classes/LinphoneUI/StatusBarView.m @@ -181,10 +181,15 @@ message = NSLocalizedString(@"Fetching remote configuration", nil); } else if (config == NULL) { state = LinphoneRegistrationNone; - if (linphone_core_is_network_reachable([LinphoneManager getLc])) - message = NSLocalizedString(@"No account configured", nil); - else + if (linphone_core_is_network_reachable([LinphoneManager getLc])) { + if (linphone_core_get_proxy_config_list(lc) != NULL) { + message = NSLocalizedString(@"No default account", nil); + } else { + message = NSLocalizedString(@"No account configured", nil); + } + } else { message = NSLocalizedString(@"Network down", nil); + } } else { state = linphone_proxy_config_get_state(config); diff --git a/Classes/SettingsView.m b/Classes/SettingsView.m index d7946b495..50f79a070 100644 --- a/Classes/SettingsView.m +++ b/Classes/SettingsView.m @@ -434,6 +434,7 @@ static UICompositeViewDescription *compositeDescription = nil; } else if ([@"advanced_account_preference" compare:notif.object] == NSOrderedSame) { removeFromHiddenKeys = [[notif.userInfo objectForKey:@"advanced_account_preference"] boolValue]; [keys addObject:@"userid_preference"]; + [keys addObject:@"display_name_preference"]; [keys addObject:@"proxy_preference"]; [keys addObject:@"outbound_proxy_preference"]; [keys addObject:@"avpf_preference"]; @@ -624,6 +625,7 @@ static UICompositeViewDescription *compositeDescription = nil; if (![lm lpConfigBoolForKey:@"advanced_account_preference"]) { [hiddenKeys addObject:@"userid_preference"]; + [hiddenKeys addObject:@"display_name_preference"]; [hiddenKeys addObject:@"proxy_preference"]; [hiddenKeys addObject:@"outbound_proxy_preference"]; [hiddenKeys addObject:@"avpf_preference"]; diff --git a/Classes/SideMenuView.m b/Classes/SideMenuView.m index c841b351d..bee769e69 100644 --- a/Classes/SideMenuView.m +++ b/Classes/SideMenuView.m @@ -18,7 +18,7 @@ if (default_proxy != NULL) { const LinphoneAddress *addr = linphone_proxy_config_get_identity_address(default_proxy); [ContactDisplay setDisplayNameLabel:_nameLabel forAddress:addr]; - char *as_string = linphone_address_as_string(addr); + char *as_string = linphone_address_as_string_uri_only(addr); [_addressButton setTitle:[NSString stringWithUTF8String:as_string] forState:UIControlStateNormal]; ms_free(as_string); [_addressButton setImage:[StatusBarView imageForState:linphone_proxy_config_get_state(default_proxy)] diff --git a/Settings/InAppSettings.bundle/Account.plist b/Settings/InAppSettings.bundle/Account.plist index 57afc23f3..53035045e 100644 --- a/Settings/InAppSettings.bundle/Account.plist +++ b/Settings/InAppSettings.bundle/Account.plist @@ -12,6 +12,16 @@ Type IASKButtonSpecifier + + Type + PSToggleSwitchSpecifier + Title + Default account + Key + is_default_preference + DefaultValue + + AutocapitalizationType None @@ -26,7 +36,25 @@ KeyboardType Alphabet Title - User name + Username + Type + PSTextFieldSpecifier + + + AutocapitalizationType + None + AutocorrectionType + No + DefaultValue + + IsSecure + + Key + display_name_preference + KeyboardType + Alphabet + Title + Display name Type PSTextFieldSpecifier