|
@@ -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:
|