Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 9 years ago
parent e75ed5e477
commit 5c0c9b533e

@ -12,6 +12,8 @@ NS_ASSUME_NONNULL_BEGIN
- (BOOL)canSelectBlockedContact; - (BOOL)canSelectBlockedContact;
- (nullable UIView *)createHeader:(UIView *)superview;
@end @end
#pragma mark - #pragma mark -

@ -90,13 +90,19 @@ NS_ASSUME_NONNULL_BEGIN
- (void)createViews - (void)createViews
{ {
UIView *header = [self.delegate createHeader:self.view];
// Table // Table
_tableViewController = [OWSTableViewController new]; _tableViewController = [OWSTableViewController new];
_tableViewController.delegate = self; _tableViewController.delegate = self;
_tableViewController.contents = [OWSTableContents new]; _tableViewController.contents = [OWSTableContents new];
[self.view addSubview:self.tableViewController.view]; [self.view addSubview:self.tableViewController.view];
[_tableViewController.view autoPinWidthToSuperview]; [_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]; [_tableViewController.view autoPinEdgeToSuperviewEdge:ALEdgeBottom];
// Search // Search
@ -149,18 +155,16 @@ NS_ASSUME_NONNULL_BEGIN
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
SelectThreadViewController *strongSelf = weakSelf; SelectThreadViewController *strongSelf = weakSelf;
if (!strongSelf) { if (!strongSelf) {
return (InboxTableViewCell *)nil; return (ContactTableViewCell *)nil;
} }
InboxTableViewCell *cell = [InboxTableViewCell inboxTableViewCell]; // To be consistent with the threads (above), we use ContactTableViewCell
// instead of InboxTableViewCell to present contacts and threads.
[cell configureWithThread:thread ContactTableViewCell *cell = [ContactTableViewCell new];
contactsManager:strongSelf.contactsManager [cell configureWithThread:thread contactsManager:strongSelf.contactsManager];
blockedPhoneNumberSet:strongSelf.blockedPhoneNumberSet];
return cell; return cell;
} }
customRowHeight:[InboxTableViewCell rowHeight] customRowHeight:[ContactTableViewCell rowHeight]
actionBlock:^{ actionBlock:^{
[weakSelf.delegate threadWasSelected:thread]; [weakSelf.delegate threadWasSelected:thread];
}]]; }]];
@ -172,25 +176,21 @@ NS_ASSUME_NONNULL_BEGIN
[section addItem:[OWSTableItem itemWithCustomCellBlock:^{ [section addItem:[OWSTableItem itemWithCustomCellBlock:^{
SelectThreadViewController *strongSelf = weakSelf; SelectThreadViewController *strongSelf = weakSelf;
if (!strongSelf) { if (!strongSelf) {
return (InboxTableViewCell *)nil; return (ContactTableViewCell *)nil;
} }
// To be consistent with the threads (above), we use InboxTableViewCell ContactTableViewCell *cell = [ContactTableViewCell new];
// instead of ContactTableViewCell to present contacts.
InboxTableViewCell *cell = [InboxTableViewCell inboxTableViewCell];
// TODO: Use ContactAccount.
NSString *recipientId = contact.textSecureIdentifiers.firstObject;
BOOL isBlocked = [strongSelf isContactBlocked:contact]; BOOL isBlocked = [strongSelf isContactBlocked:contact];
if (isBlocked) {
[cell configureWithContact:contact cell.accessoryMessage
recipientId:recipientId = NSLocalizedString(@"CONTACT_CELL_IS_BLOCKED", @"An indicator that a contact has been blocked.");
contactsManager:strongSelf.contactsManager } else {
isBlocked:isBlocked]; OWSAssert(cell.accessoryMessage == nil);
}
[cell configureWithContact:contact contactsManager:strongSelf.contactsManager];
return cell; return cell;
} }
customRowHeight:[InboxTableViewCell rowHeight] customRowHeight:[ContactTableViewCell rowHeight]
actionBlock:^{ actionBlock:^{
[weakSelf contactWasSelected:contact]; [weakSelf contactWasSelected:contact];
}]]; }]];

@ -49,6 +49,11 @@ NS_ASSUME_NONNULL_BEGIN
return NO; return NO;
} }
- (nullable UIView *)createHeader:(UIView *)superview
{
return nil;
}
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -16,6 +16,7 @@ NS_ASSUME_NONNULL_BEGIN
extern NSString *const kContactsTable_CellReuseIdentifier; extern NSString *const kContactsTable_CellReuseIdentifier;
@class OWSContactsManager; @class OWSContactsManager;
@class TSThread;
@interface ContactTableViewCell : UITableViewCell @interface ContactTableViewCell : UITableViewCell
@ -29,6 +30,8 @@ extern NSString *const kContactsTable_CellReuseIdentifier;
- (void)configureWithRecipientId:(NSString *)recipientId contactsManager:(OWSContactsManager *)contactsManager; - (void)configureWithRecipientId:(NSString *)recipientId contactsManager:(OWSContactsManager *)contactsManager;
- (void)configureWithThread:(TSThread *)thread contactsManager:(OWSContactsManager *)contactsManager;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -9,6 +9,8 @@
#import "UIFont+OWS.h" #import "UIFont+OWS.h"
#import "UIUtil.h" #import "UIUtil.h"
#import "UIView+OWS.h" #import "UIView+OWS.h"
#import <SignalServiceKit/TSGroupThread.h>
#import <SignalServiceKit/TSThread.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -50,11 +52,11 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI
{ {
const CGFloat kAvatarSize = 40.f; const CGFloat kAvatarSize = 40.f;
_avatarView = [UIImageView new]; _avatarView = [UIImageView new];
_avatarView.contentMode = UIViewContentModeScaleToFill;
_avatarView.image = [UIImage imageNamed:@"empty-group-avatar"]; _avatarView.image = [UIImage imageNamed:@"empty-group-avatar"];
// applyRoundedBorderToImageView requires the avatar to have // applyRoundedBorderToImageView requires the avatar to have
// the correct size. // the correct size.
_avatarView.frame = CGRectMake(0, 0, kAvatarSize, kAvatarSize); _avatarView.frame = CGRectMake(0, 0, kAvatarSize, kAvatarSize);
_avatarView.contentMode = UIViewContentModeScaleToFill;
_avatarView.layer.minificationFilter = kCAFilterTrilinear; _avatarView.layer.minificationFilter = kCAFilterTrilinear;
_avatarView.layer.magnificationFilter = kCAFilterTrilinear; _avatarView.layer.magnificationFilter = kCAFilterTrilinear;
[self.contentView addSubview:_avatarView]; [self.contentView addSubview:_avatarView];
@ -121,6 +123,28 @@ NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseI
[self layoutSubviews]; [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 - (void)layoutSubviews
{ {
[super layoutSubviews]; [super layoutSubviews];

Loading…
Cancel
Save