Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 334f5826 authored by Qinmei Du's avatar Qinmei Du Committed by Android (Google) Code Review
Browse files

Merge "Add the confirm button on the get flow and remove the Sign in another...

Merge "Add the confirm button on the get flow and remove the Sign in another way button if there’s no other entries to show in the next page"
parents 9f46cdcb 328885de
Loading
Loading
Loading
Loading
+31 −4
Original line number Diff line number Diff line
@@ -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<ProviderInfo>,
    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)
            ) {
                if (totalEntriesCount > 1) {
                    ActionButton(
                        stringResource(R.string.get_dialog_use_saved_passkey_for),
                    onMoreOptionSelected)
                        onMoreOptionSelected
                    )
                }
                // Only one sign-in options exist
                if (activeEntry != null) {
                    ConfirmButton(
                        stringResource(R.string.string_continue),
                        onClick = onConfirm
                    )
                }
            }
            Divider(
                thickness = 18.dp,
+32 −0
Original line number Diff line number Diff line
@@ -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<IntentSenderRequest, ActivityResult>
  ) {
@@ -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<ProviderInfo>
): GetScreenState {