Fix profile picture issue
This commit is contained in:
parent
21778e7d6c
commit
c9cc1ee64e
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"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 |
BIN
Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@2x.png
vendored
Normal file
BIN
Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@2x.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 989 B |
BIN
Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@3x.png
vendored
Normal file
BIN
Signal/Images.xcassets/Loki V2/SessionWhite16.imageset/SessionWhite16@3x.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
|
@ -17,7 +17,7 @@ final class ConversationTitleView : UIView {
|
|||
// MARK: Components
|
||||
private lazy var profilePictureView: ProfilePictureView = {
|
||||
let result = ProfilePictureView()
|
||||
let size = Values.smallProfilePictureSize
|
||||
let size: CGFloat = 40
|
||||
result.set(.width, to: size)
|
||||
result.set(.height, to: size)
|
||||
result.size = size
|
||||
|
|
|
@ -954,20 +954,8 @@ const CGFloat kIconViewLength = 24;
|
|||
CGFloat horizontalSpacing = isSmallScreen ? LKValues.largeSpacing : LKValues.veryLargeSpacing;
|
||||
stackView.layoutMargins = UIEdgeInsetsMake(LKValues.mediumSpacing, horizontalSpacing, LKValues.mediumSpacing, horizontalSpacing);
|
||||
[stackView setLayoutMarginsRelativeArrangement:YES];
|
||||
|
||||
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;
|
||||
|
||||
|
||||
if (!self.isGroupThread) {
|
||||
SRCopyableLabel *subtitleView = [SRCopyableLabel new];
|
||||
subtitleView.textColor = LKColors.text;
|
||||
subtitleView.font = [LKFonts spaceMonoOfSize:LKValues.smallFontSize];
|
||||
|
@ -978,7 +966,7 @@ const CGFloat kIconViewLength = 24;
|
|||
[stackView addArrangedSubview:subtitleView];
|
||||
}
|
||||
|
||||
[profilePictureView update];
|
||||
[profilePictureView updateForThread:self.thread];
|
||||
|
||||
return stackView;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
public final class ProfilePictureView : UIView {
|
||||
private var imageViewWidthConstraint: 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 isRSSFeed = false
|
||||
@objc public var hexEncodedPublicKey: String!
|
||||
|
@ -37,8 +39,8 @@ public final class ProfilePictureView : UIView {
|
|||
additionalImageView.pin(.trailing, to: .trailing, of: self)
|
||||
additionalImageView.pin(.bottom, to: .bottom, of: self)
|
||||
let additionalImageViewSize = CGFloat(Values.smallProfilePictureSize)
|
||||
additionalImageView.set(.width, to: additionalImageViewSize)
|
||||
additionalImageView.set(.height, to: additionalImageViewSize)
|
||||
additionalImageViewWidthConstraint = additionalImageView.set(.width, to: additionalImageViewSize)
|
||||
additionalImageViewHeightConstraint = additionalImageView.set(.height, to: additionalImageViewSize)
|
||||
additionalImageView.layer.cornerRadius = additionalImageViewSize / 2
|
||||
}
|
||||
|
||||
|
@ -46,16 +48,16 @@ public final class ProfilePictureView : UIView {
|
|||
@objc(updateForThread:)
|
||||
public func update(for thread: TSThread) {
|
||||
openGroupProfilePicture = nil
|
||||
if thread.isGroupThread() {
|
||||
if let thread = thread as? TSGroupThread {
|
||||
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
|
||||
hexEncodedPublicKey = ""
|
||||
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
|
||||
isRSSFeed = false
|
||||
} else if (thread as! TSGroupThread).groupModel.groupType == .openGroup
|
||||
|| (thread as! TSGroupThread).groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed
|
||||
} else if thread.groupModel.groupType == .openGroup
|
||||
|| thread.groupModel.groupType == .rssFeed { // An open group without a profile picture or an RSS feed
|
||||
hexEncodedPublicKey = ""
|
||||
isRSSFeed = true
|
||||
} else { // A closed group
|
||||
|
@ -66,7 +68,7 @@ public final class ProfilePictureView : UIView {
|
|||
additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
|
||||
isRSSFeed = false
|
||||
}
|
||||
} else { // A one-on-one chat
|
||||
} else { // A one-to-one chat
|
||||
hexEncodedPublicKey = thread.contactIdentifier()!
|
||||
additionalHexEncodedPublicKey = nil
|
||||
isRSSFeed = false
|
||||
|
@ -78,13 +80,26 @@ public final class ProfilePictureView : UIView {
|
|||
AssertIsOnMainThread()
|
||||
func getProfilePicture(of size: CGFloat, for hexEncodedPublicKey: String) -> UIImage? {
|
||||
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
|
||||
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
|
||||
imageViewHeightConstraint.constant = size
|
||||
additionalImageViewWidthConstraint.constant = size
|
||||
additionalImageViewHeightConstraint.constant = size
|
||||
additionalImageView.isHidden = false
|
||||
additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey)
|
||||
} else {
|
||||
|
@ -98,9 +113,14 @@ public final class ProfilePictureView : UIView {
|
|||
imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey))
|
||||
imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant
|
||||
imageView.layer.cornerRadius = size / 2
|
||||
additionalImageView.layer.cornerRadius = size / 2
|
||||
imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit
|
||||
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…
Reference in New Issue