From 3115abc72ea5df93607c57e2aa8701d27fdc60b0 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 9 Jan 2020 14:38:25 -0700 Subject: [PATCH] Enhance accessibility for toggle toolbar buttons. Issue #1581 --- iOS/Article/ArticleExtractorButton.swift | 18 ++++++++++++++++++ iOS/Article/ArticleViewController.swift | 18 ++++++++++++++---- iOS/MasterFeed/MasterFeedViewController.swift | 18 ++++++++++++++---- .../MasterTimelineViewController.swift | 18 ++++++++++++++---- 4 files changed, 60 insertions(+), 12 deletions(-) diff --git a/iOS/Article/ArticleExtractorButton.swift b/iOS/Article/ArticleExtractorButton.swift index 8806f1676..a93e40cc8 100644 --- a/iOS/Article/ArticleExtractorButton.swift +++ b/iOS/Article/ArticleExtractorButton.swift @@ -38,6 +38,24 @@ class ArticleExtractorButton: UIButton { } } + override var accessibilityLabel: String? { + get { + switch buttonState { + case .error: + return NSLocalizedString("Error - Reader View", comment: "Error - Reader View") + case .animated: + return NSLocalizedString("Processing - Reader View", comment: "Processing - Reader View") + case .on: + return NSLocalizedString("Selected - Reader View", comment: "Selected - Reader View") + case .off: + return NSLocalizedString("Reader View", comment: "Reader View") + } + } + set { + super.accessibilityLabel = newValue + } + } + override func layoutSubviews() { super.layoutSubviews() guard case .animated = buttonState else { diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 968e7f2cb..8ee6e9088 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -135,11 +135,21 @@ class ArticleViewController: UIViewController { starBarButtonItem.isEnabled = true actionBarButtonItem.isEnabled = true - let readImage = article.status.read ? AppAssets.circleOpenImage : AppAssets.circleClosedImage - readBarButtonItem.image = readImage + if article.status.read { + readBarButtonItem.image = AppAssets.circleOpenImage + readBarButtonItem.accLabelText = NSLocalizedString("Mark Article Unread", comment: "Mark Article Unread") + } else { + readBarButtonItem.image = AppAssets.circleClosedImage + readBarButtonItem.accLabelText = NSLocalizedString("Selected - Mark Article Unread", comment: "Selected - Mark Article Unread") + } - let starImage = article.status.starred ? AppAssets.starClosedImage : AppAssets.starOpenImage - starBarButtonItem.image = starImage + if article.status.starred { + starBarButtonItem.image = AppAssets.starClosedImage + starBarButtonItem.accLabelText = NSLocalizedString("Selected - Star Article", comment: "Selected - Star Article") + } else { + starBarButtonItem.image = AppAssets.starOpenImage + starBarButtonItem.accLabelText = NSLocalizedString("Star Article", comment: "Star Article") + } } diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 6c1a348b2..771c31382 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -402,10 +402,10 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { @IBAction func toggleFilter(_ sender: Any) { if coordinator.isReadFeedsFiltered { - filterButton.image = AppAssets.filterInactiveImage + setFilterButtonToInactive() coordinator.showAllFeeds() } else { - filterButton.image = AppAssets.filterActiveImage + setFilterButtonToActive() coordinator.hideReadFeeds() } } @@ -674,14 +674,24 @@ private extension MasterFeedViewController { func updateUI() { if coordinator.isReadFeedsFiltered { - filterButton?.image = AppAssets.filterActiveImage + setFilterButtonToActive() } else { - filterButton?.image = AppAssets.filterInactiveImage + setFilterButtonToInactive() } refreshProgressView?.updateRefreshLabel() addNewItemButton?.isEnabled = !AccountManager.shared.activeAccounts.isEmpty } + func setFilterButtonToActive() { + filterButton?.image = AppAssets.filterActiveImage + filterButton?.accLabelText = NSLocalizedString("Selected - Filter Read Feeds", comment: "Selected - Filter Read Feeds") + } + + func setFilterButtonToInactive() { + filterButton?.image = AppAssets.filterInactiveImage + filterButton?.accLabelText = NSLocalizedString("Filter Read Feeds", comment: "Filter Read Feeds") + } + func reloadNode(_ node: Node) { var snapshot = dataSource.snapshot() snapshot.reloadItems([node]) diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index 46c476e8e..6c933f5d4 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -112,10 +112,10 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner // MARK: Actions @IBAction func toggleFilter(_ sender: Any) { if coordinator.isReadArticlesFiltered { - filterButton.image = AppAssets.filterInactiveImage + setFilterButtonToInactive() coordinator.showAllArticles() } else { - filterButton.image = AppAssets.filterActiveImage + setFilterButtonToActive() coordinator.hideReadArticles() } } @@ -579,9 +579,9 @@ private extension MasterTimelineViewController { } if coordinator.isReadArticlesFiltered { - filterButton.image = AppAssets.filterActiveImage + setFilterButtonToActive() } else { - filterButton.image = AppAssets.filterInactiveImage + setFilterButtonToInactive() } tableView.selectRow(at: nil, animated: false, scrollPosition: .top) @@ -599,6 +599,16 @@ private extension MasterTimelineViewController { updateToolbar() } + func setFilterButtonToActive() { + filterButton?.image = AppAssets.filterActiveImage + filterButton?.accLabelText = NSLocalizedString("Selected - Filter Read Articles", comment: "Selected - Filter Read Articles") + } + + func setFilterButtonToInactive() { + filterButton?.image = AppAssets.filterInactiveImage + filterButton?.accLabelText = NSLocalizedString("Filter Read Articles", comment: "Filter Read Articles") + } + func updateToolbar() { markAllAsReadButton.isEnabled = coordinator.isTimelineUnreadAvailable firstUnreadButton.isEnabled = coordinator.isTimelineUnreadAvailable