You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/Signal/src/views/ContactTableViewCell.m

78 lines
3.2 KiB
Matlab

11 years ago
#import "ContactTableViewCell.h"
#import "Environment.h"
#import "OWSContactAvatarBuilder.h"
#import "OWSContactsManager.h"
#import "PhoneManager.h"
#import "UIUtil.h"
@interface ContactTableViewCell ()
11 years ago
@property (nonatomic) IBOutlet UILabel *nameLabel;
@property (nonatomic) IBOutlet UIImageView *avatarView;
@end
11 years ago
@implementation ContactTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
11 years ago
return self;
}
- (NSString *)reuseIdentifier {
return NSStringFromClass(self.class);
11 years ago
}
- (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];
11 years ago
}
- (NSAttributedString *)attributedStringForContact:(Contact *)contact {
NSMutableAttributedString *fullNameAttributedString =
[[NSMutableAttributedString alloc] initWithString:contact.fullName];
11 years ago
UIFont *firstNameFont;
UIFont *lastNameFont;
11 years ago
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];
11 years ago
}
[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)];
}
11 years ago
return fullNameAttributedString;
}
@end