|
@ -9,17 +9,17 @@ |
|
|
import Kingfisher |
|
|
import Kingfisher |
|
|
import UIKit |
|
|
import UIKit |
|
|
|
|
|
|
|
|
protocol StatusViewDelegate { |
|
|
|
|
|
func accountTapped(account: AccountMO) |
|
|
|
|
|
func statusTapped(status: StatusMO) |
|
|
|
|
|
func loadMoreTapped(status: StatusMO, direction: PaginationDirection) |
|
|
|
|
|
func attachmentTapped(status: StatusMO, index: Int) |
|
|
|
|
|
func urlTapped(url: URL) |
|
|
|
|
|
func boostTapped() |
|
|
|
|
|
func favoriteTapped() |
|
|
|
|
|
func replyTapped(status: StatusMO) |
|
|
|
|
|
func revealTapped() |
|
|
|
|
|
func hideTapped() |
|
|
|
|
|
|
|
|
protocol StatusViewDelegate: class { |
|
|
|
|
|
func accountTapped(_ sender: Any, account: AccountMO) |
|
|
|
|
|
func statusTapped(_ sender: Any, status: StatusMO) |
|
|
|
|
|
func loadMoreTapped(_ sender: Any, status: StatusMO, direction: PaginationDirection) |
|
|
|
|
|
func attachmentTapped(_ sender: Any, status: StatusMO, index: Int) |
|
|
|
|
|
func urlTapped(_ sender: Any, url: URL) |
|
|
|
|
|
func boostTapped(_ sender: Any) |
|
|
|
|
|
func favoriteTapped(_ sender: Any) |
|
|
|
|
|
func replyTapped(_ sender: Any, status: StatusMO) |
|
|
|
|
|
func revealTapped(_ sender: Any) |
|
|
|
|
|
func hideTapped(_ sender: Any) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class StatusView: UIView { |
|
|
class StatusView: UIView { |
|
@ -52,15 +52,16 @@ class StatusView: UIView { |
|
|
@IBOutlet var bottomLoadMoreView: UIView! |
|
|
@IBOutlet var bottomLoadMoreView: UIView! |
|
|
@IBOutlet var contentTextView: UITextView! |
|
|
@IBOutlet var contentTextView: UITextView! |
|
|
|
|
|
|
|
|
var status: StatusMO? = nil |
|
|
|
|
|
var delegate: StatusViewDelegate? = nil |
|
|
|
|
|
var spoilerView: UIVisualEffectView? = nil |
|
|
|
|
|
|
|
|
var status: StatusMO? |
|
|
|
|
|
var spoilerView: UIVisualEffectView? |
|
|
|
|
|
var feedbackGenerator: UINotificationFeedbackGenerator? |
|
|
var attachmentManager: AttachmentManager = AttachmentManager() |
|
|
var attachmentManager: AttachmentManager = AttachmentManager() |
|
|
var feedbackGenerator: UINotificationFeedbackGenerator? = nil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
weak var delegate: StatusViewDelegate? |
|
|
|
|
|
|
|
|
@IBAction func boostViewTapped(_ sender: Any) { |
|
|
@IBAction func boostViewTapped(_ sender: Any) { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let delegate = delegate, let status = status { |
|
|
delegate.accountTapped(account: status.account!) |
|
|
|
|
|
|
|
|
delegate.accountTapped(self, account: status.account!) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -69,16 +70,16 @@ class StatusView: UIView { |
|
|
let status = status, |
|
|
let status = status, |
|
|
let replyAccountID = status.inReplyToAccountID, |
|
|
let replyAccountID = status.inReplyToAccountID, |
|
|
let replyAccount = MastodonDataManager.account(id: replyAccountID) { |
|
|
let replyAccount = MastodonDataManager.account(id: replyAccountID) { |
|
|
delegate.accountTapped(account: replyAccount) |
|
|
|
|
|
|
|
|
delegate.accountTapped(self, account: replyAccount) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@IBAction func accountViewTapped(_ sender: Any) { |
|
|
@IBAction func accountViewTapped(_ sender: Any) { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let reblog = status.reblog { |
|
|
if let reblog = status.reblog { |
|
|
delegate.accountTapped(account: reblog.account!) |
|
|
|
|
|
|
|
|
delegate.accountTapped(self, account: reblog.account!) |
|
|
} else { |
|
|
} else { |
|
|
delegate.accountTapped(account: status.account!) |
|
|
|
|
|
|
|
|
delegate.accountTapped(self, account: status.account!) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -86,9 +87,9 @@ class StatusView: UIView { |
|
|
@IBAction func mainViewTapped(_ sender: Any) { |
|
|
@IBAction func mainViewTapped(_ sender: Any) { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let reblog = status.reblog { |
|
|
if let reblog = status.reblog { |
|
|
delegate.statusTapped(status: reblog) |
|
|
|
|
|
|
|
|
delegate.statusTapped(self, status: reblog) |
|
|
} else { |
|
|
} else { |
|
|
delegate.statusTapped(status: status) |
|
|
|
|
|
|
|
|
delegate.statusTapped(self, status: status) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -97,19 +98,19 @@ class StatusView: UIView { |
|
|
if let status = status { |
|
|
if let status = status { |
|
|
status.hidden = true |
|
|
status.hidden = true |
|
|
CoreDataManager.shared.saveContext() |
|
|
CoreDataManager.shared.saveContext() |
|
|
delegate?.hideTapped() |
|
|
|
|
|
|
|
|
delegate?.hideTapped(self) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@IBAction func topLoadMoreViewTapped(_ sender: Any) { |
|
|
@IBAction func topLoadMoreViewTapped(_ sender: Any) { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let delegate = delegate, let status = status { |
|
|
delegate.loadMoreTapped(status: status, direction: .prev) |
|
|
|
|
|
|
|
|
delegate.loadMoreTapped(self, status: status, direction: .prev) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@IBAction func bottomLoadMoreViewTapped(_ sender: Any) { |
|
|
@IBAction func bottomLoadMoreViewTapped(_ sender: Any) { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let delegate = delegate, let status = status { |
|
|
delegate.loadMoreTapped(status: status, direction: .next) |
|
|
|
|
|
|
|
|
delegate.loadMoreTapped(self, status: status, direction: .next) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -155,7 +156,7 @@ class StatusView: UIView { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
CoreDataManager.shared.saveContext() |
|
|
CoreDataManager.shared.saveContext() |
|
|
delegate?.boostTapped() |
|
|
|
|
|
|
|
|
delegate?.boostTapped(self) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -194,19 +195,19 @@ class StatusView: UIView { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
CoreDataManager.shared.saveContext() |
|
|
CoreDataManager.shared.saveContext() |
|
|
delegate?.favoriteTapped() |
|
|
|
|
|
|
|
|
delegate?.favoriteTapped(self) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@IBAction func replyTapped(_ sender: Any) { |
|
|
@IBAction func replyTapped(_ sender: Any) { |
|
|
delegate?.replyTapped(status: status!) |
|
|
|
|
|
|
|
|
delegate?.replyTapped(self, status: status!) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@objc func reveal(sender: UITapGestureRecognizer) { |
|
|
@objc func reveal(sender: UITapGestureRecognizer) { |
|
|
if let status = status { |
|
|
if let status = status { |
|
|
status.hidden = false |
|
|
status.hidden = false |
|
|
CoreDataManager.shared.saveContext() |
|
|
CoreDataManager.shared.saveContext() |
|
|
delegate?.revealTapped() |
|
|
|
|
|
|
|
|
delegate?.revealTapped(self) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -369,12 +370,12 @@ class StatusView: UIView { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
extension StatusView: AttachmentManagerDelegate { |
|
|
extension StatusView: AttachmentManagerDelegate { |
|
|
func attachmentTapped(index: Int) { |
|
|
|
|
|
|
|
|
func attachmentTapped(_ sender: Any, index: Int) { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let delegate = delegate, let status = status { |
|
|
if let reblog = status.reblog { |
|
|
if let reblog = status.reblog { |
|
|
delegate.attachmentTapped(status: reblog, index: index) |
|
|
|
|
|
|
|
|
delegate.attachmentTapped(self, status: reblog, index: index) |
|
|
} else { |
|
|
} else { |
|
|
delegate.attachmentTapped(status: status, index: index) |
|
|
|
|
|
|
|
|
delegate.attachmentTapped(self, status: status, index: index) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -386,7 +387,7 @@ extension StatusView: UITextViewDelegate { |
|
|
for mention in mentions { |
|
|
for mention in mentions { |
|
|
if URL == mention.url { |
|
|
if URL == mention.url { |
|
|
if let account = MastodonDataManager.account(id: mention.id) { |
|
|
if let account = MastodonDataManager.account(id: mention.id) { |
|
|
delegate?.accountTapped(account: account) |
|
|
|
|
|
|
|
|
delegate?.accountTapped(self, account: account) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return false |
|
|
return false |
|
@ -395,7 +396,7 @@ extension StatusView: UITextViewDelegate { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if URL.scheme == "http" || URL.scheme == "https" { |
|
|
if URL.scheme == "http" || URL.scheme == "https" { |
|
|
delegate?.urlTapped(url: URL) |
|
|
|
|
|
|
|
|
delegate?.urlTapped(self, url: URL) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return false |
|
|
return false |
|
|