diff --git a/Classes/ContactDetailsTableViewController.m b/Classes/ContactDetailsTableViewController.m index ecc513ff6..dd4c21b6f 100644 --- a/Classes/ContactDetailsTableViewController.m +++ b/Classes/ContactDetailsTableViewController.m @@ -55,6 +55,14 @@ @implementation ContactDetailsTableViewController +enum _ContactSections { + ContactSections_Number = 0, + ContactSections_Sip, + ContactSections_MAX +}; + +static const int contactSections[ContactSections_MAX] = {ContactSections_Number, ContactSections_Sip}; + @synthesize contact; #pragma mark - Lifecycle Functions @@ -129,6 +137,16 @@ return NO; } + +- (NSMutableArray*)getSectionData:(int)section { + if(contactSections[section] == ContactSections_Number) { + return [dataCache objectAtIndex:0]; + } else if(contactSections[section] == ContactSections_Sip) { + return [dataCache objectAtIndex:1]; + } + return nil; +} + + (NSString*)localizeLabel:(NSString*)str { CFStringRef lLocalizedLabel = ABAddressBookCopyLocalizedLabel((CFStringRef) str); NSString * retStr = [NSString stringWithString:(NSString*) lLocalizedLabel]; @@ -203,11 +221,11 @@ } - (void)addEntry:(UITableView*)tableview section:(NSInteger)section animated:(BOOL)animated value:(NSString *)value{ - NSMutableArray *sectionArray = [dataCache objectAtIndex:section]; + NSMutableArray *sectionArray = [self getSectionData:section]; NSUInteger count = [sectionArray count]; NSError* error = NULL; bool added = TRUE; - if(section == 0) { + if(contactSections[section] == ContactSections_Number) { ABMultiValueIdentifier identifier; ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); ABMutableMultiValueRef lMap; @@ -231,7 +249,7 @@ [LinphoneLogger log:LinphoneLoggerLog format:@"Can't add entry: %@", [error localizedDescription]]; } CFRelease(lMap); - } else if(section == 1) { + } else if(contactSections[section] == ContactSections_Sip) { ABMultiValueIdentifier identifier; ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); ABMutableMultiValueRef lMap; @@ -271,11 +289,11 @@ } - (void)removeEmptyEntry:(UITableView*)tableview section:(NSInteger)section animated:(BOOL)animated { - NSMutableArray *sectionDict = [dataCache objectAtIndex: section]; + NSMutableArray *sectionDict = [self getSectionData:section]; int row = [sectionDict count] - 1; if(row >= 0) { Entry *entry = [sectionDict objectAtIndex:row]; - if(section == 0) { + if(contactSections[section] == ContactSections_Number) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFStringRef valueRef = ABMultiValueCopyValueAtIndex(lMap, index); @@ -284,7 +302,7 @@ } CFRelease(valueRef); CFRelease(lMap); - } else if(section == 1) { + } else if(contactSections[section] == ContactSections_Sip) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFDictionaryRef lDict = ABMultiValueCopyValueAtIndex(lMap, index); @@ -299,9 +317,9 @@ } - (void)removeEntry:(UITableView*)tableview path:(NSIndexPath*)indexPath animated:(BOOL)animated { - NSMutableArray *sectionArray = [dataCache objectAtIndex:[indexPath section]]; + NSMutableArray *sectionArray = [self getSectionData:[indexPath section]]; Entry *entry = [sectionArray objectAtIndex:[indexPath row]]; - if([indexPath section] == 0) { + if(contactSections[[indexPath section]] == ContactSections_Number) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); @@ -309,7 +327,7 @@ ABMultiValueRemoveValueAndLabelAtIndex(lMap, index); ABRecordSetValue(contact, kABPersonPhoneProperty, lMap, nil); CFRelease(lMap); - } else if([indexPath section] == 1) { + } else if(contactSections[[indexPath section]] == ContactSections_Sip) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); @@ -338,18 +356,20 @@ } - (void)addSipField:(NSString*)address { - [self addEntry:[self tableView] section:1 animated:FALSE value:address]; + int i = 0; + while(i < ContactSections_MAX && contactSections[i] != ContactSections_Sip) ++i; + [self addEntry:[self tableView] section:i animated:FALSE value:address]; } #pragma mark - UITableViewDataSource Functions - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return [dataCache count]; + return ContactSections_MAX; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return [[dataCache objectAtIndex:section] count]; + return [[self getSectionData:section] count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -367,13 +387,13 @@ [selectedBackgroundView setBackgroundColor:LINPHONE_TABLE_CELL_BACKGROUND_COLOR]; } - NSMutableArray *sectionDict = [dataCache objectAtIndex:[indexPath section]]; + NSMutableArray *sectionDict = [self getSectionData:[indexPath section]]; Entry *entry = [sectionDict objectAtIndex:[indexPath row]]; NSString *value = @""; NSString *label = @""; - if([indexPath section] == 0) { + if(contactSections[[indexPath section]] == ContactSections_Number) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(lMap, index); @@ -387,7 +407,7 @@ CFRelease(valueRef); } CFRelease(lMap); - } else if([indexPath section] == 1) { + } else if(contactSections[[indexPath section]] == ContactSections_Sip) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(lMap, index); @@ -406,10 +426,10 @@ [cell.textLabel setText:label]; [cell.detailTextLabel setText:value]; [cell.detailTextField setText:value]; - if ([indexPath section] == 0) { + if (contactSections[[indexPath section]] == ContactSections_Number) { [cell.detailTextField setKeyboardType:UIKeyboardTypePhonePad]; [cell.detailTextField setPlaceholder:NSLocalizedString(@"Phone number", nil)]; - } else { + } else if(contactSections[[indexPath section]] == ContactSections_Sip){ [cell.detailTextField setKeyboardType:UIKeyboardTypeASCIICapable]; [cell.detailTextField setPlaceholder:NSLocalizedString(@"SIP address", nil)]; } @@ -418,11 +438,11 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:NO]; - NSMutableArray *sectionDict = [dataCache objectAtIndex:[indexPath section]]; + NSMutableArray *sectionDict = [self getSectionData:[indexPath section]]; Entry *entry = [sectionDict objectAtIndex:[indexPath row]]; if (![self isEditing]) { NSString *dest; - if([indexPath section] == 0) { + if(contactSections[[indexPath section]] == ContactSections_Number) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFStringRef valueRef = ABMultiValueCopyValueAtIndex(lMap, index); @@ -431,7 +451,7 @@ CFRelease(valueRef); } CFRelease(lMap); - } else if([indexPath section] == 1) { + } else if(contactSections[[indexPath section]] == ContactSections_Sip) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFDictionaryRef lDict = ABMultiValueCopyValueAtIndex(lMap, index); @@ -459,7 +479,7 @@ } } else { NSString *key = nil; - if([indexPath section] == 0) { + if(contactSections[[indexPath section]] == ContactSections_Number) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(lMap, index); @@ -468,7 +488,7 @@ CFRelease(labelRef); } CFRelease(lMap); - } else if([indexPath section] == 1) { + } else if(contactSections[[indexPath section]] == ContactSections_Sip) { ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]); CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(lMap, index); @@ -538,7 +558,7 @@ } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { - int last_index = [[dataCache objectAtIndex:[indexPath section]] count] - 1; + int last_index = [[self getSectionData:[indexPath section]] count] - 1; if (indexPath.row == last_index) { return UITableViewCellEditingStyleInsert; } @@ -557,7 +577,7 @@ } - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { - if(section != 0) { + if(section == (ContactSections_MAX - 1)) { UIView *footerView = [footerController view]; return footerView; } else { @@ -566,11 +586,12 @@ } - (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { - if(section == 0) { - return NSLocalizedString(@"Phone number", nil); - } else { + if(contactSections[section] == ContactSections_Number) { + return NSLocalizedString(@"Phone numbers", nil); + } else if(contactSections[section] == ContactSections_Sip) { return NSLocalizedString(@"SIP", nil); } + return nil; } - (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section { @@ -582,7 +603,7 @@ return [UIContactDetailsHeader height:[self isEditing]]; } else { // Hide section if nothing in it - if([[dataCache objectAtIndex:section] count] > 0) + if([[self getSectionData:section] count] > 0) return 22; else return 0.000001f; // Hack UITableView = 0 @@ -593,7 +614,7 @@ if(section != 0) { return [UIContactDetailsFooter height:[self isEditing]]; } - return 0.000001f; // Hack UITableView = 0 + return 10.0f; } @@ -601,9 +622,9 @@ - (void)changeContactDetailsLabel:(NSString *)value { if(value != nil) { - NSMutableArray *sectionDict = [dataCache objectAtIndex:[editingIndexPath section]]; + NSMutableArray *sectionDict = [self getSectionData:[editingIndexPath section]]; Entry *entry = [sectionDict objectAtIndex:[editingIndexPath row]]; - if([editingIndexPath section] == 0) { + if(contactSections[[editingIndexPath section]] == ContactSections_Number) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); @@ -611,7 +632,7 @@ ABMultiValueReplaceLabelAtIndex(lMap, (CFStringRef)(value), index); ABRecordSetValue(contact, kABPersonPhoneProperty, lMap, nil); CFRelease(lMap); - } else if([editingIndexPath section] == 1) { + } else if(contactSections[[editingIndexPath section]] == ContactSections_Sip) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); @@ -643,10 +664,10 @@ if(view != nil) { UIEditableTableViewCell *cell = (UIEditableTableViewCell*)view; NSIndexPath *path = [self.tableView indexPathForCell:cell]; - NSMutableArray *sectionDict = [dataCache objectAtIndex:[path section]]; + NSMutableArray *sectionDict = [self getSectionData:[path section]]; Entry *entry = [sectionDict objectAtIndex:[path row]]; NSString *value = [textField text]; - if([path section] == 0) { + if(contactSections[[path section]] == ContactSections_Number) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonPhoneProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); @@ -654,7 +675,7 @@ ABMultiValueReplaceValueAtIndex(lMap, (CFStringRef)value, index); ABRecordSetValue(contact, kABPersonPhoneProperty, lMap, nil); CFRelease(lMap); - } else if([path section] == 1) { + } else if(contactSections[[path section]] == ContactSections_Sip) { ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty); ABMutableMultiValueRef lMap = ABMultiValueCreateMutableCopy(lcMap); CFRelease(lcMap); diff --git a/Classes/LinphoneUI/UIMainBar.m b/Classes/LinphoneUI/UIMainBar.m index 4c5fba903..631d465cd 100644 --- a/Classes/LinphoneUI/UIMainBar.m +++ b/Classes/LinphoneUI/UIMainBar.m @@ -91,12 +91,32 @@ } - (void)viewDidLoad { - [super viewDidLoad]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; + + // Set selected+over background: IB lack ! + [historyButton setImage:[UIImage imageNamed:@"history_selected.png"] + forState:(UIControlStateHighlighted | UIControlStateSelected)]; + + // Set selected+over background: IB lack ! + [contactsButton setImage:[UIImage imageNamed:@"contacts_selected.png"] + forState:(UIControlStateHighlighted | UIControlStateSelected)]; + + // Set selected+over background: IB lack ! + [dialerButton setImage:[UIImage imageNamed:@"dialer_selected.png"] + forState:(UIControlStateHighlighted | UIControlStateSelected)]; + + // Set selected+over background: IB lack ! + [settingsButton setImage:[UIImage imageNamed:@"settings_selected.png"] + forState:(UIControlStateHighlighted | UIControlStateSelected)]; + + // Set selected+over background: IB lack ! + [chatButton setImage:[UIImage imageNamed:@"chat_selected.png"] + forState:(UIControlStateHighlighted | UIControlStateSelected)]; + + [super viewDidLoad]; // Have to be after due to TPMultiLayoutViewController } - (void)viewDidUnload { diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings index 8c5c5114b..5077d42c4 100644 Binary files a/Resources/en.lproj/Localizable.strings and b/Resources/en.lproj/Localizable.strings differ