Merge branch 'mkirk/contact-editing'

pull/1/head
Michael Kirk 7 years ago
commit a4b26dda09

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12120" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="tuk-0x-yCb">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12118" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="tuk-0x-yCb">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
@ -388,28 +388,7 @@
<!--Show Group Members View Controller-->
<scene sceneID="VBt-Ax-0G9">
<objects>
<tableViewController storyboardIdentifier="ShowGroupMembersViewController" id="JeZ-9g-U61" customClass="ShowGroupMembersViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="Fdx-Zk-e27">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="groupMemberCell" id="hyn-Ss-OAa">
<rect key="frame" x="0.0" y="22" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hyn-Ss-OAa" id="4XE-JO-Upr">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="JeZ-9g-U61" id="xVC-pb-xNg"/>
<outlet property="delegate" destination="JeZ-9g-U61" id="qYP-nN-CLJ"/>
</connections>
</tableView>
<navigationItem key="navigationItem" id="gcZ-cw-Rtp"/>
</tableViewController>
<tableViewController storyboardIdentifier="ShowGroupMembersViewController" id="JeZ-9g-U61" customClass="ShowGroupMembersViewController" sceneMemberID="viewController"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="3R8-C6-Zq8" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1032" y="-1540"/>
@ -419,7 +398,7 @@
<objects>
<navigationController storyboardIdentifier="UserInitialViewController" automaticallyAdjustsScrollViewInsets="NO" useStoryboardIdentifierAsRestorationIdentifier="YES" id="tuk-0x-yCb" customClass="SignalsNavigationController" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="VNq-cN-pk9">
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" id="VNq-cN-pk9">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="barTintColor" red="0.082137122750282288" green="0.46843802928924561" blue="0.91112053394317627" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@ -529,7 +508,7 @@
<scene sceneID="nF7-wR-ITu">
<objects>
<navigationController storyboardIdentifier="SettingsNavigationController" id="u7y-N1-6Ba" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="OEe-gh-9Ii">
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" id="OEe-gh-9Ii">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
@ -904,7 +883,7 @@
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="cZ7-de-SUi" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="gzw-fh-en2">
<navigationBar key="navigationBar" contentMode="scaleToFill" misplaced="YES" translucent="NO" id="gzw-fh-en2">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="barTintColor" red="0.082137122750282288" green="0.46843802928924561" blue="0.91112053394317627" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>

@ -277,6 +277,7 @@ NSString * const kOWSTableCellIdentifier = @"kOWSTableCellIdentifier";
- (void)setContents:(OWSTableContents *)contents
{
OWSAssert(contents);
AssertIsOnMainThread();
_contents = contents;

@ -18,9 +18,11 @@
#import <SignalServiceKit/TSGroupModel.h>
#import <SignalServiceKit/TSGroupThread.h>
@import ContactsUI;
NS_ASSUME_NONNULL_BEGIN
@interface ShowGroupMembersViewController () <ContactsViewHelperDelegate>
@interface ShowGroupMembersViewController () <ContactsViewHelperDelegate, CNContactViewControllerDelegate>
@property (nonatomic, readonly) TSGroupThread *thread;
@property (nonatomic, readonly) ContactsViewHelper *contactsViewHelper;
@ -78,13 +80,25 @@ NS_ASSUME_NONNULL_BEGIN
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController.navigationBar setTranslucent:NO];
// HACK otherwise CNContactViewController Navbar is shown as black.
// RADAR rdar://28433898 http://www.openradar.me/28433898
// CNContactViewController incompatible with opaque navigation bar
[self.navigationController.navigationBar setTranslucent:YES];
self.title = _thread.groupModel.groupName;
[self updateTableContents];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// In case we're dismissing a CNContactViewController which requires default system appearance
[UIUtil applySignalAppearence];
}
#pragma mark - Table Contents
- (void)updateTableContents
@ -143,13 +157,15 @@ NS_ASSUME_NONNULL_BEGIN
UIAlertController *actionSheetController =
[UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheetController
addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"GROUP_MEMBERS_VIEW_CONTACT_INFO",
@"Button label for the 'show contact info' button")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
[self showContactInfoViewForRecipientId:recipientId];
}]];
NSString *contactInfoTitle = signalAccount
? NSLocalizedString(@"GROUP_MEMBERS_VIEW_CONTACT_INFO", @"Button label for the 'show contact info' button")
: NSLocalizedString(
@"GROUP_MEMBERS_ADD_CONTACT_INFO", @"Button label to add information to an unknown contact");
[actionSheetController addAction:[UIAlertAction actionWithTitle:contactInfoTitle
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *_Nonnull action) {
[self showContactInfoViewForRecipientId:recipientId];
}]];
BOOL isBlocked;
if (signalAccount) {
@ -280,37 +296,43 @@ NS_ASSUME_NONNULL_BEGIN
[self presentViewController:alertController animated:YES completion:nil];
return;
}
CNContactViewController *_Nullable contactViewController;
if (signalAccount) {
// FIXME This is broken until converted to Contacts framework.
ABPersonViewController *view = [[ABPersonViewController alloc] init];
ABAddressBookRef addressBookRef = ABAddressBookCreateWithOptions(NULL, nil);
// Assume person is already defined.
view.displayedPerson = ABAddressBookGetPersonWithRecordID(addressBookRef, signalAccount.contact.recordID);
view.allowsActions = NO;
view.allowsEditing = YES;
CNContact *_Nullable cnContact = signalAccount.contact.cnContact;
if (cnContact) {
contactViewController = [CNContactViewController viewControllerForContact:cnContact];
}
}
[self.navigationController pushViewController:view animated:YES];
} else {
// FIXME This is broken until converted to Contacts framework.
ABUnknownPersonViewController *view = [[ABUnknownPersonViewController alloc] init];
if (!contactViewController) {
CNMutableContact *newContact = [CNMutableContact new];
CNPhoneNumber *phoneNumber = [CNPhoneNumber phoneNumberWithStringValue:recipientId];
CNLabeledValue<CNPhoneNumber *> *labeledPhoneNumber = [CNLabeledValue labeledValueWithLabel:CNLabelPhoneNumberMain
value:phoneNumber];
newContact.phoneNumbers = @[labeledPhoneNumber];
contactViewController = [CNContactViewController viewControllerForNewContact:newContact];
}
ABRecordRef aContact = ABPersonCreate();
CFErrorRef anError = NULL;
contactViewController.delegate = self;
contactViewController.allowsActions = NO;
contactViewController.allowsEditing = YES;
contactViewController.navigationItem.leftBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"TXT_CANCEL_TITLE", nil)
style:UIBarButtonItemStylePlain
target:self
action:@selector(dismissPressed)];
ABMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phone, (__bridge CFTypeRef)recipientId, kABPersonPhoneMainLabel, NULL);
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController:contactViewController];
[self presentViewController:navigationController animated:YES completion:nil];
ABRecordSetValue(aContact, kABPersonPhoneProperty, phone, &anError);
CFRelease(phone);
if (!anError && aContact) {
view.displayedPerson = aContact; // Assume person is already defined.
view.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:view animated:YES];
}
}
// HACK otherwise CNContactViewController Navbar is shown as black.
// RADAR rdar://28433898 http://www.openradar.me/28433898
// CNContactViewController incompatible with opaque navigation bar
[UIUtil applyDefaultSystemAppearence];
}
- (void)showConversationViewForRecipientId:(NSString *)recipientId
@ -325,6 +347,12 @@ NS_ASSUME_NONNULL_BEGIN
[Environment callUserWithIdentifier:recipientId];
}
- (void)dismissPressed
{
DDLogDebug(@"%@ %s", self.tag, __PRETTY_FUNCTION__);
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - ContactsViewHelperDelegate
- (void)contactsViewHelperDidUpdateContacts
@ -337,6 +365,27 @@ NS_ASSUME_NONNULL_BEGIN
return YES;
}
#pragma mark - CNContactViewControllerDelegate
- (void)contactViewController:(CNContactViewController *)viewController
didCompleteWithContact:(nullable CNContact *)contact
{
DDLogDebug(@"%@ done editing contact.", self.tag);
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - Logging
+ (NSString *)tag
{
return [NSString stringWithFormat:@"[%@]", self.class];
}
- (NSString *)tag
{
return self.class.tag;
}
@end
NS_ASSUME_NONNULL_END

@ -4,6 +4,7 @@
import Foundation
import Contacts
import ContactsUI
@objc protocol SystemContactsFetcherDelegate: class {
func systemContactsFetcher(_ systemContactsFetcher: SystemContactsFetcher, updatedContacts contacts: [Contact])
@ -36,7 +37,8 @@ class SystemContactsFetcher: NSObject {
CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
CNContactThumbnailImageDataKey as CNKeyDescriptor, // TODO full image instead of thumbnail?
CNContactPhoneNumbersKey as CNKeyDescriptor,
CNContactEmailAddressesKey as CNKeyDescriptor
CNContactEmailAddressesKey as CNKeyDescriptor,
CNContactViewController.descriptorForRequiredKeys()
]
/**
@ -106,14 +108,11 @@ class SystemContactsFetcher: NSObject {
systemContactsHaveBeenRequestedAtLeastOnce = true
let contactStore = self.contactStore
let allowedContactKeys = self.allowedContactKeys
DispatchQueue.global().async {
var systemContacts = [CNContact]()
do {
let contactFetchRequest = CNContactFetchRequest(keysToFetch: allowedContactKeys)
try contactStore.enumerateContacts(with: contactFetchRequest) { (contact, _) -> Void in
let contactFetchRequest = CNContactFetchRequest(keysToFetch: self.allowedContactKeys)
try self.contactStore.enumerateContacts(with: contactFetchRequest) { (contact, _) -> Void in
systemContacts.append(contact)
}
} catch let error as NSError {

@ -33,6 +33,7 @@
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
[[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];
[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UIBarButtonItem appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor blackColor],

@ -520,6 +520,9 @@
/* No comment provided by engineer. */
"GROUP_MEMBER_LEFT" = " %@ left the group. ";
/* Button label to add information to an unknown contact */
"GROUP_MEMBERS_ADD_CONTACT_INFO" = "Add Contact";
/* Button label for the 'call group member' button */
"GROUP_MEMBERS_CALL" = "Call";

Loading…
Cancel
Save