Browse Source

Fix a11y for collection cells

- treat cell as single entity, don't have views inside cell accessible
- add custom a11y actions for buttons
- add a11y labels, and values for visible indicators

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 years ago
parent
commit
9227edaeb0

+ 23 - 0
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1388,6 +1388,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 progress = progressType.progress
                 totalBytes = progressType.totalBytes
             }
+
             if metadata.status == NCGlobal.shared.metadataStatusDownloading || metadata.status == NCGlobal.shared.metadataStatusUploading {
                 cell.progressView.isHidden = false
                 cell.progressView.progress = progress
@@ -1396,6 +1397,11 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 cell.progressView.progress = 0.0
             }
 
+            var a11yValues: [String] = []
+            if metadata.ownerId != appDelegate.userId, appDelegate.account == metadata.account {
+                a11yValues.append(NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName)
+            }
+
             if metadata.directory {
 
                 if metadata.e2eEncrypted {
@@ -1428,6 +1434,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
 
                 // image local
                 if dataSource.metadataOffLine.contains(metadata.ocId) {
+                    a11yValues.append(NSLocalizedString("_offline_", comment: ""))
                     cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
                 } else if CCUtility.fileProviderStorageExists(metadata) {
                     cell.imageLocal.image = NCBrandColor.cacheImages.local
@@ -1437,6 +1444,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             // image Favorite
             if metadata.favorite {
                 cell.imageFavorite.image = NCBrandColor.cacheImages.favorite
+                a11yValues.append(NSLocalizedString("_favorite_", comment: ""))
             }
 
             // Share image
@@ -1490,10 +1498,14 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 break
             }
 
+            cell.accessibilityLabel = metadata.fileNameView + ", " + (cell.labelInfo.text ?? "")
+
             // Live Photo
             if metadata.livePhoto {
                 cell.imageStatus.image = NCBrandColor.cacheImages.livePhoto
+                a11yValues.append(NSLocalizedString("_upload_mov_livephoto_", comment: ""))
             }
+            cell.accessibilityValue = a11yValues.joined(separator: ", ")
 
             // E2EE
             if metadata.e2eEncrypted || isEncryptedFolder {
@@ -1559,9 +1571,16 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             if metadata.status == NCGlobal.shared.metadataStatusDownloading || metadata.status == NCGlobal.shared.metadataStatusUploading {
                 cell.progressView.isHidden = false
                 cell.progressView.progress = progress
+                cell.accessibilityLabel = metadata.fileNameView + ", \(Int(progress * 100))%"
             } else {
                 cell.progressView.isHidden = true
                 cell.progressView.progress = 0.0
+                cell.accessibilityLabel = metadata.fileNameView
+            }
+
+            var a11yValues: [String] = []
+            if metadata.ownerId != appDelegate.userId, appDelegate.account == metadata.account {
+                a11yValues.append(NSLocalizedString("_shared_with_you_by_", comment: "") + " " + metadata.ownerDisplayName)
             }
 
             if metadata.directory {
@@ -1597,6 +1616,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
                 // image Local
                 if dataSource.metadataOffLine.contains(metadata.ocId) {
                     cell.imageLocal.image = NCBrandColor.cacheImages.offlineFlag
+                    a11yValues.append(NSLocalizedString("_offline_", comment: ""))
                 } else if CCUtility.fileProviderStorageExists(metadata) {
                     cell.imageLocal.image = NCBrandColor.cacheImages.local
                 }
@@ -1605,6 +1625,7 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             // image Favorite
             if metadata.favorite {
                 cell.imageFavorite.image = NCBrandColor.cacheImages.favorite
+                a11yValues.append(NSLocalizedString("_favorite_", comment: ""))
             }
 
             // Transfer
@@ -1617,7 +1638,9 @@ extension NCCollectionViewCommon: UICollectionViewDataSource {
             // Live Photo
             if metadata.livePhoto {
                 cell.imageStatus.image = NCBrandColor.cacheImages.livePhoto
+                a11yValues.append(NSLocalizedString("_upload_mov_livephoto_", comment: ""))
             }
+            cell.accessibilityValue = a11yValues.joined(separator: ", ")
 
             // Edit mode
             if isEditMode {

+ 17 - 0
iOSClient/Main/Collection Common/NCGridCell.swift

@@ -72,6 +72,12 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     override func awakeFromNib() {
         super.awakeFromNib()
 
+        // use entire cell as accessibility element
+        accessibilityHint = nil
+        accessibilityLabel = nil
+        accessibilityValue = nil
+        isAccessibilityElement = true
+
         imageItem.layer.cornerRadius = 6
         imageItem.layer.masksToBounds = true
 
@@ -99,6 +105,9 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     override func prepareForReuse() {
         super.prepareForReuse()
         imageItem.backgroundColor = nil
+        accessibilityHint = nil
+        accessibilityLabel = nil
+        accessibilityValue = nil
     }
 
     @IBAction func touchUpInsideMore(_ sender: Any) {
@@ -116,6 +125,14 @@ class NCGridCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     func setButtonMore(named: String, image: UIImage) {
         namedButtonMore = named
         buttonMore.setImage(image, for: .normal)
+        let moreName = named == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_"
+
+        self.accessibilityCustomActions = [
+            UIAccessibilityCustomAction(
+                name: NSLocalizedString(moreName, comment: ""),
+                target: self,
+                selector: #selector(touchUpInsideMore))
+        ]
     }
 
     func hideButtonMore(_ status: Bool) {

+ 22 - 0
iOSClient/Main/Collection Common/NCListCell.swift

@@ -80,6 +80,12 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
         imageItem.layer.cornerRadius = 6
         imageItem.layer.masksToBounds = true
 
+        // use entire cell as accessibility element
+        accessibilityHint = nil
+        accessibilityLabel = nil
+        accessibilityValue = nil
+        isAccessibilityElement = true
+
         progressView.tintColor = NCBrandColor.shared.brandElement
         progressView.transform = CGAffineTransform(scaleX: 1.0, y: 0.5)
         progressView.trackTintColor = .clear
@@ -103,6 +109,9 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     override func prepareForReuse() {
         super.prepareForReuse()
         imageItem.backgroundColor = nil
+        accessibilityHint = nil
+        accessibilityLabel = nil
+        accessibilityValue = nil
     }
 
     @IBAction func touchUpInsideShare(_ sender: Any) {
@@ -124,6 +133,19 @@ class NCListCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellProto
     func setButtonMore(named: String, image: UIImage) {
         namedButtonMore = named
         imageMore.image = image
+
+        let moreName = named == NCGlobal.shared.buttonMoreStop ? "_cancel_" : "_more_"
+
+        self.accessibilityCustomActions = [
+            UIAccessibilityCustomAction(
+                name: NSLocalizedString("_share_", comment: ""),
+                target: self,
+                selector: #selector(touchUpInsideShare)),
+            UIAccessibilityCustomAction(
+                name: NSLocalizedString(moreName, comment: ""),
+                target: self,
+                selector: #selector(touchUpInsideMore))
+        ]
     }
 
     func hideButtonMore(_ status: Bool) {

+ 9 - 0
iOSClient/Transfers/NCTransferCell.swift

@@ -73,6 +73,8 @@ class NCTransferCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellP
     override func awakeFromNib() {
         super.awakeFromNib()
 
+        isAccessibilityElement = true
+
         imageItem.layer.cornerRadius = 6
         imageItem.layer.masksToBounds = true
 
@@ -120,6 +122,13 @@ class NCTransferCell: UICollectionViewCell, UIGestureRecognizerDelegate, NCCellP
     func setButtonMore(named: String, image: UIImage) {
         namedButtonMore = named
         imageMore.image = image
+        self.accessibilityCustomActions = [
+            UIAccessibilityCustomAction(
+                name: NSLocalizedString("_cancel_", comment: ""),
+                target: self,
+                selector: #selector(touchUpInsideMore))
+        ]
+
     }
 }
 

+ 1 - 0
iOSClient/Transfers/NCTransfers.swift

@@ -252,6 +252,7 @@ class NCTransfers: NCCollectionViewCommon, NCTransferCellDelegate {
             cell.labelInfo.text = ""
             break
         }
+        cell.accessibilityLabel = metadata.fileNameView + ", " + (cell.labelInfo.text ?? "")
 
         // Remove last separator
         if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {

+ 21 - 4
iOSClient/Trash/Cell/NCTrashListCell.swift

@@ -50,6 +50,20 @@ class NCTrashListCell: UICollectionViewCell, NCTrashCell {
     override func awakeFromNib() {
         super.awakeFromNib()
 
+        isAccessibilityElement = true
+
+        self.accessibilityCustomActions = [
+            UIAccessibilityCustomAction(
+                name: NSLocalizedString("_restore_", comment: ""),
+                target: self,
+                selector: #selector(touchUpInsideRestore)),
+            UIAccessibilityCustomAction(
+                name: NSLocalizedString("_delete_", comment: ""),
+                target: self,
+                selector: #selector(touchUpInsideMore))
+
+        ]
+
         imageRestore.image = NCBrandColor.cacheImages.buttonRestore
         imageMore.image = NCUtility.shared.loadImage(named: "trash")
 
@@ -119,18 +133,21 @@ protocol NCTrashCell {
     func selectMode(_ status: Bool)
     func selected(_ status: Bool)
 }
-extension NCTrashCell {
+
+extension NCTrashCell where Self: UICollectionViewCell {
     mutating func setupCellUI(tableTrash: tableTrash, image: UIImage?) {
         self.objectId = tableTrash.fileId
         self.labelTitle.text = tableTrash.trashbinFileName
         self.labelTitle.textColor = NCBrandColor.shared.label
-
+        let infoText: String
         if tableTrash.directory {
             self.imageItem.image = NCBrandColor.cacheImages.folder
-            self.labelInfo?.text = CCUtility.dateDiff(tableTrash.date as Date)
+            infoText = CCUtility.dateDiff(tableTrash.date as Date)
         } else {
             self.imageItem.image = image
-            self.labelInfo?.text = CCUtility.dateDiff(tableTrash.date as Date) + ", " + CCUtility.transformedSize(tableTrash.size)
+            infoText = CCUtility.dateDiff(tableTrash.date as Date) + ", " + CCUtility.transformedSize(tableTrash.size)
         }
+        self.labelInfo?.text = infoText
+        self.accessibilityLabel = tableTrash.trashbinFileName + ", " + infoText
     }
 }