|
@@ -10,43 +10,55 @@ class ContactCell: UITableViewCell {
|
|
|
|
|
|
public static let cellHeight: CGFloat = 74.5
|
|
|
weak var delegate: ContactCellDelegate?
|
|
|
- var rowIndex = -1
|
|
|
+ var rowIndex = -1 // TODO: is this still needed?
|
|
|
private let badgeSize: CGFloat = 54
|
|
|
private let imgSize: CGFloat = 20
|
|
|
|
|
|
+ lazy var toplineStackView: UIStackView = {
|
|
|
+ let stackView = UIStackView(arrangedSubviews: [titleLabel, timeLabel])
|
|
|
+ stackView.axis = .horizontal
|
|
|
+ return stackView
|
|
|
+ }()
|
|
|
+
|
|
|
+ lazy var bottomlineStackView: UIStackView = {
|
|
|
+ let stackView = UIStackView(arrangedSubviews: [subtitleLabel, deliveryStatusIndicator])
|
|
|
+ stackView.axis = .horizontal
|
|
|
+ stackView.spacing = 10
|
|
|
+ return stackView
|
|
|
+ }()
|
|
|
+
|
|
|
lazy var avatar: InitialsBadge = {
|
|
|
let badge = InitialsBadge(size: badgeSize)
|
|
|
badge.setColor(UIColor.lightGray)
|
|
|
badge.isAccessibilityElement = false
|
|
|
+ let tap = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
|
|
|
+ badge.addGestureRecognizer(tap)
|
|
|
return badge
|
|
|
}()
|
|
|
|
|
|
- let nameLabel: UILabel = {
|
|
|
+ let titleLabel: UILabel = {
|
|
|
let label = UILabel()
|
|
|
label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
|
|
|
label.lineBreakMode = .byTruncatingTail
|
|
|
label.textColor = DcColors.defaultTextColor
|
|
|
label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)
|
|
|
- // label.makeBorder()
|
|
|
return label
|
|
|
-
|
|
|
}()
|
|
|
|
|
|
- let emailLabel: UILabel = {
|
|
|
+ private let timeLabel: UILabel = {
|
|
|
let label = UILabel()
|
|
|
label.font = UIFont.systemFont(ofSize: 14)
|
|
|
label.textColor = UIColor(hexString: "848ba7")
|
|
|
- label.lineBreakMode = .byTruncatingTail
|
|
|
+ label.textAlignment = .right
|
|
|
+ label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 2), for: NSLayoutConstraint.Axis.horizontal)
|
|
|
return label
|
|
|
}()
|
|
|
|
|
|
- private let timeLabel: UILabel = {
|
|
|
+ let subtitleLabel: UILabel = {
|
|
|
let label = UILabel()
|
|
|
label.font = UIFont.systemFont(ofSize: 14)
|
|
|
label.textColor = UIColor(hexString: "848ba7")
|
|
|
- label.textAlignment = .right
|
|
|
- label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 2), for: NSLayoutConstraint.Axis.horizontal)
|
|
|
- // label.makeBorder()
|
|
|
+ label.lineBreakMode = .byTruncatingTail
|
|
|
return label
|
|
|
}()
|
|
|
|
|
@@ -57,6 +69,27 @@ class ContactCell: UITableViewCell {
|
|
|
return view
|
|
|
}()
|
|
|
|
|
|
+ private let archivedIndicator: UIView = {
|
|
|
+ let tintColor = UIColor(hexString: "848ba7")
|
|
|
+ let label = UILabel()
|
|
|
+ label.font = label.font.withSize(14)
|
|
|
+ label.text = String.localized("chat_archived_label")
|
|
|
+ label.textColor = tintColor
|
|
|
+ label.setContentHuggingPriority(.defaultHigh, for: NSLayoutConstraint.Axis.horizontal) // needed so label does not expand to available space
|
|
|
+ let view = UIView()
|
|
|
+ view.layer.borderColor = tintColor.cgColor
|
|
|
+ view.layer.borderWidth = 1
|
|
|
+ view.layer.cornerRadius = 4
|
|
|
+
|
|
|
+ label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ view.addSubview(label)
|
|
|
+ label.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 4).isActive = true
|
|
|
+ label.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
|
|
|
+ label.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -4).isActive = true
|
|
|
+ label.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
|
|
|
+ return view
|
|
|
+ }()
|
|
|
+
|
|
|
private let unreadMessageCounter: MessageCounter = {
|
|
|
let view = MessageCounter(count: 0, size: 20)
|
|
|
return view
|
|
@@ -70,6 +103,10 @@ class ContactCell: UITableViewCell {
|
|
|
setupSubviews()
|
|
|
}
|
|
|
|
|
|
+ required init?(coder: NSCoder) {
|
|
|
+ fatalError("init(coder:) has not been implemented")
|
|
|
+ }
|
|
|
+
|
|
|
private func setupSubviews() {
|
|
|
let margin: CGFloat = 10
|
|
|
|
|
@@ -87,35 +124,17 @@ class ContactCell: UITableViewCell {
|
|
|
deliveryStatusIndicator.heightAnchor.constraint(equalToConstant: 20).isActive = true
|
|
|
deliveryStatusIndicator.widthAnchor.constraint(equalToConstant: 20).isActive = true
|
|
|
|
|
|
- let myStackView = UIStackView()
|
|
|
- myStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
- myStackView.clipsToBounds = true
|
|
|
-
|
|
|
- let toplineStackView = UIStackView()
|
|
|
- toplineStackView.axis = .horizontal
|
|
|
-
|
|
|
- let bottomLineStackView = UIStackView()
|
|
|
- bottomLineStackView.axis = .horizontal
|
|
|
-
|
|
|
- toplineStackView.addArrangedSubview(nameLabel)
|
|
|
- toplineStackView.addArrangedSubview(timeLabel)
|
|
|
-
|
|
|
- bottomLineStackView.addArrangedSubview(emailLabel)
|
|
|
- bottomLineStackView.addArrangedSubview(deliveryStatusIndicator)
|
|
|
- bottomLineStackView.addArrangedSubview(unreadMessageCounter)
|
|
|
-
|
|
|
- contentView.addSubview(myStackView)
|
|
|
- myStackView.leadingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: margin).isActive = true
|
|
|
- myStackView.centerYAnchor.constraint(equalTo: avatar.centerYAnchor).isActive = true
|
|
|
- myStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
|
|
|
- myStackView.axis = .vertical
|
|
|
- myStackView.addArrangedSubview(toplineStackView)
|
|
|
- myStackView.addArrangedSubview(bottomLineStackView)
|
|
|
-
|
|
|
- if delegate != nil {
|
|
|
- let tap = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
|
|
|
- avatar.addGestureRecognizer(tap)
|
|
|
- }
|
|
|
+ let verticalStackView = UIStackView()
|
|
|
+ verticalStackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ verticalStackView.clipsToBounds = true
|
|
|
+
|
|
|
+ contentView.addSubview(verticalStackView)
|
|
|
+ verticalStackView.leadingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: margin).isActive = true
|
|
|
+ verticalStackView.centerYAnchor.constraint(equalTo: avatar.centerYAnchor).isActive = true
|
|
|
+ verticalStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -margin).isActive = true
|
|
|
+ verticalStackView.axis = .vertical
|
|
|
+ verticalStackView.addArrangedSubview(toplineStackView)
|
|
|
+ verticalStackView.addArrangedSubview(bottomlineStackView)
|
|
|
}
|
|
|
|
|
|
func setVerified(isVerified: Bool) {
|
|
@@ -140,6 +159,16 @@ class ContactCell: UITableViewCell {
|
|
|
unreadMessageCounter.setCount(count)
|
|
|
}
|
|
|
|
|
|
+ func setIsArchived(_ isArchived: Bool) {
|
|
|
+ if isArchived {
|
|
|
+ bottomlineStackView.removeArrangedSubview(deliveryStatusIndicator)
|
|
|
+ bottomlineStackView.addArrangedSubview(archivedIndicator)
|
|
|
+ } else {
|
|
|
+ bottomlineStackView.removeArrangedSubview(archivedIndicator)
|
|
|
+ bottomlineStackView.addArrangedSubview(deliveryStatusIndicator)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
func setDeliveryStatusIndicator(_ status: Int) {
|
|
|
var indicatorImage: UIImage?
|
|
|
switch Int32(status) {
|
|
@@ -182,21 +211,15 @@ class ContactCell: UITableViewCell {
|
|
|
}
|
|
|
|
|
|
@objc func onAvatarTapped() {
|
|
|
- if let delegate = delegate {
|
|
|
- if rowIndex == -1 {
|
|
|
- return
|
|
|
- }
|
|
|
- delegate.onAvatarTapped(at: rowIndex)
|
|
|
+ if rowIndex == -1 {
|
|
|
+ return
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- required init?(coder _: NSCoder) {
|
|
|
- fatalError("init(coder:) has not been implemented")
|
|
|
+ delegate?.onAvatarTapped(at: rowIndex)
|
|
|
}
|
|
|
|
|
|
func updateCell(cellViewModel: AvatarCellViewModel) {
|
|
|
// subtitle
|
|
|
- emailLabel.attributedText = cellViewModel.subtitle.boldAt(indexes: cellViewModel.subtitleHighlightIndexes, fontSize: emailLabel.font.pointSize)
|
|
|
+ subtitleLabel.attributedText = cellViewModel.subtitle.boldAt(indexes: cellViewModel.subtitleHighlightIndexes, fontSize: subtitleLabel.font.pointSize)
|
|
|
|
|
|
switch cellViewModel.type {
|
|
|
case .CHAT(let chatData):
|
|
@@ -204,9 +227,9 @@ class ContactCell: UITableViewCell {
|
|
|
|
|
|
// text bold if chat contains unread messages - otherwise hightlight search results if needed
|
|
|
if chatData.unreadMessages > 0 {
|
|
|
- nameLabel.attributedText = NSAttributedString(string: cellViewModel.title, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .bold) ])
|
|
|
+ titleLabel.attributedText = NSAttributedString(string: cellViewModel.title, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .bold) ])
|
|
|
} else {
|
|
|
- nameLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: nameLabel.font.pointSize)
|
|
|
+ titleLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: titleLabel.font.pointSize)
|
|
|
}
|
|
|
|
|
|
if let img = chat.profileImage {
|
|
@@ -219,10 +242,11 @@ class ContactCell: UITableViewCell {
|
|
|
setTimeLabel(chatData.summary.timestamp)
|
|
|
setUnreadMessageCounter(chatData.unreadMessages)
|
|
|
setDeliveryStatusIndicator(chatData.summary.state)
|
|
|
+ setIsArchived(chat.isArchived)
|
|
|
|
|
|
case .CONTACT(let contactData):
|
|
|
let contact = DcContact(id: contactData.contactId)
|
|
|
- nameLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: nameLabel.font.pointSize)
|
|
|
+ titleLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: titleLabel.font.pointSize)
|
|
|
avatar.setName(cellViewModel.title)
|
|
|
avatar.setColor(contact.color)
|
|
|
}
|