#import "ContactTableViewCell.h" #import "Environment.h" #import "OWSContactAvatarBuilder.h" #import "OWSContactsManager.h" #import "PhoneManager.h" #import "UIUtil.h" @interface ContactTableViewCell () @property (nonatomic) IBOutlet UILabel *nameLabel; @property (nonatomic) IBOutlet UIImageView *avatarView; @end @implementation ContactTableViewCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; return self; } - (NSString *)reuseIdentifier { return NSStringFromClass(self.class); } - (void)configureWithContact:(Contact *)contact contactsManager:(OWSContactsManager *)contactsManager { self.nameLabel.attributedText = [self attributedStringForContact:contact]; self.avatarView.image = [[[OWSContactAvatarBuilder alloc] initWithContactId:contact.textSecureIdentifiers.firstObject name:contact.fullName contactsManager:contactsManager] build]; } - (void)layoutSubviews { [super layoutSubviews]; [UIUtil applyRoundedBorderToImageView:self.avatarView]; } - (NSAttributedString *)attributedStringForContact:(Contact *)contact { NSMutableAttributedString *fullNameAttributedString = [[NSMutableAttributedString alloc] initWithString:contact.fullName]; UIFont *firstNameFont; UIFont *lastNameFont; if (ABPersonGetSortOrdering() == kABPersonCompositeNameFormatFirstNameFirst) { firstNameFont = [UIFont ows_mediumFontWithSize:self.nameLabel.font.pointSize]; lastNameFont = [UIFont ows_regularFontWithSize:self.nameLabel.font.pointSize]; } else { firstNameFont = [UIFont ows_regularFontWithSize:self.nameLabel.font.pointSize]; lastNameFont = [UIFont ows_mediumFontWithSize:self.nameLabel.font.pointSize]; } [fullNameAttributedString addAttribute:NSFontAttributeName value:firstNameFont range:NSMakeRange(0, contact.firstName.length)]; [fullNameAttributedString addAttribute:NSFontAttributeName value:lastNameFont range:NSMakeRange(contact.firstName.length + 1, contact.lastName.length)]; [fullNameAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, contact.fullName.length)]; if (ABPersonGetSortOrdering() == kABPersonCompositeNameFormatFirstNameFirst) { [fullNameAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor ows_darkGrayColor] range:NSMakeRange(contact.firstName.length + 1, contact.lastName.length)]; } else { [fullNameAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor ows_darkGrayColor] range:NSMakeRange(0, contact.firstName.length)]; } return fullNameAttributedString; } @end