mirror of
https://github.com/bitwarden/android.git
synced 2026-06-02 02:36:58 -05:00
BIT-1469: Autofill talkback (#1226)
This commit is contained in:
committed by
Álison Fernandes
parent
8f3f87a333
commit
1a12a91a74
@@ -6,6 +6,7 @@ import androidx.annotation.DrawableRes
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillAppInfo
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillCipher
|
||||
import com.x8bit.bitwarden.ui.autofill.util.getAutofillSuggestionContentDescription
|
||||
import com.x8bit.bitwarden.ui.autofill.util.isSystemDarkMode
|
||||
|
||||
/**
|
||||
@@ -21,6 +22,10 @@ fun buildAutofillRemoteViews(
|
||||
subtitle = autofillCipher.subtitle,
|
||||
iconRes = autofillCipher.iconRes,
|
||||
shouldTintIcon = true,
|
||||
autofillContentDescription = getAutofillSuggestionContentDescription(
|
||||
autofillCipher = autofillCipher,
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
),
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -42,10 +47,13 @@ fun buildVaultItemAutofillRemoteViews(
|
||||
},
|
||||
iconRes = R.drawable.icon,
|
||||
shouldTintIcon = false,
|
||||
autofillContentDescription = null,
|
||||
)
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
private fun buildAutofillRemoteViews(
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
autofillContentDescription: String?,
|
||||
name: String,
|
||||
subtitle: String,
|
||||
@DrawableRes iconRes: Int,
|
||||
@@ -56,6 +64,12 @@ private fun buildAutofillRemoteViews(
|
||||
R.layout.autofill_remote_view,
|
||||
)
|
||||
.apply {
|
||||
autofillContentDescription?.let {
|
||||
setContentDescription(
|
||||
R.id.container,
|
||||
it,
|
||||
)
|
||||
}
|
||||
setTextViewText(
|
||||
R.id.title,
|
||||
name,
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.x8bit.bitwarden.ui.autofill.util
|
||||
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillAppInfo
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillCipher
|
||||
|
||||
/**
|
||||
* Creates content description for an autofill suggestion given an [AutofillCipher] and
|
||||
* [AutofillAppInfo].
|
||||
*/
|
||||
fun getAutofillSuggestionContentDescription(
|
||||
autofillCipher: AutofillCipher,
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
): String =
|
||||
String.format(
|
||||
"%s, %s, %s, %s",
|
||||
ContextCompat.getString(autofillAppInfo.context, R.string.autofill_suggestion),
|
||||
getAutofillSuggestionCipherType(
|
||||
autofillCipher = autofillCipher,
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
),
|
||||
autofillCipher.name,
|
||||
autofillCipher.subtitle,
|
||||
)
|
||||
|
||||
private fun getAutofillSuggestionCipherType(
|
||||
autofillCipher: AutofillCipher,
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
): String =
|
||||
when (autofillCipher) {
|
||||
is AutofillCipher.Card -> ContextCompat.getString(
|
||||
autofillAppInfo.context,
|
||||
R.string.type_card,
|
||||
)
|
||||
|
||||
is AutofillCipher.Login -> ContextCompat.getString(
|
||||
autofillAppInfo.context,
|
||||
R.string.type_login,
|
||||
)
|
||||
}
|
||||
@@ -35,6 +35,7 @@ fun InlinePresentationSpec.createCipherInlinePresentationOrNull(
|
||||
PendingIntent.FLAG_IMMUTABLE,
|
||||
),
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
autofillCipher = autofillCipher,
|
||||
title = autofillCipher.name,
|
||||
subtitle = autofillCipher.subtitle,
|
||||
iconRes = autofillCipher.iconRes,
|
||||
@@ -54,6 +55,7 @@ fun InlinePresentationSpec.createVaultItemInlinePresentationOrNull(
|
||||
createInlinePresentationOrNull(
|
||||
pendingIntent = pendingIntent,
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
autofillCipher = null,
|
||||
title = autofillAppInfo.context.getString(R.string.app_name),
|
||||
subtitle = if (isLocked) {
|
||||
autofillAppInfo.context.getString(R.string.vault_is_locked)
|
||||
@@ -70,6 +72,7 @@ fun InlinePresentationSpec.createVaultItemInlinePresentationOrNull(
|
||||
private fun InlinePresentationSpec.createInlinePresentationOrNull(
|
||||
pendingIntent: PendingIntent,
|
||||
autofillAppInfo: AutofillAppInfo,
|
||||
autofillCipher: AutofillCipher?,
|
||||
title: String,
|
||||
subtitle: String,
|
||||
@DrawableRes iconRes: Int,
|
||||
@@ -96,6 +99,16 @@ private fun InlinePresentationSpec.createInlinePresentationOrNull(
|
||||
}
|
||||
val slice = InlineSuggestionUi
|
||||
.newContentBuilder(pendingIntent)
|
||||
.also { contentBuilder ->
|
||||
autofillCipher?.let {
|
||||
contentBuilder.setContentDescription(
|
||||
getAutofillSuggestionContentDescription(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
autofillCipher = it,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
.setTitle(title)
|
||||
.setSubtitle(subtitle)
|
||||
.setStartIcon(icon)
|
||||
|
||||
Reference in New Issue
Block a user