Clean
This commit is contained in:
parent
7289c5064a
commit
9969284a2b
|
@ -148,7 +148,7 @@ private extension GroupMembersVC {
|
||||||
|
|
||||||
// MARK: Updating
|
// MARK: Updating
|
||||||
private func update() {
|
private func update() {
|
||||||
profilePictureView.hexEncodedPublicKey = hexEncodedPublicKey
|
profilePictureView.publicKey = hexEncodedPublicKey
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
displayNameLabel.text = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
displayNameLabel.text = UserDisplayNameUtilities.getPrivateChatDisplayName(for: hexEncodedPublicKey) ?? hexEncodedPublicKey
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ private extension MentionSelectionView {
|
||||||
// MARK: Updating
|
// MARK: Updating
|
||||||
private func update() {
|
private func update() {
|
||||||
displayNameLabel.text = mentionCandidate.displayName
|
displayNameLabel.text = mentionCandidate.displayName
|
||||||
profilePictureView.hexEncodedPublicKey = mentionCandidate.publicKey
|
profilePictureView.publicKey = mentionCandidate.publicKey
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
if let server = openGroupServer, let channel = openGroupChannel {
|
if let server = openGroupServer, let channel = openGroupChannel {
|
||||||
let isUserModerator = OpenGroupAPI.isUserModerator(mentionCandidate.publicKey, for: channel, on: server)
|
let isUserModerator = OpenGroupAPI.isUserModerator(mentionCandidate.publicKey, for: channel, on: server)
|
||||||
|
|
|
@ -244,7 +244,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
|
||||||
let profilePictureView = ProfilePictureView()
|
let profilePictureView = ProfilePictureView()
|
||||||
profilePictureView.accessibilityLabel = "Settings button"
|
profilePictureView.accessibilityLabel = "Settings button"
|
||||||
profilePictureView.size = profilePictureSize
|
profilePictureView.size = profilePictureSize
|
||||||
profilePictureView.hexEncodedPublicKey = getUserHexEncodedPublicKey()
|
profilePictureView.publicKey = getUserHexEncodedPublicKey()
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
profilePictureView.set(.width, to: profilePictureSize)
|
profilePictureView.set(.width, to: profilePictureSize)
|
||||||
profilePictureView.set(.height, to: profilePictureSize)
|
profilePictureView.set(.height, to: profilePictureSize)
|
||||||
|
|
|
@ -69,7 +69,7 @@ final class SettingsVC : BaseVC, AvatarViewHelperDelegate {
|
||||||
// Set up profile picture view
|
// Set up profile picture view
|
||||||
let profilePictureTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showEditProfilePictureUI))
|
let profilePictureTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showEditProfilePictureUI))
|
||||||
profilePictureView.addGestureRecognizer(profilePictureTapGestureRecognizer)
|
profilePictureView.addGestureRecognizer(profilePictureTapGestureRecognizer)
|
||||||
profilePictureView.hexEncodedPublicKey = getUserHexEncodedPublicKey()
|
profilePictureView.publicKey = getUserHexEncodedPublicKey()
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
// Set up display name label
|
// Set up display name label
|
||||||
displayNameLabel.text = OWSProfileManager.shared().profileNameForRecipient(withID: getUserHexEncodedPublicKey())
|
displayNameLabel.text = OWSProfileManager.shared().profileNameForRecipient(withID: getUserHexEncodedPublicKey())
|
||||||
|
|
|
@ -82,7 +82,7 @@ final class UserCell : UITableViewCell {
|
||||||
|
|
||||||
// MARK: Updating
|
// MARK: Updating
|
||||||
func update() {
|
func update() {
|
||||||
profilePictureView.hexEncodedPublicKey = publicKey
|
profilePictureView.publicKey = publicKey
|
||||||
profilePictureView.update()
|
profilePictureView.update()
|
||||||
displayNameLabel.text = UserDisplayNameUtilities.getPrivateChatDisplayName(for: publicKey) ?? publicKey
|
displayNameLabel.text = UserDisplayNameUtilities.getPrivateChatDisplayName(for: publicKey) ?? publicKey
|
||||||
switch accessory {
|
switch accessory {
|
||||||
|
|
|
@ -2,16 +2,17 @@ import SessionUIKit
|
||||||
|
|
||||||
@objc(LKProfilePictureView)
|
@objc(LKProfilePictureView)
|
||||||
public final class ProfilePictureView : UIView {
|
public final class ProfilePictureView : UIView {
|
||||||
|
private var hasTappableProfilePicture: Bool = false
|
||||||
|
@objc public var size: CGFloat = 0 // Not an implicitly unwrapped optional due to Obj-C limitations
|
||||||
|
@objc public var useFallbackPicture = false
|
||||||
|
@objc public var publicKey: String!
|
||||||
|
@objc public var additionalPublicKey: String?
|
||||||
|
@objc public var openGroupProfilePicture: UIImage?
|
||||||
|
// Constraints
|
||||||
private var imageViewWidthConstraint: NSLayoutConstraint!
|
private var imageViewWidthConstraint: NSLayoutConstraint!
|
||||||
private var imageViewHeightConstraint: NSLayoutConstraint!
|
private var imageViewHeightConstraint: NSLayoutConstraint!
|
||||||
private var additionalImageViewWidthConstraint: NSLayoutConstraint!
|
private var additionalImageViewWidthConstraint: NSLayoutConstraint!
|
||||||
private var additionalImageViewHeightConstraint: NSLayoutConstraint!
|
private var additionalImageViewHeightConstraint: NSLayoutConstraint!
|
||||||
private var hasTappableProfilePicture: Bool = false
|
|
||||||
@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!
|
|
||||||
@objc public var additionalHexEncodedPublicKey: String?
|
|
||||||
@objc public var openGroupProfilePicture: UIImage?
|
|
||||||
|
|
||||||
// MARK: Components
|
// MARK: Components
|
||||||
private lazy var imageView = getImageView()
|
private lazy var imageView = getImageView()
|
||||||
|
@ -50,9 +51,9 @@ public final class ProfilePictureView : UIView {
|
||||||
@objc(updateForContact:)
|
@objc(updateForContact:)
|
||||||
public func update(for publicKey: String) {
|
public func update(for publicKey: String) {
|
||||||
openGroupProfilePicture = nil
|
openGroupProfilePicture = nil
|
||||||
hexEncodedPublicKey = publicKey
|
self.publicKey = publicKey
|
||||||
additionalHexEncodedPublicKey = nil
|
additionalPublicKey = nil
|
||||||
isRSSFeed = false
|
useFallbackPicture = false
|
||||||
update()
|
update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +63,11 @@ public final class ProfilePictureView : UIView {
|
||||||
if let thread = thread as? TSGroupThread {
|
if let thread = thread as? TSGroupThread {
|
||||||
if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture
|
if let openGroupProfilePicture = thread.groupModel.groupImage { // An open group with a profile picture
|
||||||
self.openGroupProfilePicture = openGroupProfilePicture
|
self.openGroupProfilePicture = openGroupProfilePicture
|
||||||
isRSSFeed = false
|
useFallbackPicture = false
|
||||||
hasTappableProfilePicture = true
|
hasTappableProfilePicture = true
|
||||||
} else if thread.groupModel.groupType == .openGroup { // An open group without a profile picture or an RSS feed
|
} else if thread.groupModel.groupType == .openGroup { // An open group without a profile picture or an RSS feed
|
||||||
hexEncodedPublicKey = ""
|
publicKey = ""
|
||||||
isRSSFeed = true
|
useFallbackPicture = true
|
||||||
} else { // A closed group
|
} else { // A closed group
|
||||||
var users = MentionsManager.userPublicKeyCache[thread.uniqueId!] ?? []
|
var users = MentionsManager.userPublicKeyCache[thread.uniqueId!] ?? []
|
||||||
users.remove(getUserHexEncodedPublicKey())
|
users.remove(getUserHexEncodedPublicKey())
|
||||||
|
@ -74,9 +75,9 @@ public final class ProfilePictureView : UIView {
|
||||||
if users.count == 1 {
|
if users.count == 1 {
|
||||||
randomUsers.insert(getUserHexEncodedPublicKey(), at: 0) // Ensure the current user is at the back visually
|
randomUsers.insert(getUserHexEncodedPublicKey(), at: 0) // Ensure the current user is at the back visually
|
||||||
}
|
}
|
||||||
hexEncodedPublicKey = randomUsers.count >= 1 ? randomUsers[0] : ""
|
publicKey = randomUsers.count >= 1 ? randomUsers[0] : ""
|
||||||
additionalHexEncodedPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
|
additionalPublicKey = randomUsers.count >= 2 ? randomUsers[1] : ""
|
||||||
isRSSFeed = false
|
useFallbackPicture = false
|
||||||
}
|
}
|
||||||
update()
|
update()
|
||||||
} else { // A one-to-one chat
|
} else { // A one-to-one chat
|
||||||
|
@ -97,7 +98,7 @@ public final class ProfilePictureView : UIView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let size: CGFloat
|
let size: CGFloat
|
||||||
if let additionalHexEncodedPublicKey = additionalHexEncodedPublicKey, !isRSSFeed, openGroupProfilePicture == nil {
|
if let additionalPublicKey = additionalPublicKey, !useFallbackPicture, openGroupProfilePicture == nil {
|
||||||
if self.size == 40 {
|
if self.size == 40 {
|
||||||
size = 32
|
size = 32
|
||||||
} else if self.size == Values.largeProfilePictureSize {
|
} else if self.size == Values.largeProfilePictureSize {
|
||||||
|
@ -110,7 +111,7 @@ public final class ProfilePictureView : UIView {
|
||||||
additionalImageViewWidthConstraint.constant = size
|
additionalImageViewWidthConstraint.constant = size
|
||||||
additionalImageViewHeightConstraint.constant = size
|
additionalImageViewHeightConstraint.constant = size
|
||||||
additionalImageView.isHidden = false
|
additionalImageView.isHidden = false
|
||||||
additionalImageView.image = getProfilePicture(of: size, for: additionalHexEncodedPublicKey)
|
additionalImageView.image = getProfilePicture(of: size, for: additionalPublicKey)
|
||||||
} else {
|
} else {
|
||||||
size = self.size
|
size = self.size
|
||||||
imageViewWidthConstraint.constant = size
|
imageViewWidthConstraint.constant = size
|
||||||
|
@ -118,13 +119,13 @@ public final class ProfilePictureView : UIView {
|
||||||
additionalImageView.isHidden = true
|
additionalImageView.isHidden = true
|
||||||
additionalImageView.image = nil
|
additionalImageView.image = nil
|
||||||
}
|
}
|
||||||
guard hexEncodedPublicKey != nil || openGroupProfilePicture != nil else { return }
|
guard publicKey != nil || openGroupProfilePicture != nil else { return }
|
||||||
imageView.image = isRSSFeed ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: hexEncodedPublicKey))
|
imageView.image = useFallbackPicture ? nil : (openGroupProfilePicture ?? getProfilePicture(of: size, for: publicKey))
|
||||||
imageView.backgroundColor = isRSSFeed ? UIColor(rgbHex: 0x353535) : Colors.unimportant
|
imageView.backgroundColor = useFallbackPicture ? UIColor(rgbHex: 0x353535) : Colors.unimportant
|
||||||
imageView.layer.cornerRadius = size / 2
|
imageView.layer.cornerRadius = size / 2
|
||||||
additionalImageView.layer.cornerRadius = size / 2
|
additionalImageView.layer.cornerRadius = size / 2
|
||||||
imageView.contentMode = isRSSFeed ? .center : .scaleAspectFit
|
imageView.contentMode = useFallbackPicture ? .center : .scaleAspectFit
|
||||||
if isRSSFeed {
|
if useFallbackPicture {
|
||||||
switch size {
|
switch size {
|
||||||
case Values.smallProfilePictureSize..<Values.mediumProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite16")
|
case Values.smallProfilePictureSize..<Values.mediumProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite16")
|
||||||
case Values.mediumProfilePictureSize..<Values.largeProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite24")
|
case Values.mediumProfilePictureSize..<Values.largeProfilePictureSize: imageView.image = #imageLiteral(resourceName: "SessionWhite24")
|
||||||
|
|
Loading…
Reference in New Issue