Fix profile picture issue

pull/268/head
nielsandriesse 5 years ago
parent 21778e7d6c
commit c9cc1ee64e

@ -1,6 +1,6 @@
{ {
"info" : { "info" : {
"version" : 1, "author" : "xcode",
"author" : "xcode" "version" : 1
} }
} }

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 459 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 989 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -17,7 +17,7 @@ final class ConversationTitleView : UIView {
// MARK: Components // MARK: Components
private lazy var profilePictureView: ProfilePictureView = { private lazy var profilePictureView: ProfilePictureView = {
let result = ProfilePictureView() let result = ProfilePictureView()
let size = Values.smallProfilePictureSize let size: CGFloat = 40
result.set(.width, to: size) result.set(.width, to: size)
result.set(.height, to: size) result.set(.height, to: size)
result.size = size result.size = size

@ -954,20 +954,8 @@ const CGFloat kIconViewLength = 24;
CGFloat horizontalSpacing = isSmallScreen ? LKValues.largeSpacing : LKValues.veryLargeSpacing; CGFloat horizontalSpacing = isSmallScreen ? LKValues.largeSpacing : LKValues.veryLargeSpacing;
stackView.layoutMargins = UIEdgeInsetsMake(LKValues.mediumSpacing, horizontalSpacing, LKValues.mediumSpacing, horizontalSpacing); stackView.layoutMargins = UIEdgeInsetsMake(LKValues.mediumSpacing, horizontalSpacing, LKValues.mediumSpacing, horizontalSpacing);
[stackView setLayoutMarginsRelativeArrangement:YES]; [stackView setLayoutMarginsRelativeArrangement:YES];
if (self.isGroupThread) { if (!self.isGroupThread) {
TSGroupThread* groupThread = (TSGroupThread *)self.thread;
if (groupThread.isPublicChat && groupThread.groupModel.groupImage != nil
&& ![groupThread.groupModel.groupName isEqual:@"Loki Public Chat"] && ![groupThread.groupModel.groupName isEqual:@"Session Public Chat"]) {
profilePictureView.openGroupProfilePicture = groupThread.groupModel.groupImage;
profilePictureView.isRSSFeed = false;
} else {
profilePictureView.hexEncodedPublicKey = @"";
profilePictureView.isRSSFeed = true; // For now just always show the Session logo
}
} else {
profilePictureView.hexEncodedPublicKey = self.thread.contactIdentifier;
SRCopyableLabel *subtitleView = [SRCopyableLabel new]; SRCopyableLabel *subtitleView = [SRCopyableLabel new];
subtitleView.textColor = LKColors.text; subtitleView.textColor = LKColors.text;
subtitleView.font = [LKFonts spaceMonoOfSize:LKValues.smallFontSize]; subtitleView.font = [LKFonts spaceMonoOfSize:LKValues.smallFontSize];
@ -978,7 +966,7 @@ const CGFloat kIconViewLength = 24;
[stackView addArrangedSubview:subtitleView]; [stackView addArrangedSubview:subtitleView];
} }
[profilePictureView update]; [profilePictureView updateForThread:self.thread];
return stackView; return stackView;
} }

@ -3,6 +3,8 @@
public final class ProfilePictureView : UIView { public final class ProfilePictureView : UIView {
private var imageViewWidthConstraint: NSLayoutConstraint! private var imageViewWidthConstraint: NSLayoutConstraint!
private var imageViewHeightConstraint: NSLayoutConstraint! private var imageViewHeightConstraint: NSLayoutConstraint!
private var additionalImageViewWidthConstraint: NSLayoutConstraint!
private var additionalImageViewHeightConstraint: NSLayoutConstraint!
@objc public var size: CGFloat = 0 // Not an implicitly unwrapped optional due to Obj-C limitations @objc public var size: CGFloat = 0 // Not an implicitly unwrapped optional due to Obj-C limitations
@objc public var isRSSFeed = false @objc public var isRSSFeed = false
@objc public var hexEncodedPublicKey: String! @objc public var hexEncodedPublicKey: String!
@ -37,8 +39,8 @@ public final class ProfilePictureView : UIView {
additionalImageView.pin(.trailing, to: .trailing, of: self) additionalImageView.pin(.trailing, to: .trailing, of: self)
additionalImageView.pin(.bottom, to: .bottom, of: self) additionalImageView.pin(.bottom, to: .bottom, of: self)
let additionalImageViewSize = CGFloat(Values.smallProfilePictureSize) let additionalImageViewSize = CGFloat(Values.smallProfilePictureSize)
additionalImageView.set(.width, to: additionalImageViewSize) additionalImageViewWidthConstraint = additionalImageView.set(.width, to: additionalImageViewSize)
additionalImageView.set(.height, to: additionalImageViewSize) additionalImageViewHeightConstraint = additionalImageView.set(.height, to: additionalImageViewSize)
additionalImageView.layer.cornerRadius = additionalImageViewSize / 2 additionalImageView.layer.cornerRadius = additionalImageViewSize / 2
} }
@ -46,16 +48,16 @@ public final class ProfilePictureView : UIView {
@objc(updateForThread:) @objc(updateForThread:)
public func update(for thread: TSThread) { public func update(for thread: TSThread) {
openGroupProfilePicture = nil openGroupProfilePicture = nil
if thread.isGroupThread() { if let thread = thread as? TSGroupThread {
if thread.name() == "Loki Public Chat" if thread.name() == "Loki Public Chat"
|| thread.name() == "Session Public Chat" { // Override the profile picture for the Loki Public Chat and the Session Public Chat || thread.name() == "Session Public Chat" { // Override the profile picture for the Loki Public Chat and the Session Public Chat
hexEncodedPublicKey = "" hexEncodedPublicKey = ""
isRSSFeed = true isRSSFeed = true
} else if let openGroupProfilePicture = (thread as! TSGroupThread).groupModel.groupImage { // An open group with a profile picture } else if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture
self.openGroupProfilePicture = openGroupProfilePicture self.openGroupProfilePicture = openGroupProfilePicture
isRSSFeed = false isRSSFeed = false
} else if (thread as! TSGroupThread).groupModel.groupType == .openGroup } else if thread.groupModel.groupType == .openGroup
|| (thread as! TSGroupThread).groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed || thread.groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed
hexEncodedPublicKey = "" hexEncodedPublicKey = ""
isRSSFeed = true isRSSFeed = true
} else { // A closed group } else { // A closed group
@ -66,7 +68,7 @@ public final class ProfilePictureView : UIView {
additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : "" additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
isRSSFeed = false isRSSFeed = false
} }
} else { // A one-on-one chat } else { // A one-to-one chat
hexEncodedPublicKey = thread.contactIdentifier()! hexEncodedPublicKey = thread.contactIdentifier()!
additionalHexEncodedPublicKey = nil additionalHexEncodedPublicKey = nil
isRSSFeed = false isRSSFeed = false
@ -78,13 +80,26 @@ public final class ProfilePictureView : UIView {
AssertIsOnMainThread() AssertIsOnMainThread()
func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? { func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? {
guard !hexEncodedPublicKey.isEmpty else { return nil } guard !hexEncodedPublicKey.isEmpty else { return nil }
return OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) ?? Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey, size: size) if let profilePicture = OWSProfileManager.shared().profileAvatar(forRecipientId: hexEncodedPublicKey) {
return profilePicture
} else {
let displayName = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey) ?? hexEncodedPublicKey
return Identicon.generatePlaceholderIcon(seed: hexEncodedPublicKey, text: displayName, size: size)
}
} }
let size: CGFloat let size: CGFloat
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil { if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil {
size = Values.smallProfilePictureSize if self.size == 40 {
size = 32
} else if self.size == Values.largeProfilePictureSize {
size = 56
} else {
size = Values.smallProfilePictureSize
}
imageViewWidthConstraint.constant = size imageViewWidthConstraint.constant = size
imageViewHeightConstraint.constant = size imageViewHeightConstraint.constant = size
additionalImageViewWidthConstraint.constant = size
additionalImageViewHeightConstraint.constant = size
additionalImageView.isHidden = false additionalImageView.isHidden = false
additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey) additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey)
} else { } else {
@ -98,9 +113,14 @@ public final class ProfilePictureView : UIView {
imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey)) imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey))
imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant
imageView.layer.cornerRadius = size / 2 imageView.layer.cornerRadius = size / 2
additionalImageView.layer.cornerRadius = size / 2
imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit
if isRSSFeed { if isRSSFeed {
imageView.image = (size == 45) ? #imageLiteral(resourceName: "SessionWhite24") : #imageLiteral(resourceName: "SessionWhite40") switch size {
case Values.smallProfilePictureSize..<Values.mediumProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite16")
case Values.mediumProfilePictureSize..<Values.largeProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite24")
default: imageView.image = #imageLiteral(resourceName: "SessionWhite40")
}
} }
} }

Loading…
Cancel
Save