Skip to content

Commit

Permalink
🚧 Fixed warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-sarda committed May 18, 2021
1 parent ed1ef5e commit 69bca4b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ disabled_rules:
- nesting
- identifier_name
line_length: 200
file_length: 800
type_body_length: 500
22 changes: 22 additions & 0 deletions ViteMaDose/Helpers/Extensions/Array+Commons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ extension RangeReplaceableCollection {
return filter { unique.insert($0[keyPath: keyPath]).inserted }
}
}

public protocol OptionalProtocol {
associatedtype Wrapped
var value: Wrapped? { get }
}

extension Sequence where Element: OptionalProtocol {
var compacted: [Element.Wrapped] {
return compactMap(\.value)
}
}

extension Optional: OptionalProtocol {
public var value: Wrapped? {
switch self {
case .none:
return nil
case let .some(value):
return value
}
}
}
47 changes: 31 additions & 16 deletions ViteMaDose/Views/CentresList/Cells/CentreCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ final class CentreCell: UITableViewCell {
configurePhoneNumberView(viewData)
configureChronoDoseView(viewData)
configureFollowCentreButton(viewData)
configureAccessibility(viewData)

let dateText = createDateText(
dayText: viewData.dayText,
Expand All @@ -127,16 +128,6 @@ final class CentreCell: UITableViewCell {
)
dateLabel.attributedText = dateText

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
if let dayText = viewData.dayText, let timeText = viewData.timeText, let dayDate = dateFormatter.date(from: timeText) {
let hourComponents = Calendar.current.dateComponents([.hour, .minute], from: dayDate)
if let localizedHours = DateComponentsFormatter.localizedString(from: hourComponents, unitsStyle: .spellOut) {
dateLabel.accessibilityLabel = dayText + String.space + Localization.A11y.VoiceOver.Details.from + localizedHours
} else {
dateLabel.accessibilityLabel = dayText
}
}
nameLabel.text = viewData.addressNameText
nameLabel.font = Constant.labelPrimaryFont
nameLabel.textColor = Constant.labelPrimaryColor
Expand All @@ -154,14 +145,8 @@ final class CentreCell: UITableViewCell {
vaccineTypesLabel.text = viewData.vaccineTypesText
vaccineTypesLabel.font = Constant.labelPrimaryFont
vaccineTypesLabel.textColor = Constant.labelPrimaryColor
if let vaccineName = viewData.vaccineTypesText {
vaccineTypesLabel.accessibilityLabel = Localization.A11y.VoiceOver.Details.vaccine.format(vaccineName)
}
setCornerRadius(to: Constant.iconContainersCornerRadius, for: iconContainers)
configureAppointmentsLabel(appointmentsCount: viewData.appointmentsCount, partnerLogo: viewData.partnerLogo, partnerName: viewData.partnerName)
accessibilityElements = [
dateLabel, nameLabel, phoneButton, vaccineTypesLabel, bookingButton, appointmentsLabel
]
}

override func prepareForReuse() {
Expand Down Expand Up @@ -369,6 +354,36 @@ final class CentreCell: UITableViewCell {
)
}

private func configureAccessibility(_ viewData: CentreViewData) {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH:mm"
if
let dayText = viewData.dayText,
let timeText = viewData.timeText,
let dayDate = dateFormatter.date(from: timeText)
{
let hourComponents = Calendar.current.dateComponents([.hour, .minute], from: dayDate)
if let localizedHours = DateComponentsFormatter.localizedString(from: hourComponents, unitsStyle: .spellOut) {
dateLabel.accessibilityLabel = dayText + String.space + Localization.A11y.VoiceOver.Details.from + localizedHours
} else {
dateLabel.accessibilityLabel = dayText
}
}

if let vaccineName = viewData.vaccineTypesText {
vaccineTypesLabel.accessibilityLabel = Localization.A11y.VoiceOver.Details.vaccine.format(vaccineName)
}

accessibilityElements = [
dateLabel,
nameLabel,
phoneButton,
vaccineTypesLabel,
bookingButton,
appointmentsLabel
].compacted
}

private func setCornerRadius(to radius: CGFloat, for views: [UIView]) {
views.forEach { $0.setCornerRadius(radius) }
}
Expand Down

0 comments on commit 69bca4b

Please sign in to comment.