summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Helen Qin <helenqin@google.com> 2023-03-06 18:10:16 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-03-06 18:10:16 +0000
commit82348e00b8b3f002b4fb085c6edaaecc17856fe1 (patch)
tree712dc3088037a8d21cf83bfdba0e35600be091c5
parentdcefc1b20cdc97dfed973a18c820cad0d7e62f9e (diff)
parent46dd975b20ca8f8a87e260edfd951312427a4a3c (diff)
Merge "[CredManUi] Truncate credential entry texts on the first page." into udc-dev
-rw-r--r--packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt16
-rw-r--r--packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt9
-rw-r--r--packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt1
-rw-r--r--packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt9
4 files changed, 27 insertions, 8 deletions
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
index 6abfde5e90c9..c0c29bb021d0 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Entry.kt
@@ -74,6 +74,7 @@ fun Entry(
passwordValue: String? = null,
/** If true, draws a trailing lock icon. */
isLockedAuthEntry: Boolean = false,
+ enforceOneLine: Boolean = false,
) {
val iconPadding = Modifier.wrapContentSize().padding(
// Horizontal padding should be 16dp, but the suggestion chip itself
@@ -93,10 +94,12 @@ fun Entry(
// has 8dp horizontal elements padding
horizontal = 8.dp, vertical = 16.dp,
),
+ // Make sure the trailing icon and text column are centered vertically.
verticalAlignment = Alignment.CenterVertically,
) {
- Column(modifier = Modifier.wrapContentSize()) {
- SmallTitleText(entryHeadlineText)
+ // Apply weight so that the trailing icon can always show.
+ Column(modifier = Modifier.wrapContentHeight().fillMaxWidth().weight(1f)) {
+ SmallTitleText(text = entryHeadlineText, enforceOneLine = enforceOneLine)
if (passwordValue != null) {
Row(
modifier = Modifier.fillMaxWidth(),
@@ -113,7 +116,8 @@ fun Entry(
).text.text
)
}
- BodySmallText(displayedPassword.value)
+ BodySmallText(
+ text = displayedPassword.value, enforceOneLine = enforceOneLine)
ToggleVisibilityButton(
modifier = Modifier.padding(start = 12.dp, top = 5.dp).size(24.dp),
onToggle = {
@@ -128,14 +132,14 @@ fun Entry(
)
}
} else if (entrySecondLineText != null) {
- BodySmallText(entrySecondLineText)
+ BodySmallText(text = entrySecondLineText, enforceOneLine = enforceOneLine)
}
if (entryThirdLineText != null) {
- BodySmallText(entryThirdLineText)
+ BodySmallText(text = entryThirdLineText, enforceOneLine = enforceOneLine)
}
}
if (isLockedAuthEntry) {
- Box(modifier = Modifier.wrapContentSize()) {
+ Box(modifier = Modifier.wrapContentSize().padding(start = 16.dp)) {
Icon(
imageVector = Icons.Outlined.Lock,
// Decorative purpose only.
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
index 8af729ecdc25..22871bcbe767 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/common/ui/Texts.kt
@@ -23,6 +23,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.text.style.TextOverflow
/**
* The headline for a screen. E.g. "Create a passkey for X", "Choose a saved sign-in for X".
@@ -57,12 +58,14 @@ fun BodyMediumText(text: String, modifier: Modifier = Modifier) {
* Body-small typography; on-surface-variant color.
*/
@Composable
-fun BodySmallText(text: String, modifier: Modifier = Modifier) {
+fun BodySmallText(text: String, modifier: Modifier = Modifier, enforceOneLine: Boolean = false) {
Text(
modifier = modifier.wrapContentSize(),
text = text,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall,
+ overflow = TextOverflow.Ellipsis,
+ maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE
)
}
@@ -83,12 +86,14 @@ fun LargeTitleText(text: String, modifier: Modifier = Modifier) {
* Title-small typography; on-surface color.
*/
@Composable
-fun SmallTitleText(text: String, modifier: Modifier = Modifier) {
+fun SmallTitleText(text: String, modifier: Modifier = Modifier, enforceOneLine: Boolean = false) {
Text(
modifier = modifier.wrapContentSize(),
text = text,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleSmall,
+ overflow = TextOverflow.Ellipsis,
+ maxLines = if (enforceOneLine) 1 else Int.MAX_VALUE
)
}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
index b83c593fdffc..2cb0af4fdeda 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/createflow/CreateCredentialComponents.kt
@@ -637,6 +637,7 @@ fun PrimaryCreateOptionRow(
// This subtitle would never be null for create password
requestDisplayInfo.subtitle ?: ""
else null,
+ enforceOneLine = true,
)
}
diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
index db3cdd5a5f0f..ab947aef8e01 100644
--- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
+++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt
@@ -182,12 +182,14 @@ fun PrimarySelectionCard(
CredentialEntryRow(
credentialEntryInfo = it.sortedCredentialEntryList.first(),
onEntrySelected = onEntrySelected,
+ enforceOneLine = true,
)
}
authenticationEntryList.forEach {
AuthenticationEntryRow(
authenticationEntryInfo = it,
onEntrySelected = onEntrySelected,
+ enforceOneLine = true,
)
}
} else if (usernameForCredentialSize < 4) {
@@ -195,12 +197,14 @@ fun PrimarySelectionCard(
CredentialEntryRow(
credentialEntryInfo = it.sortedCredentialEntryList.first(),
onEntrySelected = onEntrySelected,
+ enforceOneLine = true,
)
}
authenticationEntryList.take(4 - usernameForCredentialSize).forEach {
AuthenticationEntryRow(
authenticationEntryInfo = it,
onEntrySelected = onEntrySelected,
+ enforceOneLine = true,
)
}
} else {
@@ -208,6 +212,7 @@ fun PrimarySelectionCard(
CredentialEntryRow(
credentialEntryInfo = it.sortedCredentialEntryList.first(),
onEntrySelected = onEntrySelected,
+ enforceOneLine = true,
)
}
}
@@ -402,6 +407,7 @@ fun PerUserNameCredentials(
fun CredentialEntryRow(
credentialEntryInfo: CredentialEntryInfo,
onEntrySelected: (BaseEntry) -> Unit,
+ enforceOneLine: Boolean = false,
) {
Entry(
onClick = { onEntrySelected(credentialEntryInfo) },
@@ -426,6 +432,7 @@ fun CredentialEntryRow(
separator = stringResource(R.string.get_dialog_sign_in_type_username_separator)
)
},
+ enforceOneLine = enforceOneLine,
)
}
@@ -433,6 +440,7 @@ fun CredentialEntryRow(
fun AuthenticationEntryRow(
authenticationEntryInfo: AuthenticationEntryInfo,
onEntrySelected: (BaseEntry) -> Unit,
+ enforceOneLine: Boolean = false,
) {
Entry(
onClick = { onEntrySelected(authenticationEntryInfo) },
@@ -444,6 +452,7 @@ fun AuthenticationEntryRow(
else R.string.locked_credential_entry_label_subtext_tap_to_unlock
),
isLockedAuthEntry = !authenticationEntryInfo.isUnlockedAndEmpty,
+ enforceOneLine = enforceOneLine,
)
}