Add the ability to use the System contact view, which is the ABPeoplePicker.

This has the drawback that we can't (yet?) add contacts anymore, but it allows for remote directories (LDAP, exchange) searches.
This commit is contained in:
Guillaume BIENKOWSKI 2014-02-13 11:11:31 +01:00
parent fd985d9ef3
commit d0b5b8f394
5 changed files with 79 additions and 41 deletions

View file

@ -11,8 +11,7 @@
<outlet property="allButton" destination="4" id="27"/>
<outlet property="backButton" destination="87" id="90"/>
<outlet property="linphoneButton" destination="5" id="31"/>
<outlet property="tableController" destination="76" id="83"/>
<outlet property="tableView" destination="69" id="84"/>
<outlet property="toolBar" destination="3" id="n95-dF-EoN"/>
<outlet property="view" destination="2" id="16"/>
</connections>
</placeholder>
@ -113,32 +112,9 @@
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="69" userLabel="tableView">
<rect key="frame" x="0.0" y="44" width="320" height="416"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<inset key="contentInset" minX="0.0" minY="0.0" maxX="0.0" maxY="10"/>
<inset key="scrollIndicatorInsets" minX="0.0" minY="0.0" maxX="0.0" maxY="10"/>
<color key="separatorColor" red="0.7254902124" green="0.76862746479999999" blue="0.79607844350000001" alpha="1" colorSpace="deviceRGB"/>
<connections>
<outlet property="dataSource" destination="76" id="81"/>
<outlet property="delegate" destination="76" id="82"/>
</connections>
</tableView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<tableViewController autoresizesArchivedViewToFullSize="NO" id="76" userLabel="tableController" customClass="ContactsTableViewController">
<extendedEdge key="edgesForExtendedLayout"/>
<simulatedStatusBarMetrics key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics"/>
<nil key="simulatedDestinationMetrics"/>
<connections>
<outlet property="view" destination="69" id="80"/>
</connections>
</tableViewController>
</objects>
<resources>
<image name="contacts_add_default.png" width="214" height="88"/>

View file

@ -18,6 +18,7 @@
*/
#import <UIKit/UIKit.h>
#import <AddressBookUI/ABPeoplePickerNavigationController.h>
#import "UICompositeViewController.h"
#import "ContactsTableViewController.h"
@ -44,11 +45,14 @@ typedef enum _ContactSelectionMode {
@end
@interface ContactsViewController : UIViewController<UICompositeViewDelegate> {
@interface ContactsViewController : UIViewController<UICompositeViewDelegate,ABPeoplePickerNavigationControllerDelegate> {
BOOL use_systemView;
}
@property (nonatomic, retain) IBOutlet ContactsTableViewController* tableController;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain) IBOutlet UINavigationController* sysViewController;
@property (retain, nonatomic) IBOutlet UIView *toolBar;
@property (nonatomic, retain) IBOutlet UIButton* allButton;
@property (nonatomic, retain) IBOutlet UIButton* linphoneButton;
@property (nonatomic, retain) IBOutlet UIButton *backButton;

View file

@ -76,10 +76,13 @@ static BOOL sEmailFilter = FALSE;
@synthesize tableController;
@synthesize tableView;
@synthesize sysViewController;
@synthesize allButton;
@synthesize linphoneButton;
@synthesize backButton;
@synthesize addButton;
@synthesize toolBar;
typedef enum _HistoryView {
History_All,
@ -130,25 +133,43 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[tableController viewWillDisappear:animated];
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[tableController viewWillAppear:animated];
}
[self update];
BOOL use_system = [[LinphoneManager instance] lpConfigBoolForKey:@"use_system_contacts"];
if( use_system && !self.sysViewController){// use system contacts
ABPeoplePickerNavigationController* picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
picker.view.frame = self.view.frame;
[self.view addSubview:picker.view];
self.sysViewController = picker;
} else if( !use_system && !self.tableController ){
CGRect subViewFrame= self.view.frame;
// let the toolBar be visible
subViewFrame.origin.y += self.toolBar.frame.size.height;
self.tableController = [[ContactsTableViewController alloc] init];
self.tableView = [[UITableView alloc] init];
self.tableController.view = self.tableView;
self.tableView.frame = subViewFrame;
self.tableView.dataSource = self.tableController;
self.tableView.delegate = self.tableController;
[self.view addSubview:tableView];
[self update];
}
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[tableController viewDidAppear:animated];
}
if(![FastAddressBook isAuthorized]) {
UIAlertView* error = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Address book",nil)
message:NSLocalizedString(@"You must authorize the application to have access to address book.\n"
@ -164,9 +185,6 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
if ([[UIDevice currentDevice].systemVersion doubleValue] < 5.0) {
[tableController viewDidDisappear:animated];
}
}
- (void)viewDidLoad {
@ -205,10 +223,10 @@ static UICompositeViewDescription *compositeDescription = nil;
} else {
allButton.selected = FALSE;
}
if(view == History_Linphone) {
[ContactSelection setSipFilter:[LinphoneManager instance].contactFilter];
[ContactSelection setEmailFilter:FALSE];
[ContactSelection setEmailFilter:FALSE];
[tableController loadData];
linphoneButton.selected = TRUE;
} else {
@ -265,4 +283,42 @@ static UICompositeViewDescription *compositeDescription = nil;
[[PhoneMainView instance] popCurrentView];
}
#pragma mark - ABPeoplePickerDelegate
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[[PhoneMainView instance] popCurrentView];
return;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person {
return true;
}
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier {
CFTypeRef multiValue = ABRecordCopyValue(person, property);
CFIndex valueIdx = ABMultiValueGetIndexForIdentifier(multiValue,identifier);
NSString *phoneNumber = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, valueIdx);
// Go to dialer view
DialerViewController *controller = DYNAMIC_CAST([[PhoneMainView instance] changeCurrentView:[DialerViewController compositeViewDescription]], DialerViewController);
if(controller != nil) {
[controller call:phoneNumber displayName:(NSString*)ABRecordCopyCompositeName(person)];
}
[phoneNumber release];
CFRelease(multiValue);
return false;
}
- (void)viewDidUnload {
[self setToolBar:nil];
[super viewDidUnload];
}
@end

View file

@ -26,6 +26,7 @@ upload_bw=380
rotation_preference=auto
animations_preference=1
edge_opt_preference=0
use_system_contacts=0
[default_values]
reg_expires=600

View file

@ -26,6 +26,7 @@ upload_bw=512
rotation_preference=auto
animations_preference=1
edge_opt_preference=0
use_system_contacts=0
[default_values]
reg_expires=600