diff --git a/Tusker/Views/ConversationMainStatusTableViewCell.swift b/Tusker/Views/ConversationMainStatusTableViewCell.swift
index 10d4543551..0248702a92 100644
--- a/Tusker/Views/ConversationMainStatusTableViewCell.swift
+++ b/Tusker/Views/ConversationMainStatusTableViewCell.swift
@@ -18,6 +18,7 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
@IBOutlet weak var contentLabel: StatusContentLabel!
@IBOutlet weak var avatarImageView: UIImageView!
@IBOutlet weak var timestampLabel: UILabel!
+ @IBOutlet weak var attachmentsView: UIView!
var status: Status!
var account: Account!
@@ -34,6 +35,8 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(accountPressed)))
avatarImageView.isUserInteractionEnabled = true
avatarImageView.layer.masksToBounds = true
+ attachmentsView.layer.cornerRadius = 5
+ attachmentsView.layer.masksToBounds = true
}
func updateUIForPreferences() {
@@ -66,6 +69,33 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
}
}
+ attachmentsView.subviews.forEach { $0.removeFromSuperview() }
+ let attachments = status.mediaAttachments.filter({ $0.type == .image })
+ if attachments.count > 0 {
+ attachmentsView.isHidden = false
+ let width = attachmentsView.bounds.width
+ let height: CGFloat = 200
+ switch attachments.count {
+ case 1:
+ addAttachmentView(frame: CGRect(x: 0, y: 0, width: width, height: height), attachment: attachments[0])
+ case 2:
+ addAttachmentView(frame: CGRect(x: 0, y: 0, width: width / 2 - 4, height: height), attachment: attachments[0])
+ addAttachmentView(frame: CGRect(x: width / 2 + 4, y: 0, width: width / 2 - 4, height: height), attachment: attachments[1])
+ case 3:
+ addAttachmentView(frame: CGRect(x: 0, y: 0, width: width / 2 - 4, height: height), attachment: attachments[0])
+ addAttachmentView(frame: CGRect(x: width / 2 + 4, y: 0, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[1])
+ addAttachmentView(frame: CGRect(x: width / 2 + 4, y: height / 2 + 4, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[2])
+ case 4:
+ addAttachmentView(frame: CGRect(x: 0, y: 0, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[0])
+ addAttachmentView(frame: CGRect(x: 0, y: height / 2 + 4, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[1])
+ addAttachmentView(frame: CGRect(x: width / 2 + 4, y: 0, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[2])
+ addAttachmentView(frame: CGRect(x: width / 2 + 4, y: height / 2 + 4, width: width / 2 - 4, height: height / 2 - 4), attachment: attachments[3])
+ default:
+ fatalError("Too many attachments")
+ }
+ } else {
+ attachmentsView.isHidden = true
+ }
contentLabel.status = status
contentLabel.delegate = self
@@ -92,10 +122,21 @@ class ConversationMainStatusTableViewCell: UITableViewCell, PreferencesAdaptive
}
}
+ func addAttachmentView(frame: CGRect, attachment: Attachment) {
+ let attachmentView = AttachmentView(frame: frame, attachment: attachment)
+ attachmentView.delegate = self
+ attachmentsView.addSubview(attachmentView)
+ }
+
override func prepareForReuse() {
if let url = avatarURL {
AvatarCache.shared.cancel(url)
}
+ updateTimestampWorkItem?.cancel()
+ updateTimestampWorkItem = nil
+ attachmentsView.subviews.forEach { view in
+ (view as? AttachmentView)?.task?.cancel()
+ }
}
@objc func accountPressed() {
@@ -123,3 +164,9 @@ extension ConversationMainStatusTableViewCell: HTMLContentLabelDelegate {
}
}
+
+extension ConversationMainStatusTableViewCell: AttachmentViewDelegate {
+ func showLargeAttachment(for attachmentView: AttachmentView) {
+ delegate?.showLargeAttachment(for: attachmentView)
+ }
+}
diff --git a/Tusker/Views/ConversationMainStatusTableViewCell.xib b/Tusker/Views/ConversationMainStatusTableViewCell.xib
index 75defe0cd2..a904d7738c 100644
--- a/Tusker/Views/ConversationMainStatusTableViewCell.xib
+++ b/Tusker/Views/ConversationMainStatusTableViewCell.xib
@@ -15,10 +15,10 @@
-
+
-
+
@@ -40,7 +40,7 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -97,6 +107,7 @@
+