You've already forked element-android
mirror of
https://github.com/vector-im/element-android.git
synced 2025-07-31 07:04:23 +03:00
Improve accessibility for avatar of users, rooms and spaces.
This commit is contained in:
@ -1470,6 +1470,9 @@
|
|||||||
<string name="reason_colon">Reason: %1$s</string>
|
<string name="reason_colon">Reason: %1$s</string>
|
||||||
|
|
||||||
<string name="avatar">Avatar</string>
|
<string name="avatar">Avatar</string>
|
||||||
|
<string name="avatar_of_space">Avatar of space %1$s</string>
|
||||||
|
<string name="avatar_of_room">Avatar of room %1$s</string>
|
||||||
|
<string name="avatar_of_user">Profile picture of user %1$s</string>
|
||||||
|
|
||||||
<!-- Consent modal -->
|
<!-- Consent modal -->
|
||||||
<string name="dialog_user_consent_content">To continue using the %1$s homeserver you must review and agree to the terms and conditions.</string>
|
<string name="dialog_user_consent_content">To continue using the %1$s homeserver you must review and agree to the terms and conditions.</string>
|
||||||
|
@ -35,13 +35,16 @@ import com.bumptech.glide.request.RequestOptions
|
|||||||
import com.bumptech.glide.request.target.DrawableImageViewTarget
|
import com.bumptech.glide.request.target.DrawableImageViewTarget
|
||||||
import com.bumptech.glide.request.target.Target
|
import com.bumptech.glide.request.target.Target
|
||||||
import com.bumptech.glide.signature.ObjectKey
|
import com.bumptech.glide.signature.ObjectKey
|
||||||
|
import im.vector.app.R
|
||||||
import im.vector.app.core.contacts.MappedContact
|
import im.vector.app.core.contacts.MappedContact
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.glide.AvatarPlaceholder
|
import im.vector.app.core.glide.AvatarPlaceholder
|
||||||
import im.vector.app.core.glide.GlideApp
|
import im.vector.app.core.glide.GlideApp
|
||||||
import im.vector.app.core.glide.GlideRequest
|
import im.vector.app.core.glide.GlideRequest
|
||||||
import im.vector.app.core.glide.GlideRequests
|
import im.vector.app.core.glide.GlideRequests
|
||||||
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.utils.DimensionConverter
|
import im.vector.app.core.utils.DimensionConverter
|
||||||
|
import im.vector.app.features.displayname.getBestName
|
||||||
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
|
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
|
||||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||||
import jp.wasabeef.glide.transformations.ColorFilterTransformation
|
import jp.wasabeef.glide.transformations.ColorFilterTransformation
|
||||||
@ -58,7 +61,8 @@ import javax.inject.Inject
|
|||||||
class AvatarRenderer @Inject constructor(
|
class AvatarRenderer @Inject constructor(
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
private val activeSessionHolder: ActiveSessionHolder,
|
||||||
private val matrixItemColorProvider: MatrixItemColorProvider,
|
private val matrixItemColorProvider: MatrixItemColorProvider,
|
||||||
private val dimensionConverter: DimensionConverter
|
private val dimensionConverter: DimensionConverter,
|
||||||
|
private val stringProvider: StringProvider,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@ -67,6 +71,7 @@ class AvatarRenderer @Inject constructor(
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun render(matrixItem: MatrixItem, imageView: ImageView) {
|
fun render(matrixItem: MatrixItem, imageView: ImageView) {
|
||||||
|
imageView.setContentDescription(matrixItem)
|
||||||
render(
|
render(
|
||||||
GlideApp.with(imageView),
|
GlideApp.with(imageView),
|
||||||
matrixItem,
|
matrixItem,
|
||||||
@ -100,6 +105,7 @@ class AvatarRenderer @Inject constructor(
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun render(matrixItem: MatrixItem, imageView: ImageView, glideRequests: GlideRequests) {
|
fun render(matrixItem: MatrixItem, imageView: ImageView, glideRequests: GlideRequests) {
|
||||||
|
imageView.setContentDescription(matrixItem)
|
||||||
render(
|
render(
|
||||||
glideRequests,
|
glideRequests,
|
||||||
matrixItem,
|
matrixItem,
|
||||||
@ -109,6 +115,7 @@ class AvatarRenderer @Inject constructor(
|
|||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun render(matrixItem: MatrixItem, localUri: Uri?, imageView: ImageView) {
|
fun render(matrixItem: MatrixItem, localUri: Uri?, imageView: ImageView) {
|
||||||
|
imageView.setContentDescription(matrixItem)
|
||||||
val placeholder = getPlaceholderDrawable(matrixItem)
|
val placeholder = getPlaceholderDrawable(matrixItem)
|
||||||
GlideApp.with(imageView)
|
GlideApp.with(imageView)
|
||||||
.load(localUri?.let { File(localUri.path!!) })
|
.load(localUri?.let { File(localUri.path!!) })
|
||||||
@ -295,4 +302,28 @@ class AvatarRenderer @Inject constructor(
|
|||||||
return activeSessionHolder.getSafeActiveSession()?.contentUrlResolver()
|
return activeSessionHolder.getSafeActiveSession()?.contentUrlResolver()
|
||||||
?.resolveThumbnail(avatarUrl, THUMBNAIL_SIZE, THUMBNAIL_SIZE, ContentUrlResolver.ThumbnailMethod.SCALE)
|
?.resolveThumbnail(avatarUrl, THUMBNAIL_SIZE, THUMBNAIL_SIZE, ContentUrlResolver.ThumbnailMethod.SCALE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accessibility management.
|
||||||
|
*/
|
||||||
|
private fun ImageView.setContentDescription(matrixItem: MatrixItem) {
|
||||||
|
// Do not set contentDescription if the ImageView should be ignored regarding accessibility.
|
||||||
|
if (isImportantForAccessibility.not()) return
|
||||||
|
when (matrixItem) {
|
||||||
|
is MatrixItem.SpaceItem -> {
|
||||||
|
contentDescription = stringProvider.getString(R.string.avatar_of_space, matrixItem.getBestName())
|
||||||
|
}
|
||||||
|
is MatrixItem.RoomAliasItem,
|
||||||
|
is MatrixItem.RoomItem -> {
|
||||||
|
contentDescription = stringProvider.getString(R.string.avatar_of_room, matrixItem.getBestName())
|
||||||
|
}
|
||||||
|
is MatrixItem.UserItem -> {
|
||||||
|
contentDescription = stringProvider.getString(R.string.avatar_of_user, matrixItem.getBestName())
|
||||||
|
}
|
||||||
|
is MatrixItem.EveryoneInRoomItem,
|
||||||
|
is MatrixItem.EventItem -> {
|
||||||
|
// NA
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user