note-to-self avatar

pull/1/head
Michael Kirk 6 years ago
parent 56d3b2a3cb
commit 2323cc21f0

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "note-24@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "note-24@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "note-24@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "OWSContactAvatarBuilder.h"
@ -90,6 +90,27 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable UIImage *)buildSavedImage
{
if ([self.signalId isEqualToString:TSAccountManager.localNumber]) {
NSString *noteToSelfCacheKey = [NSString stringWithFormat:@"%@:note-to-self", self.cacheKey];
UIImage *_Nullable cachedAvatar =
[OWSContactAvatarBuilder.contactsManager.avatarCache imageForKey:noteToSelfCacheKey
diameter:(CGFloat)self.diameter];
if (cachedAvatar) {
return cachedAvatar;
}
UIImage *image = [self noteToSelfImageWithConversationColorName:self.colorName];
if (!image) {
OWSFailDebug(@"Could not generate avatar.");
return nil;
}
[OWSContactAvatarBuilder.contactsManager.avatarCache setImage:image
forKey:noteToSelfCacheKey
diameter:self.diameter];
return image;
}
return [OWSContactAvatarBuilder.contactsManager imageForPhoneIdentifier:self.signalId];
}
@ -162,6 +183,35 @@ NS_ASSUME_NONNULL_BEGIN
return image;
}
- (nullable UIImage *)noteToSelfImageWithConversationColorName:(ConversationColorName)conversationColorName
{
UIImage *baseImage = [[UIImage imageNamed:@"note-to-self-avatar"] asTintedImageWithColor:UIColor.whiteColor];
UIColor *backgroundColor = [OWSConversationColor conversationColorOrDefaultForColorName:conversationColorName].themeColor;
CGFloat paddingFactor = 1.6;
CGFloat paddedWidth = baseImage.size.width * paddingFactor;
CGFloat paddedheight = baseImage.size.height * paddingFactor;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(paddedWidth, paddedheight), NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
[backgroundColor setFill];
CGContextFillRect(context, CGRectMake(0, 0, paddedWidth, paddedheight));
CGPoint origin = CGPointMake((paddedWidth - baseImage.size.width) / 2.0f,
(paddedheight - baseImage.size.height) / 2.0f);
[baseImage drawAtPoint:origin];
// Clean up and get the new image.
UIGraphicsPopContext();
UIImage *paddedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return paddedImage;
}
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save