From 0b6962cdd08c49f81c72a5fb70438c1d6306987b Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 5 May 2017 18:05:14 -0400 Subject: [PATCH] contacts reminder in compose view // FREEBIE --- .../MessageComposeTableViewController.m | 58 +++++++++++++------ .../ViewControllers/SignalsViewController.m | 3 +- Signal/src/views/ReminderView.swift | 3 +- .../translations/en.lproj/Localizable.strings | 5 +- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/Signal/src/ViewControllers/MessageComposeTableViewController.m b/Signal/src/ViewControllers/MessageComposeTableViewController.m index 00cb744d6..181363447 100644 --- a/Signal/src/ViewControllers/MessageComposeTableViewController.m +++ b/Signal/src/ViewControllers/MessageComposeTableViewController.m @@ -34,6 +34,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) OWSTableViewController *tableViewController; @property (nonatomic, readonly) UISearchBar *searchBar; +@property (nonatomic, readonly) NSLayoutConstraint *hideContactsPermissionReminderViewConstraint; // A list of possible phone numbers parsed from the search text as // E164 values. @@ -59,6 +60,18 @@ NS_ASSUME_NONNULL_BEGIN _contactsViewHelper.delegate = self; _nonContactAccountSet = [NSMutableSet set]; + ReminderView *contactsPermissionReminderView = [[ReminderView alloc] + initWithText:NSLocalizedString(@"COMPOSE_SCREEN_MISSING_CONTACTS_PERMISSION", + @"Multiline label explaining why compose-screen contact picker is empty.") + tapAction:^{ + [[UIApplication sharedApplication] openSystemSettings]; + }]; + [self.view addSubview:contactsPermissionReminderView]; + [contactsPermissionReminderView autoPinWidthToSuperview]; + [contactsPermissionReminderView autoPinEdgeToSuperviewMargin:ALEdgeTop]; + _hideContactsPermissionReminderViewConstraint = + [contactsPermissionReminderView autoSetDimension:ALDimensionHeight toSize:0]; + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self @@ -87,7 +100,8 @@ NS_ASSUME_NONNULL_BEGIN _tableViewController.tableViewStyle = UITableViewStylePlain; [self.view addSubview:self.tableViewController.view]; [_tableViewController.view autoPinWidthToSuperview]; - [_tableViewController.view autoPinEdgeToSuperviewEdge:ALEdgeTop]; + + [_tableViewController.view autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:contactsPermissionReminderView]; [_tableViewController.view autoPinToBottomLayoutGuideOfViewController:self withInset:0]; _tableViewController.tableView.tableHeaderView = searchBar; @@ -101,6 +115,11 @@ NS_ASSUME_NONNULL_BEGIN [self updateTableContents]; } +- (void)showContactsPermissionReminder:(BOOL)flag +{ + _hideContactsPermissionReminderViewConstraint.active = !flag; +} + - (UIView *)createNoSignalContactsView { UIView *view = [UIView new]; @@ -357,18 +376,20 @@ NS_ASSUME_NONNULL_BEGIN if (!hasSearchText && helper.signalAccounts.count < 1) { // No Contacts - [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ - UITableViewCell *cell = [UITableViewCell new]; - cell.textLabel.text = NSLocalizedString( - @"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts."); - cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f]; - cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; - cell.textLabel.textAlignment = NSTextAlignmentCenter; - cell.selectionStyle = UITableViewCellSelectionStyleNone; - return cell; + if (self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) { + [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ + UITableViewCell *cell = [UITableViewCell new]; + cell.textLabel.text = NSLocalizedString( + @"SETTINGS_BLOCK_LIST_NO_CONTACTS", @"A label that indicates the user has no Signal contacts."); + cell.textLabel.font = [UIFont ows_regularFontWithSize:15.f]; + cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; + cell.textLabel.textAlignment = NSTextAlignmentCenter; + cell.selectionStyle = UITableViewCellSelectionStyleNone; + return cell; + } + customRowHeight:kActionCellHeight + actionBlock:nil]]; } - customRowHeight:kActionCellHeight - actionBlock:nil]]; } if (hasSearchText && !hasSearchResults) { @@ -420,12 +441,15 @@ NS_ASSUME_NONNULL_BEGIN - (void)showNoContactsModeIfNecessary { - if (!self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) { - return; + if (self.contactsViewHelper.contactsManager.isSystemContactsAuthorized) { + BOOL hasNoContacts = self.contactsViewHelper.signalAccounts.count < 1; + self.isNoContactsModeActive = (hasNoContacts && ![[Environment preferences] hasDeclinedNoContactsView]); + [self showContactsPermissionReminder:NO]; + } else { + // don't show "no signal contacts", show "no contact access" + self.isNoContactsModeActive = NO; + [self showContactsPermissionReminder:YES]; } - - BOOL hasNoContacts = self.contactsViewHelper.signalAccounts.count < 1; - self.isNoContactsModeActive = (hasNoContacts && ![[Environment preferences] hasDeclinedNoContactsView]); } - (void)setIsNoContactsModeActive:(BOOL)isNoContactsModeActive diff --git a/Signal/src/ViewControllers/SignalsViewController.m b/Signal/src/ViewControllers/SignalsViewController.m index 18c7f5a44..dc2b3d012 100644 --- a/Signal/src/ViewControllers/SignalsViewController.m +++ b/Signal/src/ViewControllers/SignalsViewController.m @@ -168,7 +168,8 @@ NSString *const SignalsViewControllerSegueShowIncomingCall = @"ShowIncomingCallS @"SETTINGS_BUTTON_ACCESSIBILITY", @"Accessibility hint for the settings button"); - self.missingContactsPermissionView.text = NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION", @"Multi line label explainging how to show names instead of phone numbers in your inbox"); + self.missingContactsPermissionView.text = NSLocalizedString(@"INBOX_VIEW_MISSING_CONTACTS_PERMISSION", + @"Multiline label explaining how to show names instead of phone numbers in your inbox"); self.missingContactsPermissionView.tapAction = ^{ [[UIApplication sharedApplication] openSystemSettings]; }; diff --git a/Signal/src/views/ReminderView.swift b/Signal/src/views/ReminderView.swift index f0875a2cf..71309dd71 100644 --- a/Signal/src/views/ReminderView.swift +++ b/Signal/src/views/ReminderView.swift @@ -41,8 +41,9 @@ class ReminderView: UIView { setupSubviews() } - convenience init(tapAction: @escaping () -> Void) { + convenience init(text: String, tapAction: @escaping () -> Void) { self.init(frame: .zero) + self.text = text self.tapAction = tapAction } diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index ab6db1a7e..f986e986a 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -217,6 +217,9 @@ /* Activity Sheet label */ "COMPARE_SAFETY_NUMBER_ACTION" = "Compare with Clipboard"; +/* Multiline label explaining why compose-screen contact picker is empty. */ +"COMPOSE_SCREEN_MISSING_CONTACTS_PERMISSION" = "To see which of your contacts are Signal users, enable contacts access in your system settings."; + /* No comment provided by engineer. */ "CONFIRM_ACCOUNT_DESTRUCTION_TEXT" = "This will reset the application by deleting your messages and unregister you with the server. The app will close after deletion of data."; @@ -562,7 +565,7 @@ /* Call setup status label */ "IN_CALL_TERMINATED" = "Call Ended."; -/* Multi line label explainging how to show names instead of phone numbers in your inbox */ +/* Multiline label explaining how to show names instead of phone numbers in your inbox */ "INBOX_VIEW_MISSING_CONTACTS_PERMISSION" = "To see the names of your contacts, update your sytem settings to allow contact access."; /* notification body */