Ver código fonte

contact cell now has archived tag - stackviews now attributes of cell so they can be modified

nayooti 5 anos atrás
pai
commit
7ddefdcdb6

+ 1 - 1
deltachat-ios/Controller/ChatListController.swift

@@ -202,7 +202,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
         cell.setTimeLabel(summary.timestamp)
         cell.setUnreadMessageCounter(unreadMessages)
         cell.setDeliveryStatusIndicator(summary.state)
-
+        cell.setIsArchived(showArchive)
         return cell
     }
 

+ 66 - 41
deltachat-ios/View/ContactCell.swift

@@ -10,14 +10,29 @@ 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: [nameLabel, timeLabel])
+        stackView.axis = .horizontal
+        return stackView
+    }()
+
+    lazy var bottomlineStackView: UIStackView = {
+        let stackView = UIStackView(arrangedSubviews: [emailLabel, 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
     }()
 
@@ -27,7 +42,6 @@ class ContactCell: UITableViewCell {
         label.lineBreakMode = .byTruncatingTail
         label.textColor = DcColors.defaultTextColor
         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)
-        // label.makeBorder()
         return label
 
     }()
@@ -46,7 +60,6 @@ class ContactCell: UITableViewCell {
         label.textColor = UIColor(hexString: "848ba7")
         label.textAlignment = .right
         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 2), for: NSLayoutConstraint.Axis.horizontal)
-        // label.makeBorder()
         return label
     }()
 
@@ -57,6 +70,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 +104,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 +125,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 +160,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,16 +212,10 @@ 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) {
@@ -219,6 +243,7 @@ class ContactCell: UITableViewCell {
             setTimeLabel(chatData.summary.timestamp)
             setUnreadMessageCounter(chatData.unreadMessages)
             setDeliveryStatusIndicator(chatData.summary.state)
+            setIsArchived(chatData.isArchived)
 
         case .CONTACT(let contactData):
             let contact = DcContact(id: contactData.contactId)

+ 1 - 0
deltachat-ios/ViewModel/ContactCellViewModel.swift

@@ -25,6 +25,7 @@ struct ChatCellData {
     let chatId: Int
     let summary: DcLot
     let unreadMessages: Int
+    let isArchived: Bool
 }
 
 class ContactCellViewModel: AvatarCellViewModel {

+ 1 - 1
deltachat-ios/ViewModel/ContactDetailViewModel.swift

@@ -70,7 +70,7 @@ class ContactDetailViewModel: ContactDetailViewModelProtocol {
         let summary = sharedChats.getSummary(index: index)
         let unreadMessages = context.getUnreadMessages(chatId: chatId)
 
-        let cellData = ChatCellData(chatId: chatId, summary: summary, unreadMessages: unreadMessages)
+        let cellData = ChatCellData(chatId: chatId, summary: summary, unreadMessages: unreadMessages, isArchived: false)
         let cellViewModel = ChatCellViewModel(chatData: cellData)
         cell.updateCell(cellViewModel: cellViewModel)
     }

+ 1 - 1
deltachat-ios/libraries/deltachat-core-rust

@@ -1 +1 @@
-Subproject commit 8b4edc46a7ac31e276beb0922e87f0a7f17bc9f7
+Subproject commit 7ea0e4d4dbc8b3b9ebc32f25df7d7cc3cb54ccc9