Add Organization label to contacts

This commit is contained in:
QuentinArguillere 2023-04-17 15:55:12 +02:00
parent 2936ac9801
commit 7864e48a45
14 changed files with 114 additions and 71 deletions

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21678"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
@ -19,6 +19,7 @@
<outlet property="emptyLabel" destination="Mdj-Pz-nu4" id="ijc-2c-waE"/>
<outlet property="landscapeView" destination="lgD-Mw-h57" id="DTS-80-rMM"/>
<outlet property="nameLabel" destination="moZ-Bg-zcv" id="Lt9-h0-2o1"/>
<outlet property="organizationLabel" destination="pAA-jk-E4s" id="J0M-Ms-5dp"/>
<outlet property="portraitView" destination="1" id="k69-5P-ieM"/>
<outlet property="tableController" destination="20" id="27"/>
<outlet property="view" destination="1" id="3"/>
@ -122,8 +123,15 @@
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Organization" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="pAA-jk-E4s" userLabel="organizationLabel">
<rect key="frame" x="0.0" y="148" width="393" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="22"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<tableView clipsSubviews="YES" tag="10" contentMode="scaleToFill" fixedFrame="YES" directionalLockEnabled="YES" alwaysBounceVertical="YES" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" style="plain" allowsSelection="NO" allowsSelectionDuringEditing="YES" rowHeight="44" sectionHeaderHeight="1" sectionFooterHeight="1" translatesAutoresizingMaskIntoConstraints="NO" id="19" userLabel="tableView">
<rect key="frame" x="0.0" y="156" width="393" height="522"/>
<rect key="frame" x="0.0" y="176" width="393" height="502"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<inset key="scrollIndicatorInsets" minX="0.0" minY="0.0" maxX="0.0" maxY="10"/>

View file

@ -31,6 +31,7 @@
@property(nonatomic, retain) NSString *identifier;
@property(nonatomic, retain) NSString *firstName;
@property(nonatomic, retain) NSString *lastName;
@property(nonatomic, retain) NSString *organizationName;
@property(nonatomic, retain) NSString *displayName;
@property(nonatomic, strong) NSMutableArray *sipAddresses;
@property(nonatomic, strong) NSMutableArray *emails;

View file

@ -44,6 +44,7 @@
_identifier = _person.identifier;
_firstName = _person.givenName;
_lastName = _person.familyName;
_organizationName = _person.organizationName;
_displayName = [NSString stringWithFormat:@"%@ %@", _firstName, _lastName];
for (CNLabeledValue<CNPhoneNumber *> *phoneNumber in _person.phoneNumbers) {
[_phones addObject:phoneNumber.value.stringValue];
@ -84,6 +85,9 @@
for (NSString *phone in _phones) {
linphone_friend_add_phone_number(_friend, phone.UTF8String);
}
if (_organizationName) {
linphone_friend_set_organization(_friend, [_organizationName UTF8String]);
}
if (_friend) {
linphone_friend_enable_subscribes(_friend, FALSE);
linphone_friend_set_inc_subscribe_policy(_friend, LinphoneSPDeny);

View file

@ -27,6 +27,7 @@ typedef enum _ContactSections {
ContactSections_None = 0, // first section is empty because we cannot set header for first section
ContactSections_FirstName,
ContactSections_LastName,
ContactSections_Organization,
ContactSections_Sip,
ContactSections_Number,
ContactSections_Email,

View file

@ -139,7 +139,7 @@
}
- (BOOL)isValid {
BOOL hasName = (_contact.firstName.length + _contact.lastName.length > 0);
BOOL hasName = (_contact.firstName.length + _contact.lastName.length + _contact.organizationName.length > 0);
BOOL hasAddr =
(_contact.phones.count + _contact.sipAddresses.count) > 0;
return hasName && hasAddr;
@ -156,7 +156,7 @@
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == ContactSections_FirstName || section == ContactSections_LastName) {
if (section == ContactSections_FirstName || section == ContactSections_LastName || section == ContactSections_Organization) {
/*first and last name only when editting */
return (self.tableView.isEditing) ? 1 : 0;
} else if (section == ContactSections_Sip) {
@ -192,6 +192,9 @@
} else if (indexPath.section == ContactSections_LastName) {
value = _contact.lastName;
[cell hideDeleteButton:YES];
} else if (indexPath.section == ContactSections_Organization) {
value = _contact.organizationName;
[cell hideDeleteButton:YES];
} else if ([indexPath section] == ContactSections_Number) {
value = _contact.phones[indexPath.row];
[cell.editTextfield setKeyboardType:UIKeyboardTypePhonePad];
@ -279,6 +282,9 @@
} else if (section == ContactSections_LastName && self.tableView.isEditing) {
text = NSLocalizedString(@"Last name", nil);
canAddEntry = NO;
} else if (section == ContactSections_Organization && self.tableView.isEditing) {
text = NSLocalizedString(@"Organization", nil);
canAddEntry = NO;
} else if ([self getSectionData:section].count > 0 || self.tableView.isEditing) {
if (section == ContactSections_Number) {
text = NSLocalizedString(@"Phone numbers", nil);
@ -358,7 +364,7 @@
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0 ||
(!self.tableView.isEditing && (section == ContactSections_FirstName || section == ContactSections_LastName))) {
(!self.tableView.isEditing && (section == ContactSections_FirstName || section == ContactSections_LastName || section == ContactSections_LastName))) {
return 1e-5;
}
return [self tableView:tableView viewForHeaderInSection:section].frame.size.height;
@ -390,6 +396,9 @@
case ContactSections_LastName:
_contact.lastName = value;
break;
case ContactSections_Organization:
_contact.organizationName = value;
break;
case ContactSections_Sip:
[_contact setSipAddress:value atIndex:path.row];
value = _contact.sipAddresses[path.row]; // in case of reformatting

View file

@ -37,6 +37,7 @@
@property(nonatomic, strong) IBOutlet UIButton *cancelButton;
@property(weak, nonatomic) IBOutlet UIRoundedImageView *avatarImage;
@property(weak, nonatomic) IBOutlet UILabel *nameLabel;
@property(weak, nonatomic) IBOutlet UILabel *organizationLabel;
@property(weak, nonatomic) IBOutlet UIToggleButton *deleteButton;
@property(weak, nonatomic) IBOutlet UIScrollView *contentView;
@property(weak, nonatomic) IBOutlet UILabel *emptyLabel;

View file

@ -91,24 +91,25 @@
[PhoneMainView.instance popCurrentView];
return;
}
PhoneMainView.instance.currentName = _contact.displayName;
_nameLabel.text = PhoneMainView.instance.currentName;
// fix no sipaddresses in contact.friend
const MSList *sips = linphone_friend_get_addresses(_contact.friend);
while (sips) {
linphone_friend_remove_address(_contact.friend, sips->data);
sips = sips->next;
}
for (NSString *sipAddr in _contact.sipAddresses) {
LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true);
if (addr) {
linphone_friend_add_address(_contact.friend, addr);
linphone_address_destroy(addr);
}
}
[LinphoneManager.instance.fastAddressBook saveContact:_contact];
PhoneMainView.instance.currentName = _contact.displayName;
_nameLabel.text = PhoneMainView.instance.currentName;
_organizationLabel.text = _contact.organizationName;
// fix no sipaddresses in contact.friend
const MSList *sips = linphone_friend_get_addresses(_contact.friend);
while (sips) {
linphone_friend_remove_address(_contact.friend, sips->data);
sips = sips->next;
}
for (NSString *sipAddr in _contact.sipAddresses) {
LinphoneAddress *addr = linphone_core_interpret_url_2(LC, sipAddr.UTF8String, true);
if (addr) {
linphone_friend_add_address(_contact.friend, addr);
linphone_address_destroy(addr);
}
}
[LinphoneManager.instance.fastAddressBook saveContact:_contact];
}
- (void)selectContact:(Contact *)acontact andReload:(BOOL)reload {
@ -124,6 +125,7 @@
[_avatarImage setImage:[FastAddressBook imageForContact:_contact] bordered:NO withRoundedRadius:YES];
[ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact];
_organizationLabel.text = _contact.organizationName;
[_tableController setContact:_contact];
if (reload) {
@ -319,6 +321,7 @@
_deleteButton.hidden = TRUE;
}
_nameLabel.hidden = self.tableController.isEditing;
_organizationLabel.hidden = self.tableController.isEditing;
[self updateBackOrCancelButton];
[self recomputeTableViewSize:self.tableController.isEditing];
}
@ -405,7 +408,9 @@ static UICompositeViewDescription *compositeDescription = nil;
_cancelButton.hidden = !editing;
_backButton.hidden = editing;
_nameLabel.hidden = editing;
_organizationLabel.hidden = editing;
[ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact];
_organizationLabel.text = _contact.organizationName;
[self recomputeTableViewSize:editing];
@ -417,7 +422,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)recomputeTableViewSize:(BOOL)editing {
CGRect frame = _tableController.tableView.frame;
if ([self viewIsCurrentlyPortrait] && !editing) {
frame.origin.y = _nameLabel.frame.origin.y + _nameLabel.frame.size.height;
frame.origin.y = _organizationLabel.frame.origin.y + _organizationLabel.frame.size.height;
} else {
frame.origin.y = _avatarImage.frame.size.height + _avatarImage.frame.origin.y;
}

View file

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -14,37 +12,47 @@
<outlet property="avatarImage" destination="23" id="24"/>
<outlet property="linphoneImage" destination="25" id="27"/>
<outlet property="nameLabel" destination="6" id="26"/>
<outlet property="organizationLabel" destination="fva-Hf-er8" id="Ib6-rS-ybW"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="16">
<rect key="frame" x="0.0" y="0.0" width="360" height="44"/>
<rect key="frame" x="0.0" y="0.0" width="360" height="49"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" image="avatar.png" id="23" userLabel="avatarImage" customClass="UIRoundedImageView">
<rect key="frame" x="6" y="6" width="32" height="32"/>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" fixedFrame="YES" image="avatar.png" translatesAutoresizingMaskIntoConstraints="NO" id="23" userLabel="avatarImage" customClass="UIRoundedImageView">
<rect key="frame" x="6" y="9" width="32" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="left" text="John Doe" lineBreakMode="tailTruncation" minimumFontSize="10" id="6" userLabel="nameLabel">
<rect key="frame" x="46" y="0.0" width="256" height="44"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="left" fixedFrame="YES" text="John Doe" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="6" userLabel="nameLabel">
<rect key="frame" x="46" y="4" width="256" height="39"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration" label="Firstname"/>
<fontDescription key="fontDescription" type="system" pointSize="21"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" misplaced="YES" image="linphone_user.png" id="25" userLabel="linphoneImage">
<rect key="frame" x="319" y="10" width="25" height="25"/>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" fixedFrame="YES" image="linphone_user.png" translatesAutoresizingMaskIntoConstraints="NO" id="25" userLabel="linphoneImage">
<rect key="frame" x="319" y="13" width="25" height="25"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="2" contentMode="left" fixedFrame="YES" text="Organization" lineBreakMode="tailTruncation" minimumFontSize="10" translatesAutoresizingMaskIntoConstraints="NO" id="fva-Hf-er8" userLabel="organizationLabel">
<rect key="frame" x="46" y="29" width="256" height="18"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<accessibility key="accessibilityConfiguration" label="Firstname"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="137.59999999999999" y="-10.794602698650676"/>
</view>
</objects>
<resources>
<image name="avatar.png" width="259" height="259"/>
<image name="linphone_user.png" width="26" height="26"/>
<image name="avatar.png" width="414.39999389648438" height="414.39999389648438"/>
<image name="linphone_user.png" width="41.599998474121094" height="42.400001525878906"/>
</resources>
</document>

View file

@ -24,6 +24,7 @@
@interface UIContactCell : UITableViewCell
@property(nonatomic, strong) IBOutlet UILabel *nameLabel;
@property(nonatomic, strong) IBOutlet UILabel *organizationLabel;
@property(nonatomic, strong) IBOutlet UIRoundedImageView *avatarImage;
@property(weak, nonatomic) IBOutlet UIImageView *linphoneImage;
@property(nonatomic, assign) Contact *contact;

View file

@ -79,6 +79,7 @@
_linphoneImage.hidden = TRUE;
if(_contact) {
[ContactDisplay setDisplayNameLabel:_nameLabel forContact:_contact];
_organizationLabel.text = [FastAddressBook ogrganizationForContact:_contact];
_linphoneImage.hidden = [LinphoneManager.instance lpConfigBoolForKey:@"hide_linphone_contacts" inSection:@"app"] ||
! ((_contact.friend && linphone_presence_model_get_basic_status(linphone_friend_get_presence_model(_contact.friend)) == LinphonePresenceBasicStatusOpen) || [FastAddressBook contactHasValidSipDomain:_contact]);
}

View file

@ -55,6 +55,7 @@
+ (BOOL)isSipURIValid:(NSString*)addr;
+ (NSString *)displayNameForContact:(Contact *)person;
+ (NSString *)ogrganizationForContact:(Contact *)person;
+ (NSString *)displayNameForAddress:(const LinphoneAddress *)addr;
+ (BOOL)isSipURI:(NSString *)address;

View file

@ -338,6 +338,9 @@
+ (NSString *)displayNameForContact:(Contact *)contact {
return contact.displayName;
}
+ (NSString *)ogrganizationForContact:(Contact *)contact {
return contact.organizationName;
}
+ (NSString *)displayNameForAddress:(const LinphoneAddress *)addr {
Contact *contact = [FastAddressBook getContactWithAddress:addr];
@ -365,7 +368,7 @@
CNContactEmailAddressesKey, CNContactPhoneNumbersKey,
CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey,
CNContactIdentifierKey, CNContactInstantMessageAddressesKey,
CNInstantMessageAddressUsernameKey, CNContactImageDataKey
CNInstantMessageAddressUsernameKey, CNContactImageDataKey, CNContactOrganizationNameKey
];
CNMutableContact *mCNContact =
[[store unifiedContactWithIdentifier:acontact.identifier
@ -450,42 +453,42 @@
}
- (BOOL)saveCNContact:(CNContact *)cNContact contact:(Contact *)contact {
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
NSArray *keysToFetch = @[
CNContactEmailAddressesKey, CNContactPhoneNumbersKey,
CNContactInstantMessageAddressesKey, CNInstantMessageAddressUsernameKey,
CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey,
CNContactIdentifierKey, CNContactImageDataKey, CNContactNicknameKey
];
CNMutableContact *mCNContact =
[[store unifiedContactWithIdentifier:contact.identifier
keysToFetch:keysToFetch
error:nil] mutableCopy];
CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
NSArray *keysToFetch = @[
CNContactEmailAddressesKey, CNContactPhoneNumbersKey,
CNContactInstantMessageAddressesKey, CNInstantMessageAddressUsernameKey,
CNContactFamilyNameKey, CNContactGivenNameKey, CNContactPostalAddressesKey,
CNContactIdentifierKey, CNContactImageDataKey, CNContactNicknameKey, CNContactOrganizationNameKey
];
CNMutableContact *mCNContact =
[[store unifiedContactWithIdentifier:contact.identifier
keysToFetch:keysToFetch
error:nil] mutableCopy];
if(mCNContact == NULL){
[saveRequest addContact:[cNContact mutableCopy] toContainerWithIdentifier:nil];
}else{
[mCNContact setGivenName:contact.firstName];
[mCNContact setFamilyName:contact.lastName];
[mCNContact setNickname:contact.displayName];
[mCNContact setPhoneNumbers:contact.person.phoneNumbers];
[mCNContact setEmailAddresses:contact.person.emailAddresses];
[mCNContact
setInstantMessageAddresses:contact.person.instantMessageAddresses];
[mCNContact setImageData:UIImageJPEGRepresentation(contact.avatar, 0.9f)];
[saveRequest updateContact:mCNContact];
[mCNContact setGivenName:contact.firstName];
[mCNContact setFamilyName:contact.lastName];
[mCNContact setNickname:contact.displayName];
[mCNContact setOrganizationName:contact.organizationName];
[mCNContact setPhoneNumbers:contact.person.phoneNumbers];
[mCNContact setEmailAddresses:contact.person.emailAddresses];
[mCNContact setInstantMessageAddresses:contact.person.instantMessageAddresses];
[mCNContact setImageData:UIImageJPEGRepresentation(contact.avatar, 0.9f)];
[saveRequest updateContact:mCNContact];
}
NSError *saveError;
@try {
[self updateFriend:contact];
[LinphoneManager.instance setContactsUpdated:TRUE];
NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:&saveError]);
} @catch (NSException *exception) {
NSLog(@"=====>>>>> CNContact SaveRequest failed : description = %@", [exception description]);
return FALSE;
}
NSError *saveError;
@try {
[self updateFriend:contact];
[LinphoneManager.instance setContactsUpdated:TRUE];
NSLog(@"Success %d", [store executeSaveRequest:saveRequest error:&saveError]);
} @catch (NSException *exception) {
NSLog(@"=====>>>>> CNContact SaveRequest failed : description = %@", [exception description]);
return FALSE;
}
[self fetchContactsInBackGroundThread];
return TRUE;
return TRUE;
}
-(void)updateFriend:(Contact*) contact{