From b3d6a82c4fdfbbea46e1993f38e8595057f240c6 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Apr 2017 13:27:29 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Show=20blocked=20users=20in=20=E2=80=9Cadd?= =?UTF-8?q?=20to=20block=20list=E2=80=9D=20view.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../AddToBlockListViewController.m | 40 +++++++++++++++++-- Signal/src/views/ContactTableViewCell.h | 2 + Signal/src/views/ContactTableViewCell.m | 16 +++++++- .../translations/en.lproj/Localizable.strings | 17 ++++---- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/Signal/src/ViewControllers/AddToBlockListViewController.m b/Signal/src/ViewControllers/AddToBlockListViewController.m index d7a8695a0..fa26877e4 100644 --- a/Signal/src/ViewControllers/AddToBlockListViewController.m +++ b/Signal/src/ViewControllers/AddToBlockListViewController.m @@ -341,11 +341,11 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI [self.contactsTableView reloadData]; } -- (BOOL)isContactBlockedOrHidden:(Contact *)contact +- (BOOL)isContactBlocked:(Contact *)contact { if (contact.parsedPhoneNumbers.count < 1) { // Hide contacts without any valid phone numbers. - return YES; + return NO; } for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) { @@ -357,6 +357,20 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI return NO; } +- (BOOL)isContactHidden:(Contact *)contact +{ + if (contact.parsedPhoneNumbers.count < 1) { + // Hide contacts without any valid phone numbers. + return YES; + } + + if ([self isCurrentUserContact:contact]) { + return YES; + } + + return NO; +} + - (BOOL)isCurrentUserContact:(Contact *)contact { for (PhoneNumber *phoneNumber in contact.parsedPhoneNumbers) { @@ -372,7 +386,7 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI { NSMutableArray *result = [NSMutableArray new]; for (Contact *contact in self.contactsManager.signalContacts) { - if (![self isContactBlockedOrHidden:contact] && ![self isCurrentUserContact:contact]) { + if (![self isContactHidden:contact]) { [result addObject:contact]; } } @@ -436,6 +450,7 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI if (!cell) { cell = [ContactTableViewCell new]; } + cell.isBlocked = [self isContactBlocked:contact]; [cell configureWithContact:contact contactsManager:self.contactsManager]; return cell; } @@ -459,6 +474,25 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI __weak AddToBlockListViewController *weakSelf = self; Contact *contact = self.contacts[(NSUInteger)indexPath.item]; + if ([self isContactBlocked:contact]) { + NSString *displayName = [_contactsManager displayNameForContact:contact]; + UIAlertController *controller = [UIAlertController + alertControllerWithTitle:NSLocalizedString(@"BLOCK_LIST_VIEW_ALREADY_BLOCKED_ALERT_TITLE", + @"A title of the alert if user tries to block a user who is already blocked.") + message:[NSString + stringWithFormat:NSLocalizedString( + @"BLOCK_LIST_VIEW_ALREADY_BLOCKED_ALERT_MESSAGE_FORMAT", + @"A format for the message of the alert if user tries to " + @"block a user who is already blocked. Embeds {{the " + @"blocked user's name or phone number}}."), + displayName] + preferredStyle:UIAlertControllerStyleAlert]; + [controller addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil) + style:UIAlertActionStyleDefault + handler:nil]]; + [self presentViewController:controller animated:YES completion:nil]; + return; + } [BlockListUIUtils showBlockContactActionSheet:contact fromViewController:self blockingManager:_blockingManager diff --git a/Signal/src/views/ContactTableViewCell.h b/Signal/src/views/ContactTableViewCell.h index 91011d6c2..bc635c37d 100644 --- a/Signal/src/views/ContactTableViewCell.h +++ b/Signal/src/views/ContactTableViewCell.h @@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN @interface ContactTableViewCell : UITableViewCell +@property (nonatomic) BOOL isBlocked; + + (CGFloat)rowHeight; - (void)configureWithContact:(Contact *)contact contactsManager:(OWSContactsManager *)contactsManager; diff --git a/Signal/src/views/ContactTableViewCell.m b/Signal/src/views/ContactTableViewCell.m index c45f4fd3c..ca9271f4c 100644 --- a/Signal/src/views/ContactTableViewCell.m +++ b/Signal/src/views/ContactTableViewCell.m @@ -68,7 +68,21 @@ NS_ASSUME_NONNULL_BEGIN - (void)configureWithContact:(Contact *)contact contactsManager:(OWSContactsManager *)contactsManager { - self.nameLabel.attributedText = [contactsManager formattedFullNameForContact:contact font:self.nameLabel.font]; + NSMutableAttributedString *attributedText = + [[contactsManager formattedFullNameForContact:contact font:self.nameLabel.font] mutableCopy]; + if (self.isBlocked) { + // Add whitespace between the contact name and the blocked indicator. + [attributedText appendAttributedString:[[NSAttributedString alloc] initWithString:@" " attributes:nil]]; + [attributedText appendAttributedString:[[NSAttributedString alloc] + initWithString:NSLocalizedString(@"CONTACT_BLOCKED_INDICATOR", + @"An indicator that a contact has been blocked.") + attributes:@{ + NSFontAttributeName : [UIFont + ows_mediumFontWithSize:self.nameLabel.font.pointSize], + NSForegroundColorAttributeName : [UIColor blackColor], + }]]; + } + self.nameLabel.attributedText = attributedText; self.avatarView.image = [[[OWSContactAvatarBuilder alloc] initWithContactId:contact.textSecureIdentifiers.firstObject name:contact.fullName diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index edcda7c21..6ebef7355 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -109,6 +109,12 @@ /* A format for the 'unblock user' action sheet title. Embeds {{the blocked user's name or phone number}}. */ "BLOCK_LIST_UNBLOCK_TITLE_FORMAT" = "Unblock %@?"; +/* A format for the message of the alert if user tries to block a user who is already blocked. Embeds {{the blocked user's name or phone number}}. */ +"BLOCK_LIST_VIEW_ALREADY_BLOCKED_ALERT_MESSAGE_FORMAT" = "%@ is already blocked."; + +/* A title of the alert if user tries to block a user who is already blocked. */ +"BLOCK_LIST_VIEW_ALREADY_BLOCKED_ALERT_TITLE" = "Already Blocked"; + /* A label for the block button in the block list view */ "BLOCK_LIST_VIEW_BLOCK_BUTTON" = "Block"; @@ -187,6 +193,9 @@ /* No comment provided by engineer. */ "CONFIRMATION_TITLE" = "Confirm"; +/* An indicator that a contact has been blocked. */ +"CONTACT_BLOCKED_INDICATOR" = "(Blocked)"; + /* No comment provided by engineer. */ "CONTACT_DETAIL_COMM_TYPE_INSECURE" = "Unregistered Number"; @@ -346,9 +355,6 @@ /* No comment provided by engineer. */ "ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY" = "Safety number changed. Tap to verify."; -/* No comment provided by engineer. */ -"ERROR_WAS_DETECTED_TITLE" = "Bummer!"; - /* during registration */ "EXISTING_USER_REGISTRATION_ALERT_BODY" = "At this time Signal can only be active on one mobile device per phone number."; @@ -535,7 +541,7 @@ /* Indicates that a single member of this group has been blocked. */ "MESSAGES_VIEW_GROUP_1_MEMBER_BLOCKED" = "You Blocked 1 Member of this Group"; -/* Indicates that some members of this group has been blocked. Embeds {{the number of blocked user in this group}}. */ +/* Indicates that some members of this group has been blocked. Embeds {{the number of blocked users in this group}}. */ "MESSAGES_VIEW_GROUP_N_MEMBERS_BLOCKED_FORMAT" = "You Blocked %d Members of this Group"; /* The subtitle for the messages view title indicates that the title can be tapped to access settings for this conversation. */ @@ -979,9 +985,6 @@ /* No comment provided by engineer. */ "SUCCESSFUL_VERIFICATION_TITLE" = "Safety Number Verified!"; -/* No comment provided by engineer. */ -"TIMEOUT_CONTACTS_DETAIL" = "We couldn't fetch an updated contact list from the server. Please try again later."; - /* No comment provided by engineer. */ "TXT_CANCEL_TITLE" = "Cancel"; From e0c7457ecaca50c37c768106879f7eb1ecf4d6d8 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 5 Apr 2017 13:47:56 -0400 Subject: [PATCH 2/2] =?UTF-8?q?Refine=20appearance=20of=20=E2=80=9Cadd=20t?= =?UTF-8?q?o=20block=20list=E2=80=9D=20view.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // FREEBIE --- .../AddToBlockListViewController.m | 61 ++++++++++++++++++- .../translations/en.lproj/Localizable.strings | 13 +++- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/AddToBlockListViewController.m b/Signal/src/ViewControllers/AddToBlockListViewController.m index fa26877e4..f36a0157e 100644 --- a/Signal/src/ViewControllers/AddToBlockListViewController.m +++ b/Signal/src/ViewControllers/AddToBlockListViewController.m @@ -65,7 +65,7 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI _contactsManager = [Environment getCurrent].contactsManager; self.contacts = [self filteredContacts]; - self.title = NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_TITLE", @""); + self.title = NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_TITLE", @"Title for the 'add to block list' view."); [self createViews]; @@ -98,8 +98,15 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI } - (void)createViews { + + // Block Phone Number Title Row + UIView *blockPhoneNumberTitleRow = + [self createTitleRowWithText:NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_BLOCK_PHONE_NUMBER_TITLE", + @"Title for the 'block phone number' section of the 'add to block list' view.") + previousRow:nil]; + // Country Row - UIView *countryRow = [self createRowWithHeight:60 previousRow:nil]; + UIView *countryRow = [self createRowWithHeight:60 previousRow:blockPhoneNumberTitleRow]; _countryNameButton = [UIButton buttonWithType:UIButtonTypeCustom]; _countryNameButton.titleLabel.font = [UIFont ows_mediumFontWithSize:16.f]; @@ -186,6 +193,15 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI [_blockButton autoSetDimension:ALDimensionWidth toSize:160]; [_blockButton autoSetDimension:ALDimensionHeight toSize:40]; + // Separator Row + UIView *separatorRow = [self createRowWithHeight:10 previousRow:blockButtonRow]; + + // Block Contact Title Row + UIView *blockContactTitleRow = + [self createTitleRowWithText:NSLocalizedString(@"SETTINGS_ADD_TO_BLOCK_LIST_BLOCK_CONTACT_TITLE", + @"Title for the 'block contact' section of the 'add to block list' view.") + previousRow:separatorRow]; + _contactsTableView = [UITableView new]; _contactsTableView.dataSource = self; _contactsTableView.delegate = self; @@ -194,12 +210,29 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI _contactsTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; [self.view addSubview:_contactsTableView]; [_contactsTableView autoPinWidthToSuperview]; - [_contactsTableView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:blockButtonRow withOffset:30]; + [_contactsTableView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:blockContactTitleRow withOffset:10]; [_contactsTableView autoPinToBottomLayoutGuideOfViewController:self withInset:0]; [self updateBlockButtonEnabling]; } +- (UIView *)createTitleRowWithText:(NSString *)text previousRow:(nullable UIView *)previousRow +{ + UIView *row = [self createRowWithHeight:40 previousRow:previousRow]; + + UILabel *label = [UILabel new]; + label.text = text; + label.font = [UIFont ows_boldFontWithSize:20.f]; + label.textColor = [UIColor colorWithWhite:0.2f alpha:1.f]; + label.textAlignment = NSTextAlignmentCenter; + [row addSubview:label]; + [label autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:20.f]; + [label autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:20.f]; + [label autoPinEdgeToSuperviewEdge:ALEdgeBottom]; + + return row; +} + - (UIView *)createRowWithHeight:(CGFloat)height previousRow:(nullable UIView *)previousRow { UIView *row = [UIView new]; @@ -432,6 +465,11 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI #pragma mark - UITableViewDataSource +- (BOOL)hasNoContacts +{ + return self.contacts.count == 0; +} + - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; @@ -439,11 +477,24 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + if (self.hasNoContacts) { + return 1; + } return (NSInteger)self.contacts.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + if (self.hasNoContacts) { + 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:18.f]; + cell.textLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f]; + cell.textLabel.textAlignment = NSTextAlignmentCenter; + return cell; + } + Contact *contact = self.contacts[(NSUInteger)indexPath.item]; ContactTableViewCell *cell = [_contactsTableView cellForRowAtIndexPath:indexPath]; @@ -472,6 +523,10 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI { [tableView deselectRowAtIndexPath:indexPath animated:YES]; + if (self.hasNoContacts) { + return; + } + __weak AddToBlockListViewController *weakSelf = self; Contact *contact = self.contacts[(NSUInteger)indexPath.item]; if ([self isContactBlocked:contact]) { diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index 6ebef7355..0e2879986 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -847,8 +847,14 @@ /* Navbar title */ "SETTINGS_ABOUT" = "About"; -/* No comment provided by engineer. */ -"SETTINGS_ADD_TO_BLOCK_LIST_TITLE" = "Add to Block List"; +/* Title for the 'block contact' section of the 'add to block list' view. */ +"SETTINGS_ADD_TO_BLOCK_LIST_BLOCK_CONTACT_TITLE" = "Block Contact"; + +/* Title for the 'block phone number' section of the 'add to block list' view. */ +"SETTINGS_ADD_TO_BLOCK_LIST_BLOCK_PHONE_NUMBER_TITLE" = "Block Phone Number"; + +/* Title for the 'add to block list' view. */ +"SETTINGS_ADD_TO_BLOCK_LIST_TITLE" = "Block"; /* No comment provided by engineer. */ "SETTINGS_ADVANCED_DEBUGLOG" = "Enable Debug Log"; @@ -865,6 +871,9 @@ /* A header title for the block list table. */ "SETTINGS_BLOCK_LIST_HEADER_TITLE" = "Blocked Phone Numbers"; +/* A label that indicates the user has no Signal contacts. */ +"SETTINGS_BLOCK_LIST_NO_CONTACTS" = "You have no contacts on Signal."; + /* Label for the block list section of the settings view */ "SETTINGS_BLOCK_LIST_TITLE" = "Blocked";