From 76b9496fe6f153b19b2f0468fa662c6fe27e461e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 13 May 2023 13:18:57 -0400 Subject: [PATCH] Revert "Unseparate out updateStatusState method" This reverts commit 2157126332239140477084599f472e00b2d524d2. --- ...ersationMainStatusCollectionViewCell.swift | 44 +++++++++------- .../Status/StatusCollectionViewCell.swift | 52 +++++++++++-------- .../TimelineStatusCollectionViewCell.swift | 4 ++ 3 files changed, 59 insertions(+), 41 deletions(-) diff --git a/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift b/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift index 06df4174..29f277cd 100644 --- a/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift @@ -348,24 +348,6 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status accountDetailAccessibilityElement.navigationDelegate = delegate accountDetailAccessibilityElement.accountID = accountID - let metaButtonAttributes = AttributeContainer([ - .font: ConversationMainStatusCollectionViewCell.metaFont - ]) - - let favoritesFormat = NSLocalizedString("favorites count", comment: "conv main status favorites button label") - var favoritesConfig = UIButton.Configuration.plain() - favoritesConfig.baseForegroundColor = .secondaryLabel - favoritesConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(favoritesFormat, status.favouritesCount), attributes: metaButtonAttributes) - favoritesConfig.contentInsets = .zero - favoritesCountButton.configuration = favoritesConfig - - let reblogsFormat = NSLocalizedString("reblogs count", comment: "conv main status reblogs button label") - var reblogsConfig = UIButton.Configuration.plain() - reblogsConfig.baseForegroundColor = .secondaryLabel - reblogsConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(reblogsFormat, status.reblogsCount), attributes: metaButtonAttributes) - reblogsConfig.contentInsets = .zero - reblogsCountButton.configuration = reblogsConfig - var timestampAndClientText = ConversationMainStatusCollectionViewCell.dateFormatter.string(from: status.createdAt) if let application = status.applicationName { timestampAndClientText += " • \(application)" @@ -376,7 +358,9 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status editTimestampButton.isHidden = false var config = UIButton.Configuration.plain() config.baseForegroundColor = .secondaryLabel - config.attributedTitle = AttributedString("Edited on \(ConversationMainStatusCollectionViewCell.dateFormatter.string(from: editedAt))", attributes: metaButtonAttributes) + config.attributedTitle = AttributedString("Edited on \(ConversationMainStatusCollectionViewCell.dateFormatter.string(from: editedAt))", attributes: AttributeContainer([ + .font: ConversationMainStatusCollectionViewCell.metaFont + ])) config.contentInsets = .zero editTimestampButton.configuration = config } else { @@ -392,6 +376,28 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status baseCreateObservers() } + func updateStatusState(status: StatusMO) { + baseUpdateStatusState(status: status) + + let attributes = AttributeContainer([ + .font: ConversationMainStatusCollectionViewCell.metaFont + ]) + + let favoritesFormat = NSLocalizedString("favorites count", comment: "conv main status favorites button label") + var favoritesConfig = UIButton.Configuration.plain() + favoritesConfig.baseForegroundColor = .secondaryLabel + favoritesConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(favoritesFormat, status.favouritesCount), attributes: attributes) + favoritesConfig.contentInsets = .zero + favoritesCountButton.configuration = favoritesConfig + + let reblogsFormat = NSLocalizedString("reblogs count", comment: "conv main status reblogs button label") + var reblogsConfig = UIButton.Configuration.plain() + reblogsConfig.baseForegroundColor = .secondaryLabel + reblogsConfig.attributedTitle = AttributedString(String.localizedStringWithFormat(reblogsFormat, status.reblogsCount), attributes: attributes) + reblogsConfig.contentInsets = .zero + reblogsCountButton.configuration = reblogsConfig + } + func updateUIForPreferences(status: StatusMO) { baseUpdateUIForPreferences(status: status) } diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index cbac1e3a..4072224e 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -45,6 +45,7 @@ protocol StatusCollectionViewCell: UICollectionViewCell, AttachmentViewDelegate var cancellables: Set { get set } func updateUIForPreferences(status: StatusMO) + func updateStatusState(status: StatusMO) } // MARK: UI Configuration @@ -98,6 +99,7 @@ extension StatusCollectionViewCell { } updateUIForPreferences(status: status) + updateStatusState(status: status) contentWarningLabel.text = status.spoilerText contentWarningLabel.isHidden = status.spoilerText.isEmpty @@ -105,29 +107,9 @@ extension StatusCollectionViewCell { contentWarningLabel.setEmojis(status.emojis, identifier: statusID) } - replyButton.isEnabled = mastodonController.loggedIn - - favoriteButton.isEnabled = mastodonController.loggedIn - if status.favourited { - favoriteButton.tintColor = UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) - favoriteButton.accessibilityLabel = NSLocalizedString("Undo Favorite", comment: "undo favorite button accessibility label") - } else { - favoriteButton.tintColor = nil - favoriteButton.accessibilityLabel = NSLocalizedString("Favorite", comment: "favorite button accessibility label") - } - reblogButton.isEnabled = reblogEnabled(status: status) - if status.reblogged { - reblogButton.tintColor = UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) - reblogButton.accessibilityLabel = NSLocalizedString("Undo Reblog", comment: "undo reblog button accessibility label") - } else { - reblogButton.tintColor = nil - reblogButton.accessibilityLabel = NSLocalizedString("Reblog", comment: "reblog button accessibility label") - } - - // keep menu in sync with changed states e.g. bookmarked, muted - // do not include reply action here, because the cell already contains a button for it - moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, source: .view(moreButton), includeStatusButtonActions: false) ?? []) + replyButton.isEnabled = mastodonController.loggedIn + favoriteButton.isEnabled = mastodonController.loggedIn let didResolve = statusState.resolveFor(status: status) { // layout so that we can take the content height into consideration when deciding whether to collapse @@ -212,6 +194,32 @@ extension StatusCollectionViewCell { displayNameLabel.updateForAccountDisplayName(account: status.account) } + func baseUpdateStatusState(status: StatusMO) { + if status.favourited { + favoriteButton.tintColor = UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) + favoriteButton.accessibilityLabel = NSLocalizedString("Undo Favorite", comment: "undo favorite button accessibility label") + } else { + favoriteButton.tintColor = nil + favoriteButton.accessibilityLabel = NSLocalizedString("Favorite", comment: "favorite button accessibility label") + } + if status.reblogged { + reblogButton.tintColor = UIColor(displayP3Red: 1, green: 0.8, blue: 0, alpha: 1) + reblogButton.accessibilityLabel = NSLocalizedString("Undo Reblog", comment: "undo reblog button accessibility label") + } else { + reblogButton.tintColor = nil + reblogButton.accessibilityLabel = NSLocalizedString("Reblog", comment: "reblog button accessibility label") + } + + // keep menu in sync with changed states e.g. bookmarked, muted + // do not include reply action here, because the cell already contains a button for it + moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, source: .view(moreButton), includeStatusButtonActions: false) ?? []) + + contentContainer.pollView.isHidden = status.poll == nil + contentContainer.pollView.mastodonController = mastodonController + contentContainer.pollView.delegate = delegate + contentContainer.pollView.updateUI(status: status, poll: status.poll) + } + func setShowThreadLinks(prev: Bool, next: Bool) { if prev { if let prevThreadLinkView { diff --git a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift index 599117c2..2c988958 100644 --- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift @@ -625,6 +625,10 @@ class TimelineStatusCollectionViewCell: UICollectionViewListCell, StatusCollecti } } + func updateStatusState(status: StatusMO) { + baseUpdateStatusState(status: status) + } + private func updateTimestamp() { guard let mastodonController, let status = mastodonController.persistentContainer.status(for: statusID) else {