1 /*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 @file:OptIn(ExperimentalHorologistApi::class)
18
19 package com.android.credentialmanager.ui.screens.single.passkey
20
21 import androidx.compose.foundation.layout.Column
22 import androidx.compose.runtime.Composable
23 import androidx.compose.ui.res.stringResource
24 import com.android.credentialmanager.FlowEngine
25 import com.android.credentialmanager.model.get.CredentialEntryInfo
26 import com.android.credentialmanager.R
27 import com.android.credentialmanager.ui.components.AccountRow
28 import com.android.credentialmanager.ui.components.ContinueChip
29 import com.android.credentialmanager.ui.components.CredentialsScreenChipSpacer
30 import com.android.credentialmanager.ui.components.DismissChip
31 import com.android.credentialmanager.ui.components.SignInHeader
32 import com.android.credentialmanager.ui.components.SignInOptionsChip
33 import com.android.credentialmanager.ui.screens.single.SingleAccountScreen
34 import com.google.android.horologist.annotations.ExperimentalHorologistApi
35 import com.google.android.horologist.compose.layout.ScalingLazyColumnState
36 import com.android.credentialmanager.ui.components.BottomSpacer
37
38 /**
39 * Screen that shows single passkey credential.
40 *
41 * @param entry The passkey entry
42 * @param columnState ScalingLazyColumn configuration to be be applied to SingleAccountScreen
43 * @param modifier styling for composable
44 * @param flowEngine [FlowEngine] that updates ui state for this screen
45 */
46 @OptIn(ExperimentalHorologistApi::class)
47 @Composable
SinglePasskeyScreennull48 fun SinglePasskeyScreen(
49 entry: CredentialEntryInfo,
50 columnState: ScalingLazyColumnState,
51 flowEngine: FlowEngine,
52 ) {
53 SingleAccountScreen(
54 headerContent = {
55 SignInHeader(
56 icon = entry.icon,
57 title = stringResource(R.string.use_passkey_title),
58 )
59 },
60 accountContent = {
61 val displayName = entry.displayName
62 if (displayName == null ||
63 entry.displayName.equals(entry.userName, ignoreCase = true)) {
64 AccountRow(
65 primaryText = entry.userName,
66 )
67 } else {
68 AccountRow(
69 primaryText = displayName,
70 secondaryText = entry.userName,
71 )
72 }
73 },
74 columnState = columnState,
75 ) {
76 item {
77 val selectEntry = flowEngine.getEntrySelector()
78 Column {
79 ContinueChip { selectEntry(entry, false) }
80 CredentialsScreenChipSpacer()
81 SignInOptionsChip{ flowEngine.openSecondaryScreen() }
82 CredentialsScreenChipSpacer()
83 DismissChip { flowEngine.cancel() }
84 BottomSpacer()
85 }
86 }
87 }
88 }
89