session-ios/Signal/src/views/ContactTableViewCell.m

75 lines
2.9 KiB
Mathematica
Raw Normal View History

2014-05-06 19:41:08 +02:00
#import "ContactTableViewCell.h"
2014-11-24 21:51:43 +01:00
#import "UIUtil.h"
2014-05-06 19:41:08 +02:00
#import "Environment.h"
#import "PhoneManager.h"
2014-05-06 19:41:08 +02:00
#define CONTACT_TABLE_CELL_BORDER_WIDTH 1.0f
@interface ContactTableViewCell () {
2014-10-29 21:58:58 +01:00
}
@property (strong, nonatomic) Contact *associatedContact;
2014-10-29 21:58:58 +01:00
@end
2014-05-06 19:41:08 +02:00
@implementation ContactTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
2014-05-06 19:41:08 +02:00
return self;
}
- (NSString *)reuseIdentifier {
return NSStringFromClass(self.class);
2014-05-06 19:41:08 +02:00
}
2014-11-24 21:51:43 +01:00
2014-05-06 19:41:08 +02:00
- (void)configureWithContact:(Contact *)contact {
if (!contact.isTextSecureContact) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
}
2014-10-29 21:58:58 +01:00
_associatedContact = contact;
2014-05-06 19:41:08 +02:00
_nameLabel.attributedText = [self attributedStringForContact:contact];
if (!contact.isTextSecureContact) {
_nameLabel.textColor = [UIColor lightGrayColor];
}
2014-05-06 19:41:08 +02:00
}
- (NSAttributedString *)attributedStringForContact:(Contact *)contact {
NSMutableAttributedString *fullNameAttributedString =
[[NSMutableAttributedString alloc] initWithString:contact.fullName];
2014-05-06 19:41:08 +02:00
UIFont *firstNameFont;
UIFont *lastNameFont;
2014-05-06 19:41:08 +02:00
if (ABPersonGetSortOrdering() == kABPersonCompositeNameFormatFirstNameFirst) {
firstNameFont = [UIFont ows_mediumFontWithSize:_nameLabel.font.pointSize];
lastNameFont = [UIFont ows_regularFontWithSize:_nameLabel.font.pointSize];
} else {
firstNameFont = [UIFont ows_regularFontWithSize:_nameLabel.font.pointSize];
lastNameFont = [UIFont ows_mediumFontWithSize:_nameLabel.font.pointSize];
2014-05-06 19:41:08 +02:00
}
[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)];
}
2014-05-06 19:41:08 +02:00
return fullNameAttributedString;
}
@end