|
@@ -10,11 +10,11 @@ public class BaseMessageCell: UITableViewCell {
|
|
private var trailingConstraintCurrentSender: NSLayoutConstraint?
|
|
private var trailingConstraintCurrentSender: NSLayoutConstraint?
|
|
private var mainContentBelowTopLabelConstraint: NSLayoutConstraint?
|
|
private var mainContentBelowTopLabelConstraint: NSLayoutConstraint?
|
|
private var mainContentUnderTopLabelConstraint: NSLayoutConstraint?
|
|
private var mainContentUnderTopLabelConstraint: NSLayoutConstraint?
|
|
- private var mainContentAboveFullMessageBtnConstraint: NSLayoutConstraint?
|
|
|
|
|
|
+ private var mainContentAboveActionBtnConstraint: NSLayoutConstraint?
|
|
private var mainContentUnderBottomLabelConstraint: NSLayoutConstraint?
|
|
private var mainContentUnderBottomLabelConstraint: NSLayoutConstraint?
|
|
private var mainContentViewLeadingConstraint: NSLayoutConstraint?
|
|
private var mainContentViewLeadingConstraint: NSLayoutConstraint?
|
|
private var mainContentViewTrailingConstraint: NSLayoutConstraint?
|
|
private var mainContentViewTrailingConstraint: NSLayoutConstraint?
|
|
- private var fullMessageZeroHeightConstraint: NSLayoutConstraint?
|
|
|
|
|
|
+ private var actionBtnZeroHeightConstraint: NSLayoutConstraint?
|
|
|
|
|
|
public var mainContentViewHorizontalPadding: CGFloat {
|
|
public var mainContentViewHorizontalPadding: CGFloat {
|
|
get {
|
|
get {
|
|
@@ -46,7 +46,7 @@ public class BaseMessageCell: UITableViewCell {
|
|
return mainContentUnderBottomLabelConstraint?.isActive ?? false
|
|
return mainContentUnderBottomLabelConstraint?.isActive ?? false
|
|
}
|
|
}
|
|
set {
|
|
set {
|
|
- mainContentAboveFullMessageBtnConstraint?.isActive = !newValue
|
|
|
|
|
|
+ mainContentAboveActionBtnConstraint?.isActive = !newValue
|
|
mainContentUnderBottomLabelConstraint?.isActive = newValue
|
|
mainContentUnderBottomLabelConstraint?.isActive = newValue
|
|
bottomLabel.backgroundColor = newValue ?
|
|
bottomLabel.backgroundColor = newValue ?
|
|
UIColor(alpha: 200, red: 50, green: 50, blue: 50) :
|
|
UIColor(alpha: 200, red: 50, green: 50, blue: 50) :
|
|
@@ -54,15 +54,14 @@ public class BaseMessageCell: UITableViewCell {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public var isFullMessageButtonHidden: Bool {
|
|
|
|
|
|
+ public var isActionButtonHidden: Bool {
|
|
get {
|
|
get {
|
|
- return fullMessageButton.isHidden
|
|
|
|
|
|
+ return actionButton.isHidden
|
|
}
|
|
}
|
|
set {
|
|
set {
|
|
- mainContentAboveFullMessageBtnConstraint?.constant = newValue ? -2 : 8
|
|
|
|
- fullMessageButton.setTitle(newValue ? "" : String.localized("show_full_message"), for: .normal)
|
|
|
|
- fullMessageZeroHeightConstraint?.isActive = newValue
|
|
|
|
- fullMessageButton.isHidden = newValue
|
|
|
|
|
|
+ mainContentAboveActionBtnConstraint?.constant = newValue ? -2 : 8
|
|
|
|
+ actionBtnZeroHeightConstraint?.isActive = newValue
|
|
|
|
+ actionButton.isHidden = newValue
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -128,14 +127,15 @@ public class BaseMessageCell: UITableViewCell {
|
|
return view
|
|
return view
|
|
}()
|
|
}()
|
|
|
|
|
|
- lazy var fullMessageButton: DynamicFontButton = {
|
|
|
|
|
|
+ lazy var actionButton: DynamicFontButton = {
|
|
let button = DynamicFontButton()
|
|
let button = DynamicFontButton()
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
button.translatesAutoresizingMaskIntoConstraints = false
|
|
button.setTitleColor(.systemBlue, for: .normal)
|
|
button.setTitleColor(.systemBlue, for: .normal)
|
|
button.setTitleColor(.gray, for: .highlighted)
|
|
button.setTitleColor(.gray, for: .highlighted)
|
|
button.titleLabel?.lineBreakMode = .byWordWrapping
|
|
button.titleLabel?.lineBreakMode = .byWordWrapping
|
|
button.titleLabel?.textAlignment = .left
|
|
button.titleLabel?.textAlignment = .left
|
|
- button.addTarget(self, action: #selector(onFullMessageButtonTapped), for: .touchUpInside)
|
|
|
|
|
|
+ button.contentHorizontalAlignment = .left
|
|
|
|
+ button.addTarget(self, action: #selector(onActionButtonTapped), for: .touchUpInside)
|
|
button.titleLabel?.font = UIFont.preferredFont(for: .body, weight: .regular)
|
|
button.titleLabel?.font = UIFont.preferredFont(for: .body, weight: .regular)
|
|
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
|
button.titleLabel?.adjustsFontForContentSizeCategory = true
|
|
button.contentEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0)
|
|
button.contentEdgeInsets = UIEdgeInsets(top: 8, left: 0, bottom: 0, right: 0)
|
|
@@ -184,7 +184,7 @@ public class BaseMessageCell: UITableViewCell {
|
|
contentView.addSubview(messageBackgroundContainer)
|
|
contentView.addSubview(messageBackgroundContainer)
|
|
messageBackgroundContainer.addSubview(mainContentView)
|
|
messageBackgroundContainer.addSubview(mainContentView)
|
|
messageBackgroundContainer.addSubview(topLabel)
|
|
messageBackgroundContainer.addSubview(topLabel)
|
|
- messageBackgroundContainer.addSubview(fullMessageButton)
|
|
|
|
|
|
+ messageBackgroundContainer.addSubview(actionButton)
|
|
messageBackgroundContainer.addSubview(bottomLabel)
|
|
messageBackgroundContainer.addSubview(bottomLabel)
|
|
contentView.addSubview(avatarView)
|
|
contentView.addSubview(avatarView)
|
|
|
|
|
|
@@ -198,11 +198,11 @@ public class BaseMessageCell: UITableViewCell {
|
|
topLabel.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 8),
|
|
topLabel.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 8),
|
|
messageBackgroundContainer.constraintAlignTopTo(contentView, paddingTop: 3),
|
|
messageBackgroundContainer.constraintAlignTopTo(contentView, paddingTop: 3),
|
|
messageBackgroundContainer.constraintAlignBottomTo(contentView, paddingBottom: 3),
|
|
messageBackgroundContainer.constraintAlignBottomTo(contentView, paddingBottom: 3),
|
|
- fullMessageButton.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 12),
|
|
|
|
- fullMessageButton.constraintAlignTrailingMaxTo(messageBackgroundContainer, paddingTrailing: 12),
|
|
|
|
|
|
+ actionButton.constraintAlignLeadingTo(messageBackgroundContainer, paddingLeading: 12),
|
|
|
|
+ actionButton.constraintAlignTrailingTo(messageBackgroundContainer, paddingTrailing: 12),
|
|
bottomLabel.constraintAlignLeadingMaxTo(messageBackgroundContainer, paddingLeading: 8),
|
|
bottomLabel.constraintAlignLeadingMaxTo(messageBackgroundContainer, paddingLeading: 8),
|
|
bottomLabel.constraintAlignTrailingTo(messageBackgroundContainer, paddingTrailing: 8),
|
|
bottomLabel.constraintAlignTrailingTo(messageBackgroundContainer, paddingTrailing: 8),
|
|
- bottomLabel.constraintToBottomOf(fullMessageButton, paddingTop: 8, priority: .defaultHigh),
|
|
|
|
|
|
+ bottomLabel.constraintToBottomOf(actionButton, paddingTop: 8, priority: .defaultHigh),
|
|
bottomLabel.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 6)
|
|
bottomLabel.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 6)
|
|
])
|
|
])
|
|
|
|
|
|
@@ -219,14 +219,14 @@ public class BaseMessageCell: UITableViewCell {
|
|
|
|
|
|
mainContentBelowTopLabelConstraint = mainContentView.constraintToBottomOf(topLabel, paddingTop: 6)
|
|
mainContentBelowTopLabelConstraint = mainContentView.constraintToBottomOf(topLabel, paddingTop: 6)
|
|
mainContentUnderTopLabelConstraint = mainContentView.constraintAlignTopTo(messageBackgroundContainer)
|
|
mainContentUnderTopLabelConstraint = mainContentView.constraintAlignTopTo(messageBackgroundContainer)
|
|
- mainContentAboveFullMessageBtnConstraint = fullMessageButton.constraintToBottomOf(mainContentView, paddingTop: 8, priority: .defaultHigh)
|
|
|
|
|
|
+ mainContentAboveActionBtnConstraint = actionButton.constraintToBottomOf(mainContentView, paddingTop: 8, priority: .defaultHigh)
|
|
mainContentUnderBottomLabelConstraint = mainContentView.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 0, priority: .defaultHigh)
|
|
mainContentUnderBottomLabelConstraint = mainContentView.constraintAlignBottomTo(messageBackgroundContainer, paddingBottom: 0, priority: .defaultHigh)
|
|
|
|
|
|
- fullMessageZeroHeightConstraint = fullMessageButton.constraintHeightTo(0)
|
|
|
|
|
|
+ actionBtnZeroHeightConstraint = actionButton.constraintHeightTo(0)
|
|
|
|
|
|
topCompactView = false
|
|
topCompactView = false
|
|
bottomCompactView = false
|
|
bottomCompactView = false
|
|
- isFullMessageButtonHidden = true
|
|
|
|
|
|
+ isActionButtonHidden = true
|
|
|
|
|
|
|
|
|
|
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
|
|
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(onAvatarTapped))
|
|
@@ -265,9 +265,9 @@ public class BaseMessageCell: UITableViewCell {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @objc func onFullMessageButtonTapped() {
|
|
|
|
|
|
+ @objc func onActionButtonTapped() {
|
|
if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
|
|
if let tableView = self.superview as? UITableView, let indexPath = tableView.indexPath(for: self) {
|
|
- baseDelegate?.fullMessageTapped(indexPath: indexPath)
|
|
|
|
|
|
+ baseDelegate?.actionButtonTapped(indexPath: indexPath)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -310,7 +310,23 @@ public class BaseMessageCell: UITableViewCell {
|
|
avatarView.isHidden = true
|
|
avatarView.isHidden = true
|
|
}
|
|
}
|
|
|
|
|
|
- isFullMessageButtonHidden = !msg.hasHtml
|
|
|
|
|
|
+ let downloadState = msg.downloadState
|
|
|
|
+ let hasHtml = msg.hasHtml
|
|
|
|
+ isActionButtonHidden = !hasHtml && downloadState == DC_DOWNLOAD_DONE
|
|
|
|
+
|
|
|
|
+ switch downloadState {
|
|
|
|
+ case DC_DOWNLOAD_FAILURE, DC_DOWNLOAD_AVAILABLE:
|
|
|
|
+ actionButton.setTitle(String.localized("download"), for: .normal)
|
|
|
|
+ case DC_DOWNLOAD_IN_PROGRESS:
|
|
|
|
+ actionButton.isEnabled = false
|
|
|
|
+ actionButton.setTitle(String.localized("downloading"), for: .normal)
|
|
|
|
+ default:
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if hasHtml {
|
|
|
|
+ actionButton.setTitle(String.localized("show_full_message"), for: .normal)
|
|
|
|
+ }
|
|
|
|
|
|
messageBackgroundContainer.update(rectCorners: messageStyle,
|
|
messageBackgroundContainer.update(rectCorners: messageStyle,
|
|
color: getBackgroundColor(dcContext: dcContext, message: msg))
|
|
color: getBackgroundColor(dcContext: dcContext, message: msg))
|
|
@@ -399,6 +415,7 @@ public class BaseMessageCell: UITableViewCell {
|
|
messageLabel.attributedText = nil
|
|
messageLabel.attributedText = nil
|
|
messageLabel.delegate = nil
|
|
messageLabel.delegate = nil
|
|
quoteView.prepareForReuse()
|
|
quoteView.prepareForReuse()
|
|
|
|
+ actionButton.isEnabled = true
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: - Context menu
|
|
// MARK: - Context menu
|
|
@@ -475,5 +492,5 @@ public protocol BaseMessageCellDelegate: class {
|
|
func avatarTapped(indexPath: IndexPath)
|
|
func avatarTapped(indexPath: IndexPath)
|
|
func textTapped(indexPath: IndexPath)
|
|
func textTapped(indexPath: IndexPath)
|
|
func quoteTapped(indexPath: IndexPath)
|
|
func quoteTapped(indexPath: IndexPath)
|
|
- func fullMessageTapped(indexPath: IndexPath)
|
|
|
|
|
|
+ func actionButtonTapped(indexPath: IndexPath)
|
|
}
|
|
}
|