Browse Source

theme sent state line in message bubble as on Android

cyberta 3 years ago
parent
commit
6380d6d7c3

+ 3 - 0
DcCore/DcCore/Helper/DcColors.swift

@@ -23,6 +23,9 @@ public struct DcColors {
     public static let defaultTextColor = UIColor.themeColor(light: .darkText, dark: .white)
     public static let grayTextColor = UIColor.themeColor(light: .darkGray, dark: .lightGray)
     public static let grayDateColor = UIColor.themeColor(lightHex: "999999", darkHex: "bbbbbb") // slight variations of lightGray (#aaaaaa)
+    public static let coreDark05 = UIColor.init(hexString: "EFEFEF") // naming according to DC Android
+    public static let grey50 = UIColor.init(hexString: "808080") // naming according to DC Android
+    public static let incomingMessageSecondaryTextColor = UIColor.themeColor(light: grey50, dark: coreDark05)
     public static let middleGray = UIColor(hexString: "848ba7")
     public static let secondaryTextColor = UIColor.themeColor(lightHex: "848ba7", darkHex: "a5abc0")
     public static let inputFieldColor =  UIColor.themeColor(

+ 18 - 3
deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift

@@ -49,8 +49,13 @@ public class BaseMessageCell: UITableViewCell {
         set {
             mainContentAboveActionBtnConstraint?.isActive = !newValue
             mainContentUnderBottomLabelConstraint?.isActive = newValue
-            bottomLabel.backgroundColor = newValue ?
-                UIColor(alpha: 200, red: 50, green: 50, blue: 50) :
+        }
+    }
+
+    public var showBottomLabelBackground: Bool {
+        didSet {
+            bottomLabel.backgroundColor = showBottomLabelBackground ?
+                DcColors.systemMessageBackgroundColor :
                 UIColor(alpha: 0, red: 0, green: 0, blue: 0)
         }
     }
@@ -173,6 +178,7 @@ public class BaseMessageCell: UITableViewCell {
 
     override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
         showSelectionBackground = false
+        showBottomLabelBackground = false
         super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
         clipsToBounds = false
         backgroundColor = .none
@@ -231,6 +237,7 @@ public class BaseMessageCell: UITableViewCell {
 
         topCompactView = false
         bottomCompactView = false
+        showBottomLabelBackground = false
         isActionButtonHidden = true
         
 
@@ -346,8 +353,16 @@ public class BaseMessageCell: UITableViewCell {
                                           color: getBackgroundColor(dcContext: dcContext, message: msg))
 
         if !msg.isInfo {
+            var tintColor: UIColor
+            if showBottomLabelBackground {
+                tintColor = DcColors.coreDark05
+            } else if msg.isFromCurrentSender {
+                tintColor = DcColors.checkmarkGreen
+            } else {
+                tintColor = DcColors.incomingMessageSecondaryTextColor
+            }
             bottomLabel.attributedText = MessageUtils.getFormattedBottomLine(message: msg,
-                                                                             tintColor: !(isTransparent || bottomCompactView) ? DcColors.checkmarkGreen : nil)
+                                                                             tintColor: tintColor)
         }
 
         if let quoteText = msg.quoteText {

+ 1 - 0
deltachat-ios/Chat/Views/Cells/ImageTextCell.swift

@@ -46,6 +46,7 @@ class ImageTextCell: BaseMessageCell {
         messageLabel.text = msg.text
         let hasEmptyText = msg.text?.isEmpty ?? true
         bottomCompactView = msg.type != DC_MSG_STICKER && !msg.hasHtml && hasEmptyText
+        showBottomLabelBackground = !msg.hasHtml && hasEmptyText
         mainContentView.spacing = msg.text?.isEmpty ?? false ? 0 : 6
         topCompactView = msg.quoteText == nil ? true : false
         isTransparent = msg.type == DC_MSG_STICKER

+ 1 - 1
deltachat-ios/Chat/Views/Cells/VideoInviteCell.swift

@@ -129,7 +129,7 @@ public class VideoInviteCell: UITableViewCell {
             avatarView.setImage(profileImage)
         }
 
-        bottomLabel.attributedText = MessageUtils.getFormattedBottomLine(message: msg, tintColor: nil)
+        bottomLabel.attributedText = MessageUtils.getFormattedBottomLine(message: msg, tintColor: DcColors.coreDark05)
         
         var corners: UIRectCorner = []
         corners.formUnion(.topLeft)

+ 14 - 26
deltachat-ios/Helper/MessageUtils.swift

@@ -4,7 +4,7 @@ import DcCore
 
 
 public class MessageUtils {
-    static func getFormattedBottomLine(message: DcMsg, tintColor: UIColor?) -> NSAttributedString {
+    static func getFormattedBottomLine(message: DcMsg, tintColor: UIColor) -> NSAttributedString {
 
         var paragraphStyle = NSParagraphStyle()
         if let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle {
@@ -13,7 +13,7 @@ public class MessageUtils {
 
         var timestampAttributes: [NSAttributedString.Key: Any] = [
             .font: UIFont.preferredFont(for: .caption1, weight: .regular),
-            .foregroundColor: DcColors.grayDateColor,
+            .foregroundColor: tintColor,
             .paragraphStyle: paragraphStyle,
         ]
 
@@ -22,9 +22,6 @@ public class MessageUtils {
             if let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle {
                 style.alignment = .right
                 timestampAttributes[.paragraphStyle] = style
-                if let tintColor = tintColor {
-                    timestampAttributes[.foregroundColor] = tintColor
-                }
             }
 
             text.append(NSAttributedString(string: message.formattedSentDate(), attributes: timestampAttributes))
@@ -39,34 +36,29 @@ public class MessageUtils {
             let messageState = message.downloadState == DC_DOWNLOAD_IN_PROGRESS ?
                 Int(DC_DOWNLOAD_IN_PROGRESS) :
                 message.state
-            attachSendingState(messageState, to: text)
+            attachSendingState(messageState, to: text, color: tintColor)
             return text
         }
 
         if message.downloadState == DC_DOWNLOAD_IN_PROGRESS {
-            attachSendingState(Int(DC_DOWNLOAD_IN_PROGRESS), to: text)
+            attachSendingState(Int(DC_DOWNLOAD_IN_PROGRESS), to: text, color: tintColor)
         }
         
         text.append(NSAttributedString(string: message.formattedSentDate(), attributes: timestampAttributes))
         if message.showPadlock() {
-            attachPadlock(to: text)
+            attachPadlock(to: text, color: tintColor)
         }
 
         if message.hasLocation {
-            attachLocation(to: text)
+            attachLocation(to: text, color: tintColor)
         }
 
         return text
     }
 
-    private static func attachLocation(to text: NSMutableAttributedString, color: UIColor? = nil) {
+    private static func attachLocation(to text: NSMutableAttributedString, color: UIColor) {
         let imageAttachment = NSTextAttachment()
-
-        if let color = color {
-            imageAttachment.image = UIImage(named: "ic_location")?.maskWithColor(color: color)?.scaleDownImage(toMax: 12)
-        } else {
-            imageAttachment.image = UIImage(named: "ic_location")?.maskWithColor(color: DcColors.grayDateColor)?.scaleDownImage(toMax: 12)
-        }
+        imageAttachment.image = UIImage(named: "ic_location")?.maskWithColor(color: color)?.scaleDownImage(toMax: 12)
 
         let imageString = NSMutableAttributedString(attachment: imageAttachment)
         imageString.addAttributes([NSAttributedString.Key.baselineOffset: -0.5], range: NSRange(location: 0, length: 1))
@@ -74,13 +66,9 @@ public class MessageUtils {
         text.append(imageString)
     }
 
-    private static func attachPadlock(to text: NSMutableAttributedString, color: UIColor? = nil) {
+    private static func attachPadlock(to text: NSMutableAttributedString, color: UIColor) {
         let imageAttachment = NSTextAttachment()
-        if let color = color {
-            imageAttachment.image = UIImage(named: "ic_lock")?.maskWithColor(color: color)?.scaleDownImage(toMax: 15)
-        } else {
-            imageAttachment.image = UIImage(named: "ic_lock")?.scaleDownImage(toMax: 15)
-        }
+        imageAttachment.image = UIImage(named: "ic_lock")?.maskWithColor(color: color)?.scaleDownImage(toMax: 15)
         let imageString = NSMutableAttributedString(attachment: imageAttachment)
         imageString.addAttributes([NSAttributedString.Key.baselineOffset: -0.5], range: NSRange(location: 0, length: 1))
         text.append(NSAttributedString(string: " "))
@@ -102,18 +90,18 @@ public class MessageUtils {
         }
     }
 
-    private static func attachSendingState(_ state: Int, to text: NSMutableAttributedString) {
+    private static func attachSendingState(_ state: Int, to text: NSMutableAttributedString, color: UIColor) {
         let imageAttachment = NSTextAttachment()
         var offset: CGFloat = -2
 
         switch Int32(state) {
         case DC_STATE_OUT_PENDING, DC_STATE_OUT_PREPARING, DC_DOWNLOAD_IN_PROGRESS:
-            imageAttachment.image = #imageLiteral(resourceName: "ic_hourglass_empty_white_36pt").scaleDownImage(toMax: 14)?.maskWithColor(color: DcColors.grayDateColor)
+            imageAttachment.image = #imageLiteral(resourceName: "ic_hourglass_empty_white_36pt").scaleDownImage(toMax: 14)?.maskWithColor(color: DcColors.coreDark05)
         case DC_STATE_OUT_DELIVERED:
-            imageAttachment.image = #imageLiteral(resourceName: "ic_done_36pt").scaleDownImage(toMax: 16)?.sd_croppedImage(with: CGRect(x: 0, y: 4, width: 16, height: 14))
+            imageAttachment.image = #imageLiteral(resourceName: "ic_done_36pt").scaleDownImage(toMax: 16)?.sd_croppedImage(with: CGRect(x: 0, y: 4, width: 16, height: 14))?.maskWithColor(color: color)
             offset = -3.5
         case DC_STATE_OUT_MDN_RCVD:
-            imageAttachment.image = #imageLiteral(resourceName: "ic_done_all_36pt").scaleDownImage(toMax: 16)?.sd_croppedImage(with: CGRect(x: 0, y: 4, width: 16, height: 14))
+            imageAttachment.image = #imageLiteral(resourceName: "ic_done_all_36pt").scaleDownImage(toMax: 16)?.sd_croppedImage(with: CGRect(x: 0, y: 4, width: 16, height: 14))?.maskWithColor(color: color)
             text.append(NSAttributedString(string: "\u{202F}"))
             offset = -3.5
         case DC_STATE_OUT_FAILED: