Use actual avatar in ContactViewController

// FREEBIE
This commit is contained in:
Michael Kirk 2018-05-04 22:52:43 -04:00
parent 77fc5571fb
commit 45f91ead44
3 changed files with 22 additions and 21 deletions

View file

@ -249,16 +249,9 @@ class ContactViewController: OWSViewController, CNContactViewControllerDelegate
backButton.addSubview(backIconView)
backIconView.autoCenterInSuperview()
// TODO: Use actual avatar.
let avatarSize = CGFloat(100)
let avatarSize: CGFloat = 100
let avatarView = AvatarImageView()
// TODO: What's the best colorSeed value to use?
let avatarBuilder = OWSContactAvatarBuilder(nonSignalName: contactShare.displayName,
colorSeed: contactShare.displayName,
diameter: UInt(avatarSize),
contactsManager: contactsManager)
avatarView.image = avatarBuilder.build()
avatarView.image = contactShare.getAvatarImage(diameter: avatarSize, contactsManager: contactsManager)
topView.addSubview(avatarView)
avatarView.autoPin(toTopLayoutGuideOf: self, withInset: 20)
avatarView.autoHCenterInSuperview()

View file

@ -38,6 +38,11 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
- (OWSContactsManager *)contactsManager
{
return [Environment current].contactsManager;
}
#pragma mark -
- (CGFloat)iconHMargin
@ -107,18 +112,8 @@ NS_ASSUME_NONNULL_BEGIN
// TODO: Use the contact's avatar if present and downloaded.
AvatarImageView *avatarView = [AvatarImageView new];
// TODO: What's the best colorSeed value to use?
UIImage *_Nullable avatarImage = self.contactShare.avatarImage;
if (!avatarImage) {
OWSAvatarBuilder *avatarBuilder =
[[OWSContactAvatarBuilder alloc] initWithNonSignalName:self.contactShare.displayName
colorSeed:self.contactShare.displayName
diameter:(NSUInteger)self.iconSize
contactsManager:[Environment current].contactsManager];
avatarImage = [avatarBuilder build];
}
avatarView.image = avatarImage;
avatarView.image =
[self.contactShare getAvatarImageWithDiameter:self.iconSize contactsManager:self.contactsManager];
[avatarView autoSetDimension:ALDimensionWidth toSize:self.iconSize];
[avatarView autoSetDimension:ALDimensionHeight toSize:self.iconSize];

View file

@ -23,6 +23,19 @@ public class ContactShareViewModel: NSObject {
}
}
public func getAvatarImage(diameter: CGFloat, contactsManager: OWSContactsManager) -> UIImage {
if let avatarImage = avatarImage {
return avatarImage
}
// TODO: What's the best colorSeed value to use?
let avatarBuilder = OWSContactAvatarBuilder(nonSignalName: displayName,
colorSeed: displayName,
diameter: UInt(diameter),
contactsManager: contactsManager)
return avatarBuilder.build()
}
// MARK: Delegated -> dbRecord
public var addresses: [OWSContactAddress] {