From ca7fe74a90d2ec586dcabc60bed2aace664e45a9 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Fri, 10 Nov 2023 14:48:48 -0500 Subject: [PATCH] Add accessibility description/action to status edit history entry --- .../StatusEditCollectionViewCell.swift | 70 ++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/Tusker/Screens/Status Edit History/StatusEditCollectionViewCell.swift b/Tusker/Screens/Status Edit History/StatusEditCollectionViewCell.swift index 536928d1..bbaa1382 100644 --- a/Tusker/Screens/Status Edit History/StatusEditCollectionViewCell.swift +++ b/Tusker/Screens/Status Edit History/StatusEditCollectionViewCell.swift @@ -91,8 +91,76 @@ class StatusEditCollectionViewCell: UICollectionViewListCell { fatalError("init(coder:) has not been implemented") } - // todo: accessibility + // MARK: Accessibility + override var isAccessibilityElement: Bool { + get { true } + set {} + } + + override var accessibilityAttributedLabel: NSAttributedString? { + get { + var str: AttributedString = "" + if statusState.collapsed ?? false { + if !edit.spoilerText.isEmpty { + str += AttributedString(edit.spoilerText) + str += ", " + } + str += "collapsed" + } else { + str += AttributedString(contentContainer.contentTextView.attributedText) + + if edit.attachments.count > 0 { + let includeDescriptions: Bool + switch Preferences.shared.attachmentBlurMode { + case .useStatusSetting: + includeDescriptions = !Preferences.shared.blurMediaBehindContentWarning || edit.spoilerText.isEmpty + case .always: + includeDescriptions = true + case .never: + includeDescriptions = false + } + if includeDescriptions { + if edit.attachments.count == 1 { + let attachment = edit.attachments[0] + let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description" + str += AttributedString(", attachment: \(desc)") + } else { + for (index, attachment) in edit.attachments.enumerated() { + let desc = attachment.description?.isEmpty == false ? attachment.description! : "no description" + str += AttributedString(", attachment \(index + 1): \(desc)") + } + } + } else { + str += AttributedString(", \(edit.attachments.count) attachment\(edit.attachments.count == 1 ? "" : "s")") + } + } + if edit.poll != nil { + str += ", poll" + } + } + return NSAttributedString(str) + } + set {} + } + + override var accessibilityHint: String? { + get { + if statusState.collapsed ?? false { + return "Double tap to expand the post." + } else { + return nil + } + } + set {} + } + + override func accessibilityActivate() -> Bool { + if statusState.collapsed ?? false { + collapseButtonPressed() + } + return true + } // MARK: Configure UI