From 328885dec78c266521bb69ccef9256cb497de025 Mon Sep 17 00:00:00 2001 From: Qinmei Du Date: Tue, 10 Jan 2023 05:28:46 +0000 Subject: [PATCH] =?UTF-8?q?Add=20the=20confirm=20button=20on=20the=20get?= =?UTF-8?q?=20flow=20and=20remove=20the=20Sign=20in=20another=20way=20butt?= =?UTF-8?q?on=20if=20there=E2=80=99s=20no=20other=20entries=20to=20show=20?= =?UTF-8?q?in=20the=20next=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Screenshots: 1. When there's only one acount and no other entries: https://screenshot.googleplex.com/8u2u3WNbLe8AiS7 2. When there's only one account but other entries: https://screenshot.googleplex.com/937Ba2QdtFMrn9P 3. When there's multiple accounts: https://screenshot.googleplex.com/4uxuRuSTLP95Jui Test: deployed locally Bug: 264959820 Fix: 264959820 Change-Id: I6f6ef879a0ff4bd4f17da35f0300df75c09190b1 --- .../getflow/GetCredentialComponents.kt | 35 ++++++++++++++++--- .../getflow/GetCredentialViewModel.kt | 32 +++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt index 03f39e1390c78..0a785d6fe8f8c 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialComponents.kt @@ -63,6 +63,7 @@ import com.android.credentialmanager.common.material.ModalBottomSheetLayout import com.android.credentialmanager.common.material.ModalBottomSheetValue import com.android.credentialmanager.common.material.rememberModalBottomSheetState import com.android.credentialmanager.common.ui.ActionButton +import com.android.credentialmanager.common.ui.ConfirmButton import com.android.credentialmanager.common.ui.Entry import com.android.credentialmanager.common.ui.TextOnSurface import com.android.credentialmanager.common.ui.TextSecondary @@ -95,7 +96,10 @@ fun GetCredentialScreen( PrimarySelectionCard( requestDisplayInfo = uiState.requestDisplayInfo, providerDisplayInfo = uiState.providerDisplayInfo, + providerInfoList = uiState.providerInfoList, + activeEntry = uiState.activeEntry, onEntrySelected = viewModel::onEntrySelected, + onConfirm = viewModel::onConfirmEntrySelected, onMoreOptionSelected = viewModel::onMoreOptionSelected, ) } else { @@ -133,7 +137,10 @@ fun GetCredentialScreen( fun PrimarySelectionCard( requestDisplayInfo: RequestDisplayInfo, providerDisplayInfo: ProviderDisplayInfo, + providerInfoList: List, + activeEntry: EntryInfo?, onEntrySelected: (EntryInfo) -> Unit, + onConfirm: () -> Unit, onMoreOptionSelected: () -> Unit, ) { val sortedUserNameToCredentialEntryList = @@ -217,13 +224,33 @@ fun PrimarySelectionCard( thickness = 24.dp, color = Color.Transparent ) + var totalEntriesCount = sortedUserNameToCredentialEntryList + .flatMap{ it.sortedCredentialEntryList}.size + authenticationEntryList + .size + providerInfoList.flatMap { it.actionEntryList }.size + if (providerDisplayInfo.remoteEntry != null) totalEntriesCount += 1 + // Row horizontalArrangement differs on only one actionButton(should place on most + // left)/only one confirmButton(should place on most right)/two buttons exist the same + // time(should be one on the left, one on the right) Row( - horizontalArrangement = Arrangement.SpaceBetween, + horizontalArrangement = + if (totalEntriesCount <= 1 && activeEntry != null) Arrangement.End + else if (totalEntriesCount > 1 && activeEntry == null) Arrangement.Start + else Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth().padding(horizontal = 24.dp) ) { - ActionButton( - stringResource(R.string.get_dialog_use_saved_passkey_for), - onMoreOptionSelected) + if (totalEntriesCount > 1) { + ActionButton( + stringResource(R.string.get_dialog_use_saved_passkey_for), + onMoreOptionSelected + ) + } + // Only one sign-in options exist + if (activeEntry != null) { + ConfirmButton( + stringResource(R.string.string_continue), + onClick = onConfirm + ) + } } Divider( thickness = 18.dp, diff --git a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt index 6f0f76b72e509..9859c89b29d4c 100644 --- a/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt +++ b/packages/CredentialManager/src/com/android/credentialmanager/getflow/GetCredentialViewModel.kt @@ -41,6 +41,7 @@ data class GetCredentialUiState( val currentScreenState: GetScreenState = toGetScreenState(providerInfoList), val providerDisplayInfo: ProviderDisplayInfo = toProviderDisplayInfo(providerInfoList), val selectedEntry: EntryInfo? = null, + val activeEntry: EntryInfo? = toActiveEntry(providerDisplayInfo), val hidden: Boolean = false, val providerActivityPending: Boolean = false, val isNoAccount: Boolean = false, @@ -73,6 +74,17 @@ class GetCredentialViewModel(private val credManRepo: CredentialManagerRepo) : V } } + fun onConfirmEntrySelected() { + val activeEntry = uiState.activeEntry + if (activeEntry != null) { + onEntrySelected(activeEntry) + } else { + Log.w("Account Selector", + "Illegal state: confirm is pressed but activeEntry isn't set.") + dialogResult.tryEmit(DialogResult(ResultState.COMPLETE)) + } + } + fun launchProviderUi( launcher: ManagedActivityResultLauncher ) { @@ -198,6 +210,26 @@ private fun toProviderDisplayInfo( ) } +private fun toActiveEntry( + providerDisplayInfo: ProviderDisplayInfo, +): EntryInfo? { + val sortedUserNameToCredentialEntryList = + providerDisplayInfo.sortedUserNameToCredentialEntryList + val authenticationEntryList = providerDisplayInfo.authenticationEntryList + var activeEntry: EntryInfo? = null + if (sortedUserNameToCredentialEntryList + .size == 1 && authenticationEntryList.isEmpty() + ) { + activeEntry = sortedUserNameToCredentialEntryList.first().sortedCredentialEntryList.first() + } else if ( + sortedUserNameToCredentialEntryList + .isEmpty() && authenticationEntryList.size == 1 + ) { + activeEntry = authenticationEntryList.first() + } + return activeEntry +} + private fun toGetScreenState( providerInfoList: List ): GetScreenState {