From 5c0c9b533e46abd3275351ac3e2d524e794151eb Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Wed, 26 Apr 2017 13:03:51 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- .../SelectThreadViewController.h | 2 + .../SelectThreadViewController.m | 46 +++++++++---------- .../SendExternalFileViewController.m | 5 ++ Signal/src/views/ContactTableViewCell.h | 3 ++ Signal/src/views/ContactTableViewCell.m | 26 ++++++++++- 5 files changed, 58 insertions(+), 24 deletions(-) diff --git a/Signal/src/ViewControllers/SelectThreadViewController.h b/Signal/src/ViewControllers/SelectThreadViewController.h index 089f377b2..b09abf4c4 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.h +++ b/Signal/src/ViewControllers/SelectThreadViewController.h @@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)canSelectBlockedContact; +- (nullable UIView *)createHeader:(UIView *)superview; + @end #pragma mark - diff --git a/Signal/src/ViewControllers/SelectThreadViewController.m b/Signal/src/ViewControllers/SelectThreadViewController.m index 471b8f820..656e492dd 100644 --- a/Signal/src/ViewControllers/SelectThreadViewController.m +++ b/Signal/src/ViewControllers/SelectThreadViewController.m @@ -90,13 +90,19 @@ NS_ASSUME_NONNULL_BEGIN - (void)createViews { + UIView *header = [self.delegate createHeader:self.view]; + // Table _tableViewController = [OWSTableViewController new]; _tableViewController.delegate = self; _tableViewController.contents = [OWSTableContents new]; [self.view addSubview:self.tableViewController.view]; [_tableViewController.view autoPinWidthToSuperview]; - [_tableViewController.view autoPinToTopLayoutGuideOfViewController:self withInset:0]; + if (header) { + [_tableViewController.view autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:header]; + } else { + [_tableViewController.view autoPinToTopLayoutGuideOfViewController:self withInset:0]; + } [_tableViewController.view autoPinEdgeToSuperviewEdge:ALEdgeBottom]; // Search @@ -149,18 +155,16 @@ NS_ASSUME_NONNULL_BEGIN [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectThreadViewController *strongSelf = weakSelf; if (!strongSelf) { - return (InboxTableViewCell *)nil; + return (ContactTableViewCell *)nil; } - InboxTableViewCell *cell = [InboxTableViewCell inboxTableViewCell]; - - [cell configureWithThread:thread - contactsManager:strongSelf.contactsManager - blockedPhoneNumberSet:strongSelf.blockedPhoneNumberSet]; - + // To be consistent with the threads (above), we use ContactTableViewCell + // instead of InboxTableViewCell to present contacts and threads. + ContactTableViewCell *cell = [ContactTableViewCell new]; + [cell configureWithThread:thread contactsManager:strongSelf.contactsManager]; return cell; } - customRowHeight:[InboxTableViewCell rowHeight] + customRowHeight:[ContactTableViewCell rowHeight] actionBlock:^{ [weakSelf.delegate threadWasSelected:thread]; }]]; @@ -172,25 +176,21 @@ NS_ASSUME_NONNULL_BEGIN [section addItem:[OWSTableItem itemWithCustomCellBlock:^{ SelectThreadViewController *strongSelf = weakSelf; if (!strongSelf) { - return (InboxTableViewCell *)nil; + return (ContactTableViewCell *)nil; } - // To be consistent with the threads (above), we use InboxTableViewCell - // instead of ContactTableViewCell to present contacts. - InboxTableViewCell *cell = [InboxTableViewCell inboxTableViewCell]; - - // TODO: Use ContactAccount. - NSString *recipientId = contact.textSecureIdentifiers.firstObject; + ContactTableViewCell *cell = [ContactTableViewCell new]; BOOL isBlocked = [strongSelf isContactBlocked:contact]; - - [cell configureWithContact:contact - recipientId:recipientId - contactsManager:strongSelf.contactsManager - isBlocked:isBlocked]; - + if (isBlocked) { + cell.accessoryMessage + = NSLocalizedString(@"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked."); + } else { + OWSAssert(cell.accessoryMessage == nil); + } + [cell configureWithContact:contact contactsManager:strongSelf.contactsManager]; return cell; } - customRowHeight:[InboxTableViewCell rowHeight] + customRowHeight:[ContactTableViewCell rowHeight] actionBlock:^{ [weakSelf contactWasSelected:contact]; }]]; diff --git a/Signal/src/ViewControllers/SendExternalFileViewController.m b/Signal/src/ViewControllers/SendExternalFileViewController.m index f2cd236d8..e3a51e658 100644 --- a/Signal/src/ViewControllers/SendExternalFileViewController.m +++ b/Signal/src/ViewControllers/SendExternalFileViewController.m @@ -49,6 +49,11 @@ NS_ASSUME_NONNULL_BEGIN return NO; } +- (nullable UIView *)createHeader:(UIView *)superview +{ + return nil; +} + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/views/ContactTableViewCell.h b/Signal/src/views/ContactTableViewCell.h index 25080871a..445e92d51 100644 --- a/Signal/src/views/ContactTableViewCell.h +++ b/Signal/src/views/ContactTableViewCell.h @@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const kContactsTable_CellReuseIdentifier; @class OWSContactsManager; +@class TSThread; @interface ContactTableViewCell : UITableViewCell @@ -29,6 +30,8 @@ extern NSString *const kContactsTable_CellReuseIdentifier; - (void)configureWithRecipientId:(NSString *)recipientId contactsManager:(OWSContactsManager *)contactsManager; +- (void)configureWithThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager; + @end NS_ASSUME_NONNULL_END diff --git a/Signal/src/views/ContactTableViewCell.m b/Signal/src/views/ContactTableViewCell.m index acddb70e8..82fd906ee 100644 --- a/Signal/src/views/ContactTableViewCell.m +++ b/Signal/src/views/ContactTableViewCell.m @@ -9,6 +9,8 @@ #import "UIFont+OWS.h" #import "UIUtil.h" #import "UIView+OWS.h" +#import +#import NS_ASSUME_NONNULL_BEGIN @@ -50,11 +52,11 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI { const CGFloat kAvatarSize = 40.f; _avatarView = [UIImageView new]; - _avatarView.contentMode = UIViewContentModeScaleToFill; _avatarView.image = [UIImage imageNamed:@"empty-group-avatar"]; // applyRoundedBorderToImageView requires the avatar to have // the correct size. _avatarView.frame = CGRectMake(0, 0, kAvatarSize, kAvatarSize); + _avatarView.contentMode = UIViewContentModeScaleToFill; _avatarView.layer.minificationFilter = kCAFilterTrilinear; _avatarView.layer.magnificationFilter = kCAFilterTrilinear; [self.contentView addSubview:_avatarView]; @@ -121,6 +123,28 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI [self layoutSubviews]; } +- (void)configureWithThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager +{ + OWSAssert(thread); + + NSString *threadName = thread.name; + if (threadName.length == 0 && [thread isKindOfClass:[TSGroupThread class]]) { + threadName = NSLocalizedString(@"NEW_GROUP_DEFAULT_TITLE", @""); + } + + NSAttributedString *attributedText = [[NSAttributedString alloc] + initWithString:threadName + attributes:@{ + NSForegroundColorAttributeName : [UIColor blackColor], + }]; + self.nameLabel.attributedText = attributedText; + + self.avatarView.image = [OWSAvatarBuilder buildImageForThread:thread contactsManager:contactsManager]; + + // Force layout, since imageView isn't being initally rendered on App Store optimized build. + [self layoutSubviews]; +} + - (void)layoutSubviews { [super layoutSubviews];