2017-03-23 14:55:39 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2014-05-06 19:41:08 +02:00
|
|
|
#import "ContactTableViewCell.h"
|
2014-11-29 19:54:33 +01:00
|
|
|
#import "Environment.h"
|
2016-11-18 23:11:56 +01:00
|
|
|
#import "OWSContactAvatarBuilder.h"
|
|
|
|
#import "OWSContactsManager.h"
|
2017-03-31 23:43:42 +02:00
|
|
|
#import "UIFont+OWS.h"
|
2016-11-18 23:11:56 +01:00
|
|
|
#import "UIUtil.h"
|
2017-03-31 23:43:42 +02:00
|
|
|
#import "UIView+OWS.h"
|
2014-11-29 19:54:33 +01:00
|
|
|
|
2016-11-22 21:19:49 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-04-18 22:08:01 +02:00
|
|
|
NSString *const kContactsTable_CellReuseIdentifier = @"kContactsTable_CellReuseIdentifier";
|
|
|
|
|
2016-06-28 02:07:18 +02:00
|
|
|
@interface ContactTableViewCell ()
|
2014-05-06 19:41:08 +02:00
|
|
|
|
2016-11-18 23:11:56 +01:00
|
|
|
@property (nonatomic) IBOutlet UILabel *nameLabel;
|
|
|
|
@property (nonatomic) IBOutlet UIImageView *avatarView;
|
2016-06-28 02:07:18 +02:00
|
|
|
|
2014-10-29 21:58:58 +01:00
|
|
|
@end
|
|
|
|
|
2014-05-06 19:41:08 +02:00
|
|
|
@implementation ContactTableViewCell
|
|
|
|
|
2017-03-31 23:43:42 +02:00
|
|
|
- (instancetype)init
|
|
|
|
{
|
|
|
|
if (self = [super init]) {
|
|
|
|
[self configureProgrammatically];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-04-06 17:44:03 +02:00
|
|
|
+ (nullable NSString *)reuseIdentifier
|
|
|
|
{
|
|
|
|
return NSStringFromClass(self.class);
|
|
|
|
}
|
|
|
|
|
2016-11-22 21:19:49 +01:00
|
|
|
- (nullable NSString *)reuseIdentifier
|
|
|
|
{
|
2014-09-08 01:31:05 +02:00
|
|
|
return NSStringFromClass(self.class);
|
2014-05-06 19:41:08 +02:00
|
|
|
}
|
|
|
|
|
2017-03-31 23:43:42 +02:00
|
|
|
+ (CGFloat)rowHeight
|
|
|
|
{
|
|
|
|
return 59.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureProgrammatically
|
|
|
|
{
|
2017-04-07 03:54:43 +02:00
|
|
|
const CGFloat kAvatarSize = 40.f;
|
2017-03-31 23:43:42 +02:00
|
|
|
_avatarView = [UIImageView new];
|
|
|
|
_avatarView.contentMode = UIViewContentModeScaleToFill;
|
|
|
|
_avatarView.image = [UIImage imageNamed:@"empty-group-avatar"];
|
2017-04-07 03:54:43 +02:00
|
|
|
// applyRoundedBorderToImageView requires the avatar to have
|
|
|
|
// the correct size.
|
|
|
|
_avatarView.frame = CGRectMake(0, 0, kAvatarSize, kAvatarSize);
|
2017-04-18 22:08:01 +02:00
|
|
|
_avatarView.layer.minificationFilter = kCAFilterTrilinear;
|
|
|
|
_avatarView.layer.magnificationFilter = kCAFilterTrilinear;
|
2017-03-31 23:43:42 +02:00
|
|
|
[self.contentView addSubview:_avatarView];
|
|
|
|
|
|
|
|
_nameLabel = [UILabel new];
|
|
|
|
_nameLabel.contentMode = UIViewContentModeLeft;
|
|
|
|
_nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
_nameLabel.font = [UIFont ows_dynamicTypeBodyFont];
|
|
|
|
[self.contentView addSubview:_nameLabel];
|
|
|
|
|
|
|
|
[_avatarView autoVCenterInSuperview];
|
|
|
|
[_avatarView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:8.f];
|
2017-04-07 03:54:43 +02:00
|
|
|
[_avatarView autoSetDimension:ALDimensionWidth toSize:kAvatarSize];
|
|
|
|
[_avatarView autoSetDimension:ALDimensionHeight toSize:kAvatarSize];
|
2017-03-31 23:43:42 +02:00
|
|
|
|
|
|
|
[_nameLabel autoPinEdgeToSuperviewEdge:ALEdgeRight];
|
|
|
|
[_nameLabel autoPinEdgeToSuperviewEdge:ALEdgeTop];
|
|
|
|
[_nameLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom];
|
|
|
|
[_nameLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeRight ofView:_avatarView withOffset:12.f];
|
|
|
|
|
|
|
|
// Force layout, since imageView isn't being initally rendered on App Store optimized build.
|
|
|
|
[self layoutSubviews];
|
|
|
|
}
|
|
|
|
|
2016-11-18 23:11:56 +01:00
|
|
|
- (void)configureWithContact:(Contact *)contact contactsManager:(OWSContactsManager *)contactsManager
|
|
|
|
{
|
2017-04-18 22:08:01 +02:00
|
|
|
[self configureWithRecipientId:contact.textSecureIdentifiers.firstObject
|
|
|
|
avatarName:contact.fullName
|
|
|
|
displayName:[contactsManager formattedFullNameForContact:contact font:self.nameLabel.font]
|
|
|
|
contactsManager:contactsManager];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureWithRecipientId:(NSString *)recipientId contactsManager:(OWSContactsManager *)contactsManager
|
|
|
|
{
|
|
|
|
[self
|
|
|
|
configureWithRecipientId:recipientId
|
|
|
|
avatarName:@""
|
|
|
|
displayName:[contactsManager formattedFullNameForRecipientId:recipientId font:self.nameLabel.font]
|
|
|
|
contactsManager:contactsManager];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)configureWithRecipientId:(NSString *)recipientId
|
|
|
|
avatarName:(NSString *)avatarName
|
|
|
|
displayName:(NSAttributedString *)displayName
|
|
|
|
contactsManager:(OWSContactsManager *)contactsManager
|
|
|
|
{
|
|
|
|
NSMutableAttributedString *attributedText = [displayName mutableCopy];
|
2017-04-06 17:44:03 +02:00
|
|
|
if (self.accessoryMessage) {
|
2017-04-05 22:32:34 +02:00
|
|
|
UILabel *blockedLabel = [[UILabel alloc] init];
|
|
|
|
blockedLabel.textAlignment = NSTextAlignmentRight;
|
2017-04-06 17:44:03 +02:00
|
|
|
blockedLabel.text = self.accessoryMessage;
|
2017-04-06 03:37:26 +02:00
|
|
|
blockedLabel.font = [UIFont ows_mediumFontWithSize:13.f];
|
|
|
|
blockedLabel.textColor = [UIColor colorWithWhite:0.5f alpha:1.f];
|
2017-04-05 22:32:34 +02:00
|
|
|
[blockedLabel sizeToFit];
|
|
|
|
|
|
|
|
self.accessoryView = blockedLabel;
|
2017-04-05 19:27:29 +02:00
|
|
|
}
|
|
|
|
self.nameLabel.attributedText = attributedText;
|
2016-11-18 23:11:56 +01:00
|
|
|
self.avatarView.image =
|
2017-04-18 22:08:01 +02:00
|
|
|
[[[OWSContactAvatarBuilder alloc] initWithContactId:recipientId name:avatarName contactsManager:contactsManager]
|
|
|
|
build];
|
2016-11-22 21:19:49 +01:00
|
|
|
|
|
|
|
// Force layout, since imageView isn't being initally rendered on App Store optimized build.
|
|
|
|
[self layoutSubviews];
|
2016-11-18 23:11:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews
|
|
|
|
{
|
|
|
|
[super layoutSubviews];
|
|
|
|
[UIUtil applyRoundedBorderToImageView:self.avatarView];
|
2014-05-06 19:41:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-06 17:44:03 +02:00
|
|
|
- (void)prepareForReuse
|
|
|
|
{
|
|
|
|
self.accessoryMessage = nil;
|
|
|
|
self.accessoryView = nil;
|
|
|
|
self.accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
}
|
|
|
|
|
2014-05-06 19:41:08 +02:00
|
|
|
@end
|
2016-11-22 21:19:49 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|