diff --git a/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings b/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings index fe9d516efdfb0e2bd0dd3cc7902e78c81ffdb736..38de31acd2aaf9e7adddf38152d9a294357c0e44 100644 --- a/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings +++ b/ElementX/Resources/Localizations/en-US.lproj/Localizable.strings @@ -8,6 +8,7 @@ "a11y_notifications_muted" = "Muted"; "a11y_page_n" = "Page %1$d"; "a11y_pause" = "Pause"; +"a11y_paused_voice_message" = "Voice message, duration: %1$@, current position: %2$@"; "a11y_pin_field" = "PIN field"; "a11y_play" = "Play"; "a11y_poll_end" = "Ended poll"; @@ -22,6 +23,7 @@ "a11y_show_password" = "Show password"; "a11y_start_call" = "Start a call"; "a11y_user_menu" = "User menu"; +"a11y_voice_message" = "Voice message, duration: %1$@"; "a11y_voice_message_record" = "Record voice message."; "a11y_voice_message_stop_recording" = "Stop recording"; "a11y.view_details" = "View details"; diff --git a/ElementX/Resources/Localizations/en.lproj/Localizable.strings b/ElementX/Resources/Localizations/en.lproj/Localizable.strings index db6b8abd8e682d735e6adb219e6d2c48b94ba1b3..c225c470c18cde1954e43d8927c09853ab1eefb5 100644 --- a/ElementX/Resources/Localizations/en.lproj/Localizable.strings +++ b/ElementX/Resources/Localizations/en.lproj/Localizable.strings @@ -8,6 +8,7 @@ "a11y_notifications_muted" = "Muted"; "a11y_page_n" = "Page %1$d"; "a11y_pause" = "Pause"; +"a11y_paused_voice_message" = "Voice message, duration: %1$@, current position: %2$@"; "a11y_pin_field" = "PIN field"; "a11y_play" = "Play"; "a11y_poll_end" = "Ended poll"; @@ -22,6 +23,7 @@ "a11y_show_password" = "Show password"; "a11y_start_call" = "Start a call"; "a11y_user_menu" = "User menu"; +"a11y_voice_message" = "Voice message, duration: %1$@"; "a11y_voice_message_record" = "Record voice message."; "a11y_voice_message_stop_recording" = "Stop recording"; "a11y.view_details" = "View details"; diff --git a/ElementX/Sources/Generated/Strings.swift b/ElementX/Sources/Generated/Strings.swift index fbc0442303bc2f6d7925104196e179206c67d8b0..28caf035116d4d90a5c4d62cdfd616f9129ddc09 100644 --- a/ElementX/Sources/Generated/Strings.swift +++ b/ElementX/Sources/Generated/Strings.swift @@ -34,6 +34,10 @@ internal enum L10n { } /// Pause internal static var a11yPause: String { return L10n.tr("Localizable", "a11y_pause") } + /// Voice message, duration: %1$@, current position: %2$@ + internal static func a11yPausedVoiceMessage(_ p1: Any, _ p2: Any) -> String { + return L10n.tr("Localizable", "a11y_paused_voice_message", String(describing: p1), String(describing: p2)) + } /// PIN field internal static var a11yPinField: String { return L10n.tr("Localizable", "a11y_pin_field") } /// Play @@ -76,6 +80,10 @@ internal enum L10n { internal static var a11yStartCall: String { return L10n.tr("Localizable", "a11y_start_call") } /// User menu internal static var a11yUserMenu: String { return L10n.tr("Localizable", "a11y_user_menu") } + /// Voice message, duration: %1$@ + internal static func a11yVoiceMessage(_ p1: Any) -> String { + return L10n.tr("Localizable", "a11y_voice_message", String(describing: p1)) + } /// Record voice message. internal static var a11yVoiceMessageRecord: String { return L10n.tr("Localizable", "a11y_voice_message_record") } /// Stop recording diff --git a/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemAccessibilityModifier.swift b/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemAccessibilityModifier.swift index 18a98b3b03d61055c2b11de159b54b89b3986d71..7335d5915e928d9c6526441a54e3d1041f420e60 100644 --- a/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemAccessibilityModifier.swift +++ b/ElementX/Sources/Screens/Timeline/View/Style/TimelineItemAccessibilityModifier.swift @@ -14,7 +14,7 @@ private struct TimelineItemAccessibilityModifier: ViewModifier { @ViewBuilder func body(content: Content) -> some View { switch timelineItem { - case is PollRoomTimelineItem, is VoiceMessageRoomTimelineItem: + case is PollRoomTimelineItem: content .accessibilityActions { Button(L10n.commonMessageActions) { diff --git a/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/VoiceMessageRoomTimelineView.swift b/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/VoiceMessageRoomTimelineView.swift index 24f9161e3ff89dd6faa3ff07735a0ec8ec57106a..ea39a87a593bc70e10dbbac4e4e3e5fe6ceb4a36 100644 --- a/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/VoiceMessageRoomTimelineView.swift +++ b/ElementX/Sources/Screens/Timeline/View/TimelineItemViews/VoiceMessageRoomTimelineView.swift @@ -16,7 +16,6 @@ struct VoiceMessageRoomTimelineView: View { TimelineStyler(timelineItem: timelineItem) { VoiceMessageRoomTimelineContent(timelineItem: timelineItem, playerState: playerState) - .accessibilityLabel(L10n.commonVoiceMessage) .frame(maxWidth: 400) } } diff --git a/ElementX/Sources/Screens/Timeline/View/VoiceMessageRoomPlaybackView.swift b/ElementX/Sources/Screens/Timeline/View/VoiceMessageRoomPlaybackView.swift index 253b55c662a43235cb76a88a605d9fa21a38eba7..7f678b4beadfcba5fc2870bd7949321f7aff9068 100644 --- a/ElementX/Sources/Screens/Timeline/View/VoiceMessageRoomPlaybackView.swift +++ b/ElementX/Sources/Screens/Timeline/View/VoiceMessageRoomPlaybackView.swift @@ -18,18 +18,6 @@ struct VoiceMessageRoomPlaybackView: View { let onPlayPause: () -> Void let onSeek: (Double) -> Void let onScrubbing: (Bool) -> Void - - var timeLabelContent: String { - // Display the duration if progress is 0.0 - let percent = playerState.progress > 0.0 ? playerState.progress : 1.0 - // If the duration is greater or equal 10 minutes, use the long format - let elapsed = Date(timeIntervalSinceReferenceDate: playerState.duration * percent) - if playerState.duration >= 600 { - return DateFormatter.longElapsedTimeFormatter.string(from: elapsed) - } else { - return DateFormatter.elapsedTimeFormatter.string(from: elapsed) - } - } var body: some View { HStack(spacing: 8) { @@ -54,6 +42,38 @@ struct VoiceMessageRoomPlaybackView: View { .onChange(of: isDragging) { _, newValue in onScrubbing(newValue) } + .accessibilityLabel(accessibilityLabel) + } + + // MARK: - Private + + private var durationString: String { + let duration = Date(timeIntervalSinceReferenceDate: playerState.duration) + return if playerState.duration >= 600 { + DateFormatter.longElapsedTimeFormatter.string(from: duration) + } else { + DateFormatter.elapsedTimeFormatter.string(from: duration) + } + } + + private var timeLabelContent: String { + // Display the duration if progress is 0.0 + let percent = playerState.progress > 0.0 ? playerState.progress : 1.0 + // If the duration is greater or equal 10 minutes, use the long format + let elapsed = Date(timeIntervalSinceReferenceDate: playerState.duration * percent) + if playerState.duration >= 600 { + return DateFormatter.longElapsedTimeFormatter.string(from: elapsed) + } else { + return DateFormatter.elapsedTimeFormatter.string(from: elapsed) + } + } + + private var accessibilityLabel: String { + if playerState.progress > 0.0 { + L10n.a11yPausedVoiceMessage(durationString, timeLabelContent) + } else { + L10n.a11yVoiceMessage(durationString) + } } @ViewBuilder