Contacts detail rework suite

This commit is contained in:
Gautier Pelloux-Prayer 2015-10-20 10:23:45 +02:00
parent d0d88ddd73
commit d6e538a16c
3 changed files with 45 additions and 55 deletions

View file

@ -449,6 +449,9 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {
#pragma mark - Property Functions
- (void)setContact:(ABRecordRef)acontact {
if (acontact == contact)
return;
if (contact != nil && ABRecordGetRecordID(contact) == kABRecordInvalidID) {
CFRelease(contact);
}
@ -486,8 +489,7 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (contactSections[section] == ContactSections_First_Name ||
contactSections[section] == ContactSections_Last_Name) {
return 0;
// return (self.tableView.isEditing) ? 1 : 0 /*no first and last name when not editting */;
return (self.tableView.isEditing) ? 1 : 0 /*no first and last name when not editting */;
} else {
return [[self getSectionData:section] count];
}
@ -663,42 +665,11 @@ static const ContactSections_e contactSections[ContactSections_MAX] = {
#pragma mark - UITableViewDelegate Functions
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
bool_t showEmails = [[LinphoneManager instance] lpConfigBoolForKey:@"show_contacts_emails_preference"];
// Resign keyboard
[super setEditing:editing animated:animated];
if (!editing) {
[LinphoneUtils findAndResignFirstResponder:[self tableView]];
}
if (animated) {
[self.tableView beginUpdates];
}
if (editing) {
// add phony entries so that the user can add new data
for (int section = 0; section < [self numberOfSectionsInTableView:[self tableView]]; ++section) {
if (contactSections[section] == ContactSections_Number || contactSections[section] == ContactSections_Sip ||
(showEmails && contactSections[section] == ContactSections_Email)) {
[self addEntry:self.tableView section:section animated:animated];
}
}
} else {
for (int section = 0; section < [self numberOfSectionsInTableView:[self tableView]]; ++section) {
// remove phony entries that were not filled by the user
if (contactSections[section] == ContactSections_Number || contactSections[section] == ContactSections_Sip ||
(showEmails && contactSections[section] == ContactSections_Email)) {
[self removeEmptyEntry:self.tableView section:section animated:animated];
if ([[self getSectionData:section] count] == 0 && animated) { // the section is empty -> remove titles
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section]
withRowAnimation:UITableViewRowAnimationFade];
}
}
}
}
if (animated) {
[self.tableView endUpdates];
}
[super setEditing:editing animated:animated];
[self loadData];
if (contactDetailsDelegate != nil) {
[contactDetailsDelegate onModification:nil];
}

View file

@ -44,7 +44,9 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
#pragma mark -
- (void)resetData {
[self disableEdit:FALSE];
if (self.isEditing) {
[self setEditing:FALSE];
}
if (_contact == NULL) {
ABAddressBookRevert(addressBook);
return;
@ -117,7 +119,7 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
[_tableController setContact:_contact];
if (reload) {
[self enableEdit:FALSE];
[self setEditing:FALSE];
[[_tableController tableView] reloadData];
}
}
@ -137,7 +139,7 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info
}
linphone_address_destroy(linphoneAddress);
[self enableEdit:FALSE];
[self setEditing:FALSE];
[[_tableController tableView] reloadData];
}
@ -197,28 +199,44 @@ static UICompositeViewDescription *compositeDescription = nil;
#pragma mark -
- (void)enableEdit:(BOOL)animated {
if (!_tableController.isEditing) {
[_tableController setEditing:TRUE animated:animated];
}
[_editButton setOn];
[_cancelButton setHidden:FALSE];
[_backButton setHidden:TRUE];
- (void)setEditing:(BOOL)editing {
[self setEditing:editing animated:NO];
}
- (void)disableEdit:(BOOL)animated {
if (_tableController.isEditing) {
[_tableController setEditing:FALSE animated:animated];
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
if (animated) {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
}
[_tableController setEditing:editing animated:animated];
if (editing) {
[_editButton setOn];
} else {
[_editButton setOff];
}
_cancelButton.hidden = !editing;
_backButton.hidden = editing;
_nameLabel.hidden = editing;
CGRect frame = _tableController.tableView.frame;
frame.origin.y = _nameLabel.frame.origin.y;
if (editing) {
frame.origin.y += _nameLabel.frame.size.height;
}
_tableController.tableView.frame = frame;
if (animated) {
[UIView commitAnimations];
}
[_editButton setOff];
[_cancelButton setHidden:TRUE];
[_backButton setHidden:FALSE];
}
#pragma mark - Action Functions
- (IBAction)onCancelClick:(id)event {
[self disableEdit:TRUE];
[self setEditing:FALSE];
[self resetData];
}
@ -232,11 +250,11 @@ static UICompositeViewDescription *compositeDescription = nil;
- (IBAction)onEditClick:(id)event {
if (_tableController.isEditing) {
if ([_tableController isValid]) {
[self disableEdit:TRUE];
[self setEditing:FALSE];
[self saveData];
}
} else {
[self enableEdit:TRUE];
[self setEditing:TRUE];
}
}
@ -245,7 +263,7 @@ static UICompositeViewDescription *compositeDescription = nil;
[UIConfirmationDialog ShowWithMessage:msg
onCancelClick:nil
onConfirmationClick:^() {
[self disableEdit:FALSE];
[self setEditing:FALSE];
[self removeContact];
[PhoneMainView.instance popCurrentView];
}];

View file

@ -52,4 +52,5 @@
duration]];
return cell;
}
@end