Improves accessibility on MessageAudioItem

This commit is contained in:
ericdecanini 2022-04-05 16:01:37 +01:00
parent 76b2cfdf40
commit dc36301070
2 changed files with 21 additions and 2 deletions

View file

@ -16,6 +16,7 @@
package im.vector.app.features.home.room.detail.timeline.item package im.vector.app.features.home.room.detail.timeline.item
import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.Color import android.graphics.Color
import android.graphics.Paint import android.graphics.Paint
@ -105,11 +106,20 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
} }
private fun bindViewAttributes(holder: Holder) { private fun bindViewAttributes(holder: Holder) {
val formattedDuration = formatPlaybackTime(duration)
val formattedFileSize = TextUtils.formatFileSize(holder.rootLayout.context, fileSize, true)
val durationContentDescription = getPlaybackTimeContentDescription(holder.rootLayout.context, duration)
holder.filenameView.text = filename holder.filenameView.text = filename
holder.filenameView.onClick(attributes.itemClickListener) holder.filenameView.onClick(attributes.itemClickListener)
holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG) holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG)
holder.audioPlaybackDuration.text = formatPlaybackTime(duration) holder.audioPlaybackDuration.text = formattedDuration
holder.fileSize.text = TextUtils.formatFileSize(holder.rootLayout.context, fileSize, true) holder.fileSize.text = holder.rootLayout.context.getString(
R.string.audio_message_file_size, formattedFileSize
)
holder.mainLayout.contentDescription = holder.rootLayout.context.getString(
R.string.a11y_audio_message_item, filename, durationContentDescription, formattedFileSize
)
} }
private fun bindSeekBar(holder: Holder) { private fun bindSeekBar(holder: Holder) {
@ -172,6 +182,12 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
private fun formatPlaybackTime(time: Int) = DateUtils.formatElapsedTime((time / 1000).toLong()) private fun formatPlaybackTime(time: Int) = DateUtils.formatElapsedTime((time / 1000).toLong())
private fun getPlaybackTimeContentDescription(context: Context, time: Int): String {
val formattedPlaybackTime = formatPlaybackTime(time)
val (minutes, seconds) = formattedPlaybackTime.split(":").map { it.toIntOrNull() ?: 0 }
return context.getString(R.string.a11y_audio_playback_duration, minutes, seconds)
}
override fun unbind(holder: Holder) { override fun unbind(holder: Holder) {
super.unbind(holder) super.unbind(holder)
contentUploadStateTrackerBinder.unbind(attributes.informationData.eventId) contentUploadStateTrackerBinder.unbind(attributes.informationData.eventId)

View file

@ -2860,10 +2860,13 @@
<string name="error_voice_message_cannot_reply_or_edit">Cannot reply or edit while voice message is active</string> <string name="error_voice_message_cannot_reply_or_edit">Cannot reply or edit while voice message is active</string>
<string name="voice_message_reply_content">Voice Message (%1$s)</string> <string name="voice_message_reply_content">Voice Message (%1$s)</string>
<string name="a11y_audio_message_item">%1$s, %2$s, %3$s</string> <!-- filename, duration, file size -->
<string name="a11y_audio_playback_duration">%1$d minutes %2$d seconds</string>
<string name="a11y_play_audio_message">Play %1$s</string> <string name="a11y_play_audio_message">Play %1$s</string>
<string name="a11y_pause_audio_message">Pause %1$s</string> <string name="a11y_pause_audio_message">Pause %1$s</string>
<string name="error_audio_message_unable_to_play">Unable to play %1$s</string> <string name="error_audio_message_unable_to_play">Unable to play %1$s</string>
<string name="audio_message_reply_content">%1$s (%2$s)</string> <string name="audio_message_reply_content">%1$s (%2$s)</string>
<string name="audio_message_file_size">(%1$s)</string>
<string name="upgrade_room_for_restricted">Anyone in %s will be able to find and join this room - no need to manually invite everyone. Youll be able to change this in room settings anytime.</string> <string name="upgrade_room_for_restricted">Anyone in %s will be able to find and join this room - no need to manually invite everyone. Youll be able to change this in room settings anytime.</string>
<string name="upgrade_room_for_restricted_no_param">Anyone in a parent space will be able to find and join this room - no need to manually invite everyone. Youll be able to change this in room settings anytime.</string> <string name="upgrade_room_for_restricted_no_param">Anyone in a parent space will be able to find and join this room - no need to manually invite everyone. Youll be able to change this in room settings anytime.</string>