Răsfoiți Sursa

Merge pull request #524 from deltachat/archivedTag

Chat cells have archive tag
bjoern 5 ani în urmă
părinte
comite
556d02847c

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

@@ -166,7 +166,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
         let summary = chatList.getSummary(index: row)
         let unreadMessages = dcContext.getUnreadMessages(chatId: chatId)
 
-        cell.nameLabel.attributedText = (unreadMessages > 0) ?
+        cell.titleLabel.attributedText = (unreadMessages > 0) ?
             NSAttributedString(string: chat.name, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .bold) ]) :
             NSAttributedString(string: chat.name, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .medium) ])
 
@@ -198,11 +198,11 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
             result = "\(result1)\(result2)"
         }
 
-        cell.emailLabel.text = result
+        cell.subtitleLabel.text = result
         cell.setTimeLabel(summary.timestamp)
         cell.setUnreadMessageCounter(unreadMessages)
         cell.setDeliveryStatusIndicator(summary.state)
-
+        cell.setIsArchived(showArchive)
         return cell
     }
 

+ 2 - 2
deltachat-ios/Controller/GroupChatDetailViewController.swift

@@ -186,8 +186,8 @@ extension GroupChatDetailViewController: UITableViewDelegate, UITableViewDataSou
                 if let contactCell = cell as? ContactCell {
                     let contact = groupMembers[row - sectionMembersStaticRowCount]
                     let displayName = contact.displayName
-                    contactCell.nameLabel.text = displayName
-                    contactCell.emailLabel.text = contact.email
+                    contactCell.titleLabel.text = displayName
+                    contactCell.subtitleLabel.text = contact.email
                     contactCell.avatar.setName(displayName)
                     contactCell.avatar.setColor(contact.color)
                     if let profileImage = contact.profileImage {

+ 8 - 8
deltachat-ios/Controller/GroupMembersViewController.swift

@@ -420,11 +420,11 @@ class GroupMembersViewController: UITableViewController, UISearchResultsUpdating
         let contact = contactWithHighlight.contact
         let displayName = contact.displayName
 
-        let emailLabelFontSize = cell.emailLabel.font.pointSize
-        let nameLabelFontSize = cell.nameLabel.font.pointSize
+        let emailLabelFontSize = cell.subtitleLabel.font.pointSize
+        let nameLabelFontSize = cell.titleLabel.font.pointSize
 
-        cell.nameLabel.text = displayName
-        cell.emailLabel.text = contact.email
+        cell.titleLabel.text = displayName
+        cell.subtitleLabel.text = contact.email
         cell.avatar.setName(displayName)
         cell.avatar.setColor(contact.color)
         if let profileImage = contact.profileImage {
@@ -434,15 +434,15 @@ class GroupMembersViewController: UITableViewController, UISearchResultsUpdating
 
         if let emailHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({ $0.contactDetail == .EMAIL }).first {
             // gets here when contact is a result of current search -> highlights relevant indexes
-            cell.emailLabel.attributedText = contact.email.boldAt(indexes: emailHighlightedIndexes.indexes, fontSize: emailLabelFontSize)
+            cell.subtitleLabel.attributedText = contact.email.boldAt(indexes: emailHighlightedIndexes.indexes, fontSize: emailLabelFontSize)
         } else {
-            cell.emailLabel.attributedText = contact.email.boldAt(indexes: [], fontSize: emailLabelFontSize)
+            cell.subtitleLabel.attributedText = contact.email.boldAt(indexes: [], fontSize: emailLabelFontSize)
         }
 
         if let nameHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({ $0.contactDetail == .NAME }).first {
-            cell.nameLabel.attributedText = displayName.boldAt(indexes: nameHighlightedIndexes.indexes, fontSize: nameLabelFontSize)
+            cell.titleLabel.attributedText = displayName.boldAt(indexes: nameHighlightedIndexes.indexes, fontSize: nameLabelFontSize)
         } else {
-            cell.nameLabel.attributedText = displayName.boldAt(indexes: [], fontSize: nameLabelFontSize)
+            cell.titleLabel.attributedText = displayName.boldAt(indexes: [], fontSize: nameLabelFontSize)
         }
     }
 

+ 8 - 8
deltachat-ios/Controller/NewChatViewController.swift

@@ -322,11 +322,11 @@ class NewChatViewController: UITableViewController {
         let contact = contactWithHighlight.contact
         let displayName = contact.displayName
 
-        let emailLabelFontSize = cell.emailLabel.font.pointSize
-        let nameLabelFontSize = cell.nameLabel.font.pointSize
+        let emailLabelFontSize = cell.subtitleLabel.font.pointSize
+        let nameLabelFontSize = cell.titleLabel.font.pointSize
 
-        cell.nameLabel.text = displayName
-        cell.emailLabel.text = contact.email
+        cell.titleLabel.text = displayName
+        cell.subtitleLabel.text = contact.email
         cell.avatar.setName(displayName)
         cell.avatar.setColor(contact.color)
         if let profileImage = contact.profileImage {
@@ -336,15 +336,15 @@ class NewChatViewController: UITableViewController {
 
         if let emailHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({ $0.contactDetail == .EMAIL }).first {
             // gets here when contact is a result of current search -> highlights relevant indexes
-            cell.emailLabel.attributedText = contact.email.boldAt(indexes: emailHighlightedIndexes.indexes, fontSize: emailLabelFontSize)
+            cell.subtitleLabel.attributedText = contact.email.boldAt(indexes: emailHighlightedIndexes.indexes, fontSize: emailLabelFontSize)
         } else {
-            cell.emailLabel.attributedText = contact.email.boldAt(indexes: [], fontSize: emailLabelFontSize)
+            cell.subtitleLabel.attributedText = contact.email.boldAt(indexes: [], fontSize: emailLabelFontSize)
         }
 
         if let nameHighlightedIndexes = contactWithHighlight.indexesToHighlight.filter({ $0.contactDetail == .NAME }).first {
-            cell.nameLabel.attributedText = displayName.boldAt(indexes: nameHighlightedIndexes.indexes, fontSize: nameLabelFontSize)
+            cell.titleLabel.attributedText = displayName.boldAt(indexes: nameHighlightedIndexes.indexes, fontSize: nameLabelFontSize)
         } else {
-            cell.nameLabel.attributedText = displayName.boldAt(indexes: [], fontSize: nameLabelFontSize)
+            cell.titleLabel.attributedText = displayName.boldAt(indexes: [], fontSize: nameLabelFontSize)
         }
     }
 

+ 2 - 2
deltachat-ios/Controller/NewGroupController.swift

@@ -181,8 +181,8 @@ class NewGroupController: UITableViewController, MediaPickerDelegate {
             if let contactCell = cell as? ContactCell {
                 let contact = DcContact(id: groupContactIds[row])
                 let displayName = contact.displayName
-                contactCell.nameLabel.text = displayName
-                contactCell.emailLabel.text = contact.email
+                contactCell.titleLabel.text = displayName
+                contactCell.subtitleLabel.text = contact.email
                 contactCell.avatar.setName(displayName)
                 contactCell.avatar.setColor(contact.color)
                 if let profileImage = contact.profileImage {

+ 4 - 0
deltachat-ios/DC/Wrapper.swift

@@ -496,6 +496,10 @@ class DcChat {
         return dc_chat_is_verified(chatPointer) > 0
     }
 
+    var isArchived: Bool {
+        return Int(dc_chat_get_archived(chatPointer)) == 1
+    }
+
     var contactIds: [Int] {
         return Utils.copyAndFreeArray(inputArray: dc_get_chat_contacts(mailboxPointer, UInt32(id)))
     }

+ 76 - 52
deltachat-ios/View/ContactCell.swift

@@ -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)
         }

+ 2 - 2
deltachat-ios/View/ContactDetailHeader.swift

@@ -13,7 +13,7 @@ class ContactDetailHeader: ContactCell {
     }
 
     func updateDetails(title: String?, subtitle: String?) {
-        nameLabel.text = title
-        emailLabel.text = subtitle
+        titleLabel.text = title
+        subtitleLabel.text = subtitle
     }
 }

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

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