Fix switch camera

Fix Contact views
This commit is contained in:
Yann Diorcet 2012-07-13 17:28:31 +02:00
parent ae4df954ca
commit 686dcd4059
4 changed files with 70 additions and 44 deletions

View file

@ -55,6 +55,7 @@
@synthesize contactID;
#pragma mark - Lifecycle Functions
- (void)initContactDetailsTableViewController {
@ -129,7 +130,7 @@
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
if(contactID == kABRecordInvalidID && contact != nil) {
if(contact != nil && ABRecordGetRecordID(contact) == kABRecordInvalidID) {
CFRelease(contact);
}
contact = nil;
@ -167,7 +168,8 @@
static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef info, void *context) {
ContactDetailsTableViewController* controller = (ContactDetailsTableViewController*)context;
if(!controller->inhibUpdate) {
//ABAddressBookRevert(addressBook);
if(!controller->inhibUpdate && ![controller isEditing]) {
[controller resetData];
}
}
@ -177,13 +179,21 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
return;
NSLog(@"Reset data to contact %p", contact);
ABAddressBookRevert(addressBook);
contact = ABAddressBookGetPersonWithRecordID(addressBook, ABRecordGetRecordID(contact));
if(contact == NULL) {
[[footerController removeButton] sendActionsForControlEvents: UIControlEventTouchUpInside];
return;
}
[self loadData];
}
- (void)removeContact {
if(contactID != kABRecordInvalidID) {
if(contact == NULL)
return;
// Remove contact from book
if(ABRecordGetRecordID(contact) != kABRecordInvalidID) {
NSError* error = NULL;
ABAddressBookRemoveRecord(addressBook, contact, (CFErrorRef*)&error);
if (error != NULL) {
@ -191,7 +201,7 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
} else {
NSLog(@"Remove contact %p: Success!", contact);
}
contactID = kABRecordInvalidID;
contact = NULL;
// Save address book
error = NULL;
@ -202,7 +212,6 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
NSLog(@"Save AddressBook: Fail(%@)", [error localizedDescription]);
} else {
NSLog(@"Save AddressBook: Success!");
contactID = ABRecordGetRecordID(contact);
}
}
}
@ -213,7 +222,7 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
// Add contact to book
NSError* error = NULL;
if(contactID == kABRecordInvalidID) {
if(ABRecordGetRecordID(contact) == kABRecordInvalidID) {
ABAddressBookAddRecord(addressBook, contact, (CFErrorRef*)&error);
if (error != NULL) {
NSLog(@"Add contact %p: Fail(%@)", contact, [error localizedDescription]);
@ -231,7 +240,6 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
NSLog(@"Save AddressBook: Fail(%@)", [error localizedDescription]);
} else {
NSLog(@"Save AddressBook: Success!");
contactID = ABRecordGetRecordID(contact);
}
}
@ -265,16 +273,16 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
NSMutableArray *subArray = [NSMutableArray array];
if(lMap) {
for(int i = 0; i < ABMultiValueGetCount(lMap); ++i) {
ABMultiValueIdentifier identifier = ABMultiValueGetIdentifierAtIndex(lMap, i);
CFDictionaryRef lDict = ABMultiValueCopyValueAtIndex(lMap, i);
if(CFDictionaryContainsKey(lDict, kABPersonInstantMessageServiceKey)) {
if(CFStringCompare((CFStringRef)CONTACT_SIP_FIELD, CFDictionaryGetValue(lDict, kABPersonInstantMessageServiceKey), kCFCompareCaseInsensitive) == 0) {
ABMultiValueIdentifier identifier = ABMultiValueGetIdentifierAtIndex(lMap, i);
Entry *entry = [[Entry alloc] initWithData:identifier];
[subArray addObject: entry];
[entry release];
}
CFRelease(lDict);
}
CFRelease(lDict);
}
CFRelease(lMap);
}
@ -301,7 +309,8 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
} else {
lMap = ABMultiValueCreateMutable(kABStringPropertyType);
}
ABMultiValueAddValueAndLabel(lMap, (CFStringRef)@"", (CFStringRef)[labelArray objectAtIndex:0], &identifier);
CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0];
ABMultiValueAddValueAndLabel(lMap, [value copy], label, &identifier);
Entry *entry = [[Entry alloc] initWithData:identifier];
[sectionArray addObject:entry];
[entry release];
@ -318,10 +327,11 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
} else {
lMap = ABMultiValueCreateMutable(kABDictionaryPropertyType);
}
CFStringRef keys[] = { kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey};
CFTypeRef values[] = { [value copy], CONTACT_SIP_FIELD };
CFStringRef keys[] = {kABPersonInstantMessageUsernameKey, kABPersonInstantMessageServiceKey};
CFTypeRef values[] = {[value copy], CONTACT_SIP_FIELD};
CFDictionaryRef lDict = CFDictionaryCreate(NULL, (const void **)&keys, (const void **)&values, 2, NULL, NULL);
ABMultiValueAddValueAndLabel(lMap, lDict, (CFStringRef)[labelArray objectAtIndex:0], &identifier);
CFStringRef label = (CFStringRef)[labelArray objectAtIndex:0];
ABMultiValueAddValueAndLabel(lMap, lDict, label, &identifier);
CFRelease(lDict);
Entry *entry = [[Entry alloc] initWithData:identifier];
[sectionArray addObject:entry];
@ -403,7 +413,6 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
- (void)newContact {
contact = ABPersonCreate();
self->contactID = kABRecordInvalidID;
[self loadData];
}
@ -447,25 +456,32 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty);
int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]);
CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(lMap, index);
label = [ContactDetailsTableViewController localizeLabel:(NSString*) labelRef];
CFRelease(labelRef);
if(labelRef != NULL) {
label = [ContactDetailsTableViewController localizeLabel:(NSString*) labelRef];
CFRelease(labelRef);
}
CFStringRef valueRef = ABMultiValueCopyValueAtIndex(lMap, index);
value = [ContactDetailsTableViewController localizeLabel:(NSString*) valueRef];
CFRelease(valueRef);
if(valueRef != NULL) {
value = [ContactDetailsTableViewController localizeLabel:(NSString*) valueRef];
CFRelease(valueRef);
}
CFRelease(lMap);
} else if([indexPath section] == 1) {
ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty);
int index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]);
CFStringRef labelRef = ABMultiValueCopyLabelAtIndex(lMap, index);
label = [ContactDetailsTableViewController localizeLabel:(NSString*) labelRef];
CFRelease(labelRef);
if(labelRef != NULL) {
label = [ContactDetailsTableViewController localizeLabel:(NSString*) labelRef];
CFRelease(labelRef);
}
CFDictionaryRef lDict = ABMultiValueCopyValueAtIndex(lMap, index);
CFStringRef valueRef = CFDictionaryGetValue(lDict, kABPersonInstantMessageUsernameKey);
value = [NSString stringWithString:(NSString*) valueRef];
if(valueRef != NULL) {
value = [NSString stringWithString:(NSString*) valueRef];
}
CFRelease(lDict);
CFRelease(lMap);
}
[cell.textLabel setText:label];
[cell.detailTextLabel setText:value];
[cell.detailTextField setText:value];
@ -543,11 +559,14 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleInsert) {
[self.tableView beginUpdates];
[self addEntry:self.tableView section:[indexPath section] animated:TRUE];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:FALSE];
// Don't save yet as the user must set a name.
[self.tableView endUpdates];
} else if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.tableView beginUpdates];
[self removeEntry:self.tableView path:indexPath animated:TRUE];
[self.tableView endUpdates];
}
}
@ -562,6 +581,9 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
[ContactDetailsTableViewController findAndResignFirstResponder:[self tableView]];
}
if(animated) {
[self.tableView beginUpdates];
}
if(editing) {
for (int section = 0; section <[self numberOfSectionsInTableView:[self tableView]]; ++section) {
[self addEntry:self.tableView section:section animated:animated];
@ -571,6 +593,9 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
[self removeEmptyEntry:self.tableView section:section animated:animated];
}
}
if(animated) {
[self.tableView endUpdates];
}
[headerController setEditing:editing animated:animated];
@ -660,7 +685,9 @@ static void sync_address_book (ABAddressBookRef addressBook, CFDictionaryRef inf
ABRecordSetValue(contact, kABPersonInstantMessageProperty, lMap, nil);
CFRelease(lMap);
}
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject: editingIndexPath] withRowAnimation:FALSE];
[self.tableView endUpdates];
[editingIndexPath release];
editingIndexPath = nil;
}

View file

@ -64,13 +64,15 @@
}
- (void)editContact:(ABRecordRef)acontact {
[self setContact:acontact];
self->contact = acontact;
[tableController setContactID:ABRecordGetRecordID(acontact)];
[self enableEdit:FALSE];
[[tableController tableView] reloadData];
}
- (void)editContact:(ABRecordRef)acontact address:(NSString*)address {
[self setContact:acontact];
self->contact = acontact;
[tableController setContactID:ABRecordGetRecordID(acontact)];
[tableController addSipField:address];
[self enableEdit:FALSE];
[[tableController tableView] reloadData];
@ -154,11 +156,7 @@
- (void)enableEdit:(BOOL)animated {
if(![tableController isEditing]) {
if(animated)
[[tableController tableView] beginUpdates];
[tableController setEditing:TRUE animated:animated];
if(animated)
[[tableController tableView] endUpdates];
}
[editButton setOn];
[cancelButton setHidden:FALSE];

View file

@ -2,10 +2,10 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11D50</string>
<string key="IBDocument.SystemVersion">11E53</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
<string key="IBDocument.AppKitVersion">1138.47</string>
<string key="IBDocument.HIToolboxVersion">569.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1181</string>
@ -158,7 +158,6 @@
<string key="NSFrame">{{0, 58}, {320, 402}}</string>
<reference key="NSSuperview" ref="812520855"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:10</string>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
@ -173,7 +172,6 @@
<double key="IBUIContentInset.left">0.0</double>
<double key="IBUIContentInset.right">0.0</double>
<bool key="IBUIAlwaysBounceVertical">YES</bool>
<bool key="IBUIPagingEnabled">YES</bool>
<bool key="IBUIShowsHorizontalScrollIndicator">NO</bool>
<int key="IBUISeparatorStyle">1</int>
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
@ -467,8 +465,8 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
<string key="contacts_add_default.png">{214, 117}</string>
<string key="contacts_add_over.png">{214, 117}</string>
<string key="contacts_add_default.png">{213, 117}</string>
<string key="contacts_add_over.png">{213, 117}</string>
<string key="contacts_all_default.png">{213, 117}</string>
<string key="contacts_all_selected.png">{213, 117}</string>
<string key="contacts_linphone_default.png">{213, 117}</string>

View file

@ -263,10 +263,7 @@ const NSInteger SECURE_BUTTON_TAG=5;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.3];
[[PhoneMainView instance] showTabBar: true];
if ([LinphoneManager instance].frontCamId !=nil ) {
// only show camera switch button if we have more than 1 camera
[videoCameraSwitch setAlpha:1.0];
}
[videoCameraSwitch setAlpha:1.0];
[UIView commitAnimations];
// hide controls in 5 sec
@ -325,8 +322,14 @@ const NSInteger SECURE_BUTTON_TAG=5;
[UIView commitAnimations];
}
videoView.alpha = 1.0;
videoView.hidden = FALSE;
[videoView setAlpha: 1.0];
[videoView setHidden: FALSE];
if ([LinphoneManager instance].frontCamId !=nil ) {
// only show camera switch button if we have more than 1 camera
[videoCameraSwitch setHidden:FALSE];
}
[videoCameraSwitch setAlpha:0.0];
[[PhoneMainView instance] fullScreen: true];
[[PhoneMainView instance] showTabBar: false];
@ -358,7 +361,7 @@ const NSInteger SECURE_BUTTON_TAG=5;
[videoGroup setAlpha:0.0];
[[PhoneMainView instance] showTabBar: true];
[callTableView setAlpha:1.0];
[videoCameraSwitch setAlpha:0.0];
[videoCameraSwitch setHidden:TRUE];
if(animation) {
[UIView commitAnimations];