|
|
@ -13,10 +13,22 @@ protocol StatusViewDelegate { |
|
|
|
func accountTapped(account: AccountMO) |
|
|
|
func statusTapped(status: StatusMO) |
|
|
|
func loadMoreTapped(status: StatusMO, direction: PaginationDirection) |
|
|
|
func attachmentTapped(status: StatusMO) |
|
|
|
func attachmentTapped(status: StatusMO, index: Int) |
|
|
|
func boostTapped() |
|
|
|
func favoriteTapped() |
|
|
|
func revealTapped() |
|
|
|
func hideTapped() |
|
|
|
} |
|
|
|
|
|
|
|
class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
extension StatusViewDelegate { |
|
|
|
func loadMoreTapped(status: StatusMO, direction: PaginationDirection) {} |
|
|
|
func boostTapped() {} |
|
|
|
func favoriteTapped() {} |
|
|
|
func revealTapped() {} |
|
|
|
func hideTapped() {} |
|
|
|
} |
|
|
|
|
|
|
|
class StatusView: UIView { |
|
|
|
@IBOutlet var contentView: UIView! |
|
|
|
@IBOutlet var boostView: UIView! |
|
|
|
@IBOutlet var boostAvatarImageView: UIImageView! |
|
|
@ -49,6 +61,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
var status: StatusMO? = nil |
|
|
|
var delegate: StatusViewDelegate? = nil |
|
|
|
var spoilerView: UIVisualEffectView? = nil |
|
|
|
var attachmentManager: AttachmentManager = AttachmentManager() |
|
|
|
|
|
|
|
@IBAction func boostViewTapped(_ sender: Any) { |
|
|
|
if let delegate = delegate, let status = status { |
|
|
@ -89,6 +102,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
if let status = status { |
|
|
|
status.hidden = true |
|
|
|
CoreDataManager.shared.saveContext() |
|
|
|
delegate?.hideTapped() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -133,6 +147,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
} |
|
|
|
|
|
|
|
CoreDataManager.shared.saveContext() |
|
|
|
delegate?.boostTapped() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -165,6 +180,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
} |
|
|
|
|
|
|
|
CoreDataManager.shared.saveContext() |
|
|
|
delegate?.favoriteTapped() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -173,16 +189,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
if let status = status { |
|
|
|
status.hidden = false |
|
|
|
CoreDataManager.shared.saveContext() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@objc func attachmentTapped() { |
|
|
|
if let delegate = delegate, let status = status { |
|
|
|
if let reblog = status.reblog { |
|
|
|
delegate.attachmentTapped(status: reblog) |
|
|
|
} else { |
|
|
|
delegate.attachmentTapped(status: status) |
|
|
|
} |
|
|
|
delegate?.revealTapped() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -200,6 +207,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
Bundle.main.loadNibNamed("StatusView", owner: self, options: nil) |
|
|
|
addSubview(contentView) |
|
|
|
contentView.frame = self.bounds |
|
|
|
attachmentManager.delegate = self |
|
|
|
} |
|
|
|
|
|
|
|
public func update(withStatus status: StatusMO) { |
|
|
@ -230,14 +238,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
|
|
|
|
if let attachments = status.attachments, attachments.count > 0 { |
|
|
|
attachmentsView.isHidden = false |
|
|
|
attachmentsView.isUserInteractionEnabled = true |
|
|
|
|
|
|
|
AttachmentManager.setupAttachmentView(attachmentsView, withAttachments: attachments) |
|
|
|
|
|
|
|
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(attachmentTapped)) |
|
|
|
attachmentsView.addGestureRecognizer(tapGestureRecognizer) |
|
|
|
|
|
|
|
tapGestureRecognizer.delegate = self |
|
|
|
attachmentManager.setupAttachmentView(attachmentsView, withAttachments: attachments) |
|
|
|
} |
|
|
|
|
|
|
|
if let content = status.content { |
|
|
@ -257,6 +258,7 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
spoilerText.font = UIFont.systemFont(ofSize: 15, weight: .bold) |
|
|
|
spoilerText.textAlignment = .center |
|
|
|
spoilerText.text = status.spoilerText |
|
|
|
spoilerText.numberOfLines = 0 |
|
|
|
spoilerText.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
|
|
|
|
let blurEffectView = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffect.Style.light)) |
|
|
@ -349,3 +351,15 @@ class StatusView: UIView, UIGestureRecognizerDelegate { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
extension StatusView: AttachmentManagerDelegate { |
|
|
|
func attachmentTapped(index: Int) { |
|
|
|
if let delegate = delegate, let status = status { |
|
|
|
if let reblog = status.reblog { |
|
|
|
delegate.attachmentTapped(status: reblog, index: index) |
|
|
|
} else { |
|
|
|
delegate.attachmentTapped(status: status, index: index) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |