diff --git a/Classes/Contact.m b/Classes/Contact.m index 6ed05fd87..453c914fb 100644 --- a/Classes/Contact.m +++ b/Classes/Contact.m @@ -296,13 +296,12 @@ NSString *valueRef = CFBridgingRelease(ABMultiValueCopyValueAtIndex(map, index)); char *normalizedPhone = linphone_proxy_config_normalize_phone_number( linphone_core_get_default_proxy_config(LC), valueRef.UTF8String); - NSString *name = [FastAddressBook - normalizeSipURI:normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : valueRef]; - if (valueRef != NULL) { - [_phoneNumbers addObject:name ?: [FastAddressBook localizedLabel:valueRef]]; - } - if (normalizedPhone) + if (normalizedPhone) { + valueRef = [NSString stringWithUTF8String:normalizedPhone]; ms_free(normalizedPhone); + } + + [_phoneNumbers addObject:valueRef]; } } CFRelease(map); @@ -323,7 +322,7 @@ NSString *value = (NSString *)(CFDictionaryGetValue(lDict, kABPersonInstantMessageUsernameKey)); CFRelease(lDict); if (value != NULL) { - [_sipAddresses addObject:[FastAddressBook normalizeSipURI:value] ?: value]; + [_sipAddresses addObject:value]; } } } @@ -440,7 +439,7 @@ MSList *numbers = linphone_friend_get_phone_numbers(_friend); while (numbers) { NSString *phone = [NSString stringWithUTF8String:numbers->data]; - [_phoneNumbers addObject:[FastAddressBook localizedLabel:phone]]; + [_phoneNumbers addObject:phone]; numbers = numbers->next; } } diff --git a/Classes/ContactDetailsTableView.m b/Classes/ContactDetailsTableView.m index fd0fba1fe..1a790e27b 100644 --- a/Classes/ContactDetailsTableView.m +++ b/Classes/ContactDetailsTableView.m @@ -22,7 +22,6 @@ #import "UIContactDetailsCell.h" #import "Utils.h" #import "OrderedDictionary.h" -#import "FastAddressBook.h" @implementation ContactDetailsTableView @@ -119,7 +118,7 @@ } - (BOOL)isValid { - return _contact.firstName.length + _contact.lastName.length > 0; + return ((NSString *)_contact.phoneNumbers[0]).length + ((NSString *)_contact.sipAddresses[0]).length > 0; } #pragma mark - UITableViewDataSource Functions @@ -185,7 +184,7 @@ [cell.editTextfield setKeyboardType:UIKeyboardTypeEmailAddress]; } - [cell setAddress:value isPhone:(indexPath.section == ContactSections_Number)]; + [cell setAddress:value]; return cell; } @@ -341,7 +340,7 @@ return YES; } -- (BOOL)textFieldShouldEndEditing:(UITextField *)textField { +- (void)textFieldUpdated:(UITextField *)textField { UIView *view = [textField superview]; while (view != nil && ![view isKindOfClass:[UIContactDetailsCell class]]) view = [view superview]; @@ -362,12 +361,15 @@ break; case ContactSections_Sip: [_contact setSipAddress:value atIndex:path.row]; + value = _contact.sipAddresses[path.row]; // in case of reformatting break; case ContactSections_Email: [_contact setEmail:value atIndex:path.row]; + value = _contact.emails[path.row]; // in case of reformatting break; case ContactSections_Number: [_contact setPhoneNumber:value atIndex:path.row]; + value = _contact.phoneNumbers[path.row]; // in case of reformatting break; case ContactSections_MAX: case ContactSections_None: @@ -376,7 +378,43 @@ cell.editTextfield.text = value; _editButton.enabled = [self isValid]; } - return TRUE; +} + +- (void)textFieldDidEndEditing:(UITextField *)textField { + [self textFieldUpdated:textField]; +} + +- (BOOL)textField:(UITextField *)textField + shouldChangeCharactersInRange:(NSRange)range + replacementString:(NSString *)string { +#if 0 + // every time we modify contact entry, we must check if we can enable "edit" button + UIView *view = [textField superview]; + while (view != nil && ![view isKindOfClass:[UIContactDetailsCell class]]) + view = [view superview]; + + UIContactDetailsCell *cell = (UIContactDetailsCell *)view; + // we cannot use indexPathForCell method here because if the cell is not visible anymore, + // it will return nil.. + NSIndexPath *path = cell.indexPath; + + _editButton.enabled = NO; + for (ContactSections s = ContactSections_Sip; !_editButton.enabled && s <= ContactSections_Number; s++) { + for (int i = 0; !_editButton.enabled && i < [self tableView:self.tableView numberOfRowsInSection:s]; i++) { + NSIndexPath *cellpath = [NSIndexPath indexPathForRow:i inSection:s]; + if ([cellpath isEqual:path]) { + _editButton.enabled = (textField.text.length > 0); + } else { + UIContactDetailsCell *cell = + (UIContactDetailsCell *)[self tableView:self.tableView cellForRowAtIndexPath:cellpath]; + _editButton.enabled = (cell.editTextfield.text.length > 0); + } + } + } +#else + [self textFieldUpdated:textField]; +#endif + return YES; } @end diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index b2623efbe..702864819 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -52,31 +52,17 @@ if (self.isEditing) { [self setEditing:FALSE]; } - if (_contact == NULL) { - return; - } - if (_contact != NULL) { - LOGI(@"Reset data to contact %p", _contact); - [_avatarImage setImage:[FastAddressBook imageForContact:_contact thumbnail:NO] - bordered:NO - withRoundedRadius:YES]; - [_tableController setContact:_contact]; - _emptyLabel.hidden = YES; - } else { - _emptyLabel.hidden = NO; - if (!IPAD) { - [PhoneMainView.instance popCurrentView]; - } - } + LOGI(@"Reset data to contact %p", _contact); + [_avatarImage setImage:[FastAddressBook imageForContact:_contact thumbnail:NO] bordered:NO withRoundedRadius:YES]; + [_tableController setContact:_contact]; + _emptyLabel.hidden = YES; } - (void)removeContact { - if (_contact != NULL) { - inhibUpdate = TRUE; - [[LinphoneManager.instance fastAddressBook] removeContact:_contact]; - inhibUpdate = FALSE; - } + inhibUpdate = TRUE; + [[LinphoneManager.instance fastAddressBook] removeContact:_contact]; + inhibUpdate = FALSE; [PhoneMainView.instance popCurrentView]; } @@ -262,8 +248,14 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - Action Functions - (IBAction)onCancelClick:(id)event { - [self setEditing:FALSE]; - [self resetData]; + if (_contact.phoneNumbers.count + _contact.sipAddresses.count > 0) { + [self setEditing:FALSE]; + [self resetData]; + _emptyLabel.hidden = NO; + if (!IPAD) { + [PhoneMainView.instance popCurrentView]; + } + } } - (IBAction)onBackClick:(id)event { diff --git a/Classes/KIF b/Classes/KIF index 927ff3b1c..26a6031f0 160000 --- a/Classes/KIF +++ b/Classes/KIF @@ -1 +1 @@ -Subproject commit 927ff3b1ceacf5b0ccc21ca116725eb355f132ae +Subproject commit 26a6031f057f68eafeea755a995ec310ac74b1c0 diff --git a/Classes/LinphoneUI/UIContactDetailsCell.h b/Classes/LinphoneUI/UIContactDetailsCell.h index 1db9398b5..e97b42529 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.h +++ b/Classes/LinphoneUI/UIContactDetailsCell.h @@ -36,7 +36,7 @@ @property(weak, nonatomic) IBOutlet UIIconButton *chatButton; - (id)initWithIdentifier:(NSString *)identifier; -- (void)setAddress:(NSString *)address isPhone:(BOOL)phone; +- (void)setAddress:(NSString *)address; - (void)hideDeleteButton:(BOOL)hidden; - (IBAction)onCallClick:(id)sender; diff --git a/Classes/LinphoneUI/UIContactDetailsCell.m b/Classes/LinphoneUI/UIContactDetailsCell.m index 14325e32c..bc1a2d4f2 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.m +++ b/Classes/LinphoneUI/UIContactDetailsCell.m @@ -40,18 +40,8 @@ #pragma mark - UITableViewCell Functions -- (void)setAddress:(NSString *)address isPhone:(BOOL)phone { - NSString *name = address; - if (phone) { - char *normalizedPhone = linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC), - address.UTF8String); - if (normalizedPhone) { - name = [NSString stringWithUTF8String:normalizedPhone]; - ms_free(normalizedPhone); - } - } - - _addressLabel.text = _editTextfield.text = name; +- (void)setAddress:(NSString *)address { + _addressLabel.text = _editTextfield.text = address; LinphoneAddress *addr = linphone_core_interpret_url(LC, _addressLabel.text.UTF8String); _chatButton.enabled = _callButton.enabled = (addr != NULL); diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 73b6fdeea..e8b429db9 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -133,10 +133,18 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info - (void)registerAddrsFor:(Contact *)contact { for (NSString *phone in contact.phoneNumbers) { - [_addressBookMap setObject:contact forKey:phone]; + char *normalizedPhone = + linphone_proxy_config_normalize_phone_number(linphone_core_get_default_proxy_config(LC), phone.UTF8String); + NSString *name = + [FastAddressBook normalizeSipURI:normalizedPhone ? [NSString stringWithUTF8String:normalizedPhone] : phone]; + if (phone != NULL) { + [_addressBookMap setObject:contact forKey:(name ?: [FastAddressBook localizedLabel:phone])]; + } + if (normalizedPhone) + ms_free(normalizedPhone); } for (NSString *sip in contact.sipAddresses) { - [_addressBookMap setObject:contact forKey:sip]; + [_addressBookMap setObject:contact forKey:([FastAddressBook normalizeSipURI:sip] ?: sip)]; } } diff --git a/TestsUI/ChatTester.m b/TestsUI/ChatTester.m index 79f65da29..b4dc0e018 100644 --- a/TestsUI/ChatTester.m +++ b/TestsUI/ChatTester.m @@ -94,7 +94,7 @@ [self startChatWith:[self me]]; [self uploadImageWithQuality:quality]; // wait for the upload to terminate... - for (int i = 0; i < 90; i++) { + for (int i = 0; i < 180; i++) { [tester waitForTimeInterval:1.f]; if (LinphoneManager.instance.fileTransferDelegates.count == 0) break; diff --git a/TestsUI/ContactsTester.m b/TestsUI/ContactsTester.m index e92f2e86b..d6fc89b38 100644 --- a/TestsUI/ContactsTester.m +++ b/TestsUI/ContactsTester.m @@ -49,7 +49,7 @@ - (void)setText:(NSString *)text forIndex:(NSInteger)idx inSection:(NSInteger)section { [tester tapRowAtIndexPath:[NSIndexPath indexPathForRow:idx inSection:section] inTableViewWithAccessibilityIdentifier:@"Contact table"]; - [tester enterTextIntoCurrentFirstResponder:text]; + [tester clearTextFromAndThenEnterTextIntoCurrentFirstResponder:text]; } - (void)addEntries:(NSArray *)numbers inSection:(NSInteger)section { @@ -118,7 +118,7 @@ - (void)testEditContact { NSString *contactName = [self getUUID]; - [self createContact:contactName lastName:@"dummy" phoneNumber:nil SIPAddress:nil]; + [self createContact:contactName lastName:@"dummy" phoneNumber:@"111" SIPAddress:nil]; /* Phone number */ NSArray *phones = @[ @"01234", @"56789" ];