Browse Source

Merge pull request #533 from deltachat/fix-chatlist

fix and tweak chatlist
bjoern 5 years ago
parent
commit
786d267c39

+ 23 - 0
deltachat-ios/Assets.xcassets/pinned_chatlist.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "pinned_chatlist.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "pinned_chatlist_2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "pinned_chatlist_3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
deltachat-ios/Assets.xcassets/pinned_chatlist.imageset/pinned_chatlist.png


BIN
deltachat-ios/Assets.xcassets/pinned_chatlist.imageset/pinned_chatlist_2x.png


BIN
deltachat-ios/Assets.xcassets/pinned_chatlist.imageset/pinned_chatlist_3x.png


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

@@ -216,9 +216,7 @@ extension ChatListController: UITableViewDataSource, UITableViewDelegate {
 
 
         cell.subtitleLabel.text = result
         cell.subtitleLabel.text = result
         cell.setTimeLabel(summary.timestamp)
         cell.setTimeLabel(summary.timestamp)
-        cell.setUnreadMessageCounter(unreadMessages)
-        cell.setDeliveryStatusIndicator(summary.state)
-        cell.setIsArchived(showArchive)
+        cell.setStatusIndicators(unreadCount: unreadMessages, status: summary.state, visibility: chat.visibility)
         return cell
         return cell
     }
     }
 
 

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

@@ -15,13 +15,14 @@ class ContactCell: UITableViewCell {
     private let imgSize: CGFloat = 20
     private let imgSize: CGFloat = 20
 
 
     lazy var toplineStackView: UIStackView = {
     lazy var toplineStackView: UIStackView = {
-        let stackView = UIStackView(arrangedSubviews: [titleLabel, timeLabel])
+        let stackView = UIStackView(arrangedSubviews: [titleLabel, pinnedIndicator, timeLabel])
         stackView.axis = .horizontal
         stackView.axis = .horizontal
+        stackView.spacing = 4
         return stackView
         return stackView
     }()
     }()
 
 
     lazy var bottomlineStackView: UIStackView = {
     lazy var bottomlineStackView: UIStackView = {
-        let stackView = UIStackView(arrangedSubviews: [subtitleLabel, deliveryStatusIndicator])
+        let stackView = UIStackView(arrangedSubviews: [subtitleLabel, deliveryStatusIndicator, archivedIndicator, unreadMessageCounter])
         stackView.axis = .horizontal
         stackView.axis = .horizontal
         stackView.spacing = 10
         stackView.spacing = 10
         return stackView
         return stackView
@@ -45,6 +46,17 @@ class ContactCell: UITableViewCell {
         return label
         return label
     }()
     }()
 
 
+    private let pinnedIndicator: UIImageView = {
+        let view = UIImageView()
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.heightAnchor.constraint(equalToConstant: 16).isActive = true
+        view.widthAnchor.constraint(equalToConstant: 16).isActive = true
+        view.tintColor = UIColor(hexString: "848ba7")
+        view.image = #imageLiteral(resourceName: "pinned_chatlist").withRenderingMode(.alwaysTemplate)
+        view.isHidden = true
+        return view
+    }()
+
     private let timeLabel: UILabel = {
     private let timeLabel: UILabel = {
         let label = UILabel()
         let label = UILabel()
         label.font = UIFont.systemFont(ofSize: 14)
         label.font = UIFont.systemFont(ofSize: 14)
@@ -59,6 +71,7 @@ class ContactCell: UITableViewCell {
         label.font = UIFont.systemFont(ofSize: 14)
         label.font = UIFont.systemFont(ofSize: 14)
         label.textColor = UIColor(hexString: "848ba7")
         label.textColor = UIColor(hexString: "848ba7")
         label.lineBreakMode = .byTruncatingTail
         label.lineBreakMode = .byTruncatingTail
+        label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)
         return label
         return label
     }()
     }()
 
 
@@ -76,10 +89,12 @@ class ContactCell: UITableViewCell {
         label.text = String.localized("chat_archived_label")
         label.text = String.localized("chat_archived_label")
         label.textColor = tintColor
         label.textColor = tintColor
         label.setContentHuggingPriority(.defaultHigh, for: NSLayoutConstraint.Axis.horizontal) // needed so label does not expand to available space
         label.setContentHuggingPriority(.defaultHigh, for: NSLayoutConstraint.Axis.horizontal) // needed so label does not expand to available space
+        label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 2), for: NSLayoutConstraint.Axis.horizontal)
         let view = UIView()
         let view = UIView()
         view.layer.borderColor = tintColor.cgColor
         view.layer.borderColor = tintColor.cgColor
         view.layer.borderWidth = 1
         view.layer.borderWidth = 1
-        view.layer.cornerRadius = 4
+        view.layer.cornerRadius = 2
+        view.isHidden = true
 
 
         label.translatesAutoresizingMaskIntoConstraints = false
         label.translatesAutoresizingMaskIntoConstraints = false
         view.addSubview(label)
         view.addSubview(label)
@@ -92,6 +107,7 @@ class ContactCell: UITableViewCell {
 
 
     private let unreadMessageCounter: MessageCounter = {
     private let unreadMessageCounter: MessageCounter = {
         let view = MessageCounter(count: 0, size: 20)
         let view = MessageCounter(count: 0, size: 20)
+        view.isHidden = true
         return view
         return view
     }()
     }()
 
 
@@ -155,46 +171,42 @@ class ContactCell: UITableViewCell {
         avatar.setName(name)
         avatar.setName(name)
     }
     }
 
 
-    func setUnreadMessageCounter(_ count: Int) {
-        unreadMessageCounter.setCount(count)
-    }
+    func setStatusIndicators(unreadCount: Int, status: Int, visibility: Int32) {
+        if visibility==DC_CHAT_VISIBILITY_ARCHIVED {
+            pinnedIndicator.isHidden = true
+            unreadMessageCounter.isHidden = true
+            deliveryStatusIndicator.isHidden = true
+            archivedIndicator.isHidden = false
+        } else if unreadCount > 0 {
+            unreadMessageCounter.setCount(unreadCount)
 
 
-    func setIsArchived(_ isArchived: Bool) {
-        if isArchived {
+            pinnedIndicator.isHidden = !(visibility==DC_CHAT_VISIBILITY_PINNED)
+            unreadMessageCounter.isHidden = false
             deliveryStatusIndicator.isHidden = true
             deliveryStatusIndicator.isHidden = true
-            bottomlineStackView.removeArrangedSubview(deliveryStatusIndicator)
-            bottomlineStackView.addArrangedSubview(archivedIndicator)
+            archivedIndicator.isHidden = true
         } else {
         } else {
-            deliveryStatusIndicator.isHidden = false
-            bottomlineStackView.removeArrangedSubview(archivedIndicator)
-            bottomlineStackView.addArrangedSubview(deliveryStatusIndicator)
-        }
-    }
+            switch Int32(status) {
+            case DC_STATE_OUT_PENDING, DC_STATE_OUT_PREPARING:
+                deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_hourglass_empty_36pt").withRenderingMode(.alwaysTemplate)
+                deliveryStatusIndicator.tintColor = UIColor.black.withAlphaComponent(0.5)
+            case DC_STATE_OUT_DELIVERED:
+                deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_done_36pt").withRenderingMode(.alwaysTemplate)
+                deliveryStatusIndicator.tintColor = DcColors.checkmarkGreen
+            case DC_STATE_OUT_FAILED:
+                deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_error_36pt").withRenderingMode(.alwaysTemplate)
+                deliveryStatusIndicator.tintColor = UIColor.red
+            case DC_STATE_OUT_MDN_RCVD:
+                deliveryStatusIndicator.image = #imageLiteral(resourceName: "ic_done_all_36pt").withRenderingMode(.alwaysTemplate)
+                deliveryStatusIndicator.tintColor = DcColors.checkmarkGreen
+            default:
+                deliveryStatusIndicator.image = nil
+            }
 
 
-    func setDeliveryStatusIndicator(_ status: Int) {
-        var indicatorImage: UIImage?
-        switch Int32(status) {
-        case DC_STATE_OUT_PENDING, DC_STATE_OUT_PREPARING:
-            indicatorImage = #imageLiteral(resourceName: "ic_hourglass_empty_36pt").withRenderingMode(.alwaysTemplate)
-            deliveryStatusIndicator.tintColor = UIColor.black.withAlphaComponent(0.5)
-        case DC_STATE_OUT_DELIVERED:
-            indicatorImage = #imageLiteral(resourceName: "ic_done_36pt").withRenderingMode(.alwaysTemplate)
-            deliveryStatusIndicator.tintColor = DcColors.checkmarkGreen
-        case DC_STATE_OUT_FAILED:
-            indicatorImage = #imageLiteral(resourceName: "ic_error_36pt").withRenderingMode(.alwaysTemplate)
-            deliveryStatusIndicator.tintColor = UIColor.red
-        case DC_STATE_OUT_MDN_RCVD:
-            indicatorImage = #imageLiteral(resourceName: "ic_done_all_36pt").withRenderingMode(.alwaysTemplate)
-            deliveryStatusIndicator.tintColor = DcColors.checkmarkGreen
-        default:
-            break
-        }
-        if indicatorImage != nil && unreadMessageCounter.isHidden {
-            deliveryStatusIndicator.isHidden = false
-        } else {
-            deliveryStatusIndicator.isHidden = true
+            pinnedIndicator.isHidden = !(visibility==DC_CHAT_VISIBILITY_PINNED)
+            unreadMessageCounter.isHidden = true
+            deliveryStatusIndicator.isHidden = deliveryStatusIndicator.image == nil ? true : false
+            archivedIndicator.isHidden = true
         }
         }
-        deliveryStatusIndicator.image = indicatorImage
     }
     }
 
 
     func setTimeLabel(_ timestamp: Int64?) {
     func setTimeLabel(_ timestamp: Int64?) {
@@ -242,15 +254,14 @@ class ContactCell: UITableViewCell {
             }
             }
             setVerified(isVerified: chat.isVerified)
             setVerified(isVerified: chat.isVerified)
             setTimeLabel(chatData.summary.timestamp)
             setTimeLabel(chatData.summary.timestamp)
-            setUnreadMessageCounter(chatData.unreadMessages)
-            setDeliveryStatusIndicator(chatData.summary.state)
-            setIsArchived(chat.isArchived)
+            setStatusIndicators(unreadCount: chatData.unreadMessages, status: chatData.summary.state, visibility: chat.visibility)
 
 
         case .CONTACT(let contactData):
         case .CONTACT(let contactData):
             let contact = DcContact(id: contactData.contactId)
             let contact = DcContact(id: contactData.contactId)
             titleLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: titleLabel.font.pointSize)
             titleLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: titleLabel.font.pointSize)
             avatar.setName(cellViewModel.title)
             avatar.setName(cellViewModel.title)
             avatar.setColor(contact.color)
             avatar.setColor(contact.color)
+            setStatusIndicators(unreadCount: 0, status: 0, visibility: 0)
         }
         }
     }
     }
 }
 }

+ 0 - 2
deltachat-ios/View/MessageCounter.swift

@@ -35,7 +35,6 @@ class MessageCounter: UIView {
                                  label.constraintAlignTrailingTo(self),
                                  label.constraintAlignTrailingTo(self),
                                  label.constraintCenterYTo(self) ]
                                  label.constraintCenterYTo(self) ]
         self.addConstraints(labelConstraints)
         self.addConstraints(labelConstraints)
-        isHidden = true
     }
     }
 
 
     required init?(coder _: NSCoder) {
     required init?(coder _: NSCoder) {
@@ -55,7 +54,6 @@ class MessageCounter: UIView {
             addConstraint(widthConstraint!)
             addConstraint(widthConstraint!)
         }
         }
         label.attributedText = countString
         label.attributedText = countString
-        isHidden = (msgNo <= 0)
     }
     }
 
 
 }
 }