New avatar placeholders.

- avatar colors implemented
- removed grey border on default group avatars and avatars with images
This commit is contained in:
Christine Corbett 2015-02-07 18:41:13 +00:00 committed by Frederic Jacobs
parent dfdd0a1974
commit 70248837e7
4 changed files with 39 additions and 10 deletions

View File

@ -12,8 +12,6 @@
+ (UIColor*) ows_materialBlueColor;
+ (UIColor *) ows_fadedBlueColor;
+ (UIColor *) ows_darkBackgroundColor;
@ -28,4 +26,6 @@
+ (UIColor*) ows_blackColor;
+ (UIColor*) backgroundColorForContact:(NSString*)contactIdentifier;
@end

View File

@ -7,6 +7,7 @@
//
#import "UIColor+OWS.h"
#import "Cryptography.h"
@implementation UIColor (OWS)
@ -54,6 +55,36 @@
return [UIColor colorWithRed:242.f/255.f green:242.f/255.f blue:242.f/255.f alpha:1.f];
}
+ (UIColor*) backgroundColorForContact:(NSString*)contactIdentifier {
NSArray *colors = @[[UIColor colorWithRed:204.f/255.f green:148.f/255.f blue:102.f/255.f alpha:1.f],
[UIColor colorWithRed:187.f/255.f green:104.f/255.f blue:62.f/255.f alpha:1.f],
[UIColor colorWithRed:145.f/255.f green:78.f/255.f blue:48.f/255.f alpha:1.f],
[UIColor colorWithRed:122.f/255.f green:63.f/255.f blue:41.f/255.f alpha:1.f],
[UIColor colorWithRed:80.f/255.f green:46.f/255.f blue:27.f/255.f alpha:1.f],
[UIColor colorWithRed:57.f/255.f green:45.f/255.f blue:19.f/255.f alpha:1.f],
[UIColor colorWithRed:37.f/255.f green:38.f/255.f blue:13.f/255.f alpha:1.f],
[UIColor colorWithRed:23.f/255.f green:31.f/255.f blue:10.f/255.f alpha:1.f],
[UIColor colorWithRed:6.f/255.f green:19.f/255.f blue:10.f/255.f alpha:1.f],
[UIColor colorWithRed:13.f/255.f green:4.f/255.f blue:16.f/255.f alpha:1.f],
[UIColor colorWithRed:27.f/255.f green:12.f/255.f blue:44.f/255.f alpha:1.f],
[UIColor colorWithRed:18.f/255.f green:17.f/255.f blue:64.f/255.f alpha:1.f],
[UIColor colorWithRed:20.f/255.f green:42.f/255.f blue:77.f/255.f alpha:1.f],
[UIColor colorWithRed:18.f/255.f green:55.f/255.f blue:68.f/255.f alpha:1.f],
[UIColor colorWithRed:18.f/255.f green:68.f/255.f blue:61.f/255.f alpha:1.f],
[UIColor colorWithRed:19.f/255.f green:73.f/255.f blue:26.f/255.f alpha:1.f],
[UIColor colorWithRed:13.f/255.f green:48.f/255.f blue:15.f/255.f alpha:1.f],
[UIColor colorWithRed:44.f/255.f green:165.f/255.f blue:137.f/255.f alpha:1.f],
[UIColor colorWithRed:137.f/255.f green:181.f/255.f blue:48.f/255.f alpha:1.f],
[UIColor colorWithRed:208.f/255.f green:204.f/255.f blue:78.f/255.f alpha:1.f],
[UIColor colorWithRed:227.f/255.f green:162.f/255.f blue:150.f/255.f alpha:1.f]];
NSData *contactData = [contactIdentifier dataUsingEncoding:NSUTF8StringEncoding];
NSData *hashData = [Cryptography computeSHA256:contactData truncatedToBytes:8];
unsigned long choose;
[hashData getBytes:&choose length:8];
return [colors objectAtIndex:(choose % [colors count])];
}
@end

View File

@ -6,7 +6,7 @@
+ (void)applyRoundedBorderToImageView:(UIImageView *__strong*)imageView {
[[*imageView layer] setBorderWidth:CONTACT_PICTURE_VIEW_BORDER_WIDTH];
[[*imageView layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
[[*imageView layer] setBorderColor:[[UIColor clearColor] CGColor]];
[[*imageView layer] setCornerRadius:CGRectGetWidth([*imageView frame])/2];
[[*imageView layer] setMasksToBounds:YES];
}

View File

@ -10,6 +10,7 @@
#import "Util.h"
#import "UIImage+JSQMessages.h"
#import "TSGroupThread.h"
#import "TSContactThread.h"
#import "JSQMessagesAvatarImageFactory.h"
#define ARCHIVE_IMAGE_VIEW_WIDTH 22.0f
#define DELETE_IMAGE_VIEW_WIDTH 19.0f
@ -63,14 +64,11 @@
}
}
}
UIImage* image = [[JSQMessagesAvatarImageFactory avatarImageWithUserInitials:initials backgroundColor:[UIColor whiteColor] textColor:[UIColor ows_materialBlueColor] font:[UIFont ows_regularFontWithSize:36.0] diameter:100] avatarImage];
UIColor *backgroundColor = thread.isGroupThread ? [UIColor whiteColor] : [UIColor backgroundColorForContact:((TSContactThread*)thread).contactIdentifier];
UIImage* image = [[JSQMessagesAvatarImageFactory avatarImageWithUserInitials:initials backgroundColor:backgroundColor textColor:[UIColor whiteColor] font:[UIFont ows_boldFontWithSize:36.0] diameter:100] avatarImage];
_contactPictureView.image = thread.image!=nil ? thread.image : image;
if(thread.image==nil) {
UIImage *overlayImage = [UIImage imageNamed:@"circContact--empty"];
UIImageView *overlayImageView = [[UIImageView alloc] initWithImage:overlayImage];
[_contactPictureView addSubview:overlayImageView];
}
else {
if(thread.image!=nil) {
[UIUtil applyRoundedBorderToImageView:&_contactPictureView];
}
}