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
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
_avatarView = [UIImageView new];
|
|
|
|
_avatarView.contentMode = UIViewContentModeScaleToFill;
|
|
|
|
_avatarView.image = [UIImage imageNamed:@"empty-group-avatar"];
|
|
|
|
[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];
|
|
|
|
[_avatarView autoSetDimension:ALDimensionWidth toSize:40.f];
|
|
|
|
[_avatarView autoSetDimension:ALDimensionHeight toSize:40.f];
|
|
|
|
|
|
|
|
[_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-05 19:27:29 +02:00
|
|
|
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;
|
2016-11-18 23:11:56 +01:00
|
|
|
self.avatarView.image =
|
|
|
|
[[[OWSContactAvatarBuilder alloc] initWithContactId:contact.textSecureIdentifiers.firstObject
|
|
|
|
name:contact.fullName
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2016-11-22 21:19:49 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|