Skip to content

Commit

Permalink
Merge pull request #562 from ualch9/fix_554
Browse files Browse the repository at this point in the history
DRY trip stop accessibility value strings
  • Loading branch information
aaronbrethorst authored Oct 22, 2021
2 parents ef24a2d + 00bcb29 commit 3c2e24f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
14 changes: 13 additions & 1 deletion OBAKit/Trip/TripStopListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,19 @@ final class TripStopCell: OBAListViewCell {

let labels = [config.viewModel.title, config.formatters?.timeFormatter.string(from: config.viewModel.date)]
accessibilityLabel = labels.compactMap { $0 }.joined(separator: "; ")
accessibilityValue = config.formatters?.accessibilityValueForTripStop(isUserDestination: config.viewModel.isUserDestination, isCurrentVehicleLocation: config.viewModel.isCurrentVehicleLocation)

var accessibilityValueFlags: [String] = []

if config.viewModel.isUserDestination {
accessibilityValueFlags.append(OBALoc("trip_stop.user_destination.accessibility_label", value: "Your destination", comment: "Voiceover text explaining that this stop is the user's destination"))
}

if config.viewModel.isCurrentVehicleLocation {
accessibilityValueFlags.append(OBALoc("trip_stop.vehicle_location.accessibility_label", value: "Vehicle is here", comment: "Voiceover text explaining that the vehicle is currently at this stop"))
}

let joined = accessibilityValueFlags.joined(separator: ", ")
accessibilityValue = joined.isEmpty ? nil : joined
}

private func apply(adjacentTripConfiguration config: AdjacentTripRowConfiguration) {
Expand Down
16 changes: 0 additions & 16 deletions OBAKitCore/Utilities/Formatters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,6 @@ public class Formatters: NSObject {
return String(format: OBALoc("voiceover.arrivaldeparture_route_fmt", value: "Route %@", comment: "VoiceOver text describing the name of a route in a verbose fashion to compensate for no visuals."), routeAndHeadsign)
}

// MARK: Accessibility value
public func accessibilityValueForTripStop(isUserDestination: Bool, isCurrentVehicleLocation: Bool) -> String? {
var flags: [String] = []

if isUserDestination {
flags.append(OBALoc("trip_stop.user_destination.accessibility_label", value: "Your destination", comment: "Voiceover text explaining that this stop is the user's destination"))
}

if isCurrentVehicleLocation {
flags.append(OBALoc("trip_stop.vehicle_location.accessibility_label", value: "Vehicle is here", comment: "Voiceover text explaining that the vehicle is currently at this stop"))
}

let joined = flags.joined(separator: ", ")
return joined.isEmpty ? nil : joined
}

/// Creates a localized string appropriate for using in UIAccessibility.accessibilityValue.
/// - Note: This does not include schedule deviation information.
/// ## Examples
Expand Down

0 comments on commit 3c2e24f

Please sign in to comment.