From 2157126332239140477084599f472e00b2d524d2 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Thu, 11 May 2023 10:02:45 -0400 Subject: [PATCH] Unseparate out updateStatusState method --- ...ersationMainStatusCollectionViewCell.swift | 40 +++++++------- .../Status/StatusCollectionViewCell.swift | 54 +++++++++---------- .../TimelineStatusCollectionViewCell.swift | 4 -- 3 files changed, 43 insertions(+), 55 deletions(-) diff --git a/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift b/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift index 3619a38f..56a25d03 100644 --- a/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/ConversationMainStatusCollectionViewCell.swift @@ -341,6 +341,24 @@ class ConversationMainStatusCollectionViewCell: UICollectionViewListCell, Status accountDetailAccessibilityElement.navigationDelegate = delegate accountDetailAccessibilityElement.accountID = accountID + let favoriteAndReblogAttributes = 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: favoriteAndReblogAttributes) + 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: favoriteAndReblogAttributes) + reblogsConfig.contentInsets = .zero + reblogsCountButton.configuration = reblogsConfig + var timestampAndClientText = ConversationMainStatusCollectionViewCell.dateFormatter.string(from: status.createdAt) if let application = status.applicationName { timestampAndClientText += " • \(application)" @@ -356,28 +374,6 @@ 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 95032103..bfcbfa7b 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -45,7 +45,6 @@ protocol StatusCollectionViewCell: UICollectionViewCell, AttachmentViewDelegate var cancellables: Set { get set } func updateUIForPreferences(status: StatusMO) - func updateStatusState(status: StatusMO) } // MARK: UI Configuration @@ -85,6 +84,10 @@ extension StatusCollectionViewCell { contentContainer.contentTextView.navigationDelegate = delegate contentContainer.attachmentsView.delegate = self contentContainer.attachmentsView.updateUI(status: status) + contentContainer.pollView.isHidden = status.poll == nil + contentContainer.pollView.mastodonController = mastodonController + contentContainer.pollView.delegate = delegate + contentContainer.pollView.updateUI(status: status, poll: status.poll) if Preferences.shared.showLinkPreviews { contentContainer.cardView.updateUI(status: status) contentContainer.cardView.isHidden = status.card == nil @@ -95,7 +98,6 @@ extension StatusCollectionViewCell { } updateUIForPreferences(status: status) - updateStatusState(status: status) contentWarningLabel.text = status.spoilerText contentWarningLabel.isHidden = status.spoilerText.isEmpty @@ -103,9 +105,29 @@ extension StatusCollectionViewCell { contentWarningLabel.setEmojis(status.emojis, identifier: statusID) } - reblogButton.isEnabled = reblogEnabled(status: status) 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) ?? []) if statusState.unknown { // layout so that we can take the content height into consideration when deciding whether to collapse @@ -188,32 +210,6 @@ 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 8bc174bb..b0b4eef4 100644 --- a/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusCollectionViewCell.swift @@ -625,10 +625,6 @@ 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 {