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.password
20 
21 import androidx.compose.foundation.layout.Column
22 import androidx.compose.foundation.layout.padding
23 import androidx.compose.runtime.Composable
24 import androidx.compose.ui.Modifier
25 import androidx.compose.ui.res.stringResource
26 import androidx.compose.ui.unit.dp
27 import com.android.credentialmanager.FlowEngine
28 import com.android.credentialmanager.R
29 import com.android.credentialmanager.ui.components.PasswordRow
30 import com.android.credentialmanager.ui.components.ContinueChip
31 import com.android.credentialmanager.ui.components.DismissChip
32 import com.android.credentialmanager.ui.components.SignInHeader
33 import com.android.credentialmanager.ui.components.SignInOptionsChip
34 import com.android.credentialmanager.ui.screens.single.SingleAccountScreen
35 import com.android.credentialmanager.model.get.CredentialEntryInfo
36 import com.android.credentialmanager.ui.components.BottomSpacer
37 import com.android.credentialmanager.ui.components.CredentialsScreenChipSpacer
38 import com.google.android.horologist.annotations.ExperimentalHorologistApi
39 import com.google.android.horologist.compose.layout.ScalingLazyColumnState
40 
41 /**
42  * Screen that shows password credential.
43  *
44  * @param entry The password entry.
45  * @param columnState ScalingLazyColumn configuration to be be applied to SingleAccountScreen
46  * @param modifier styling for composable
47  * @param flowEngine [FlowEngine] that updates ui state for this screen
48  */
49 @OptIn(ExperimentalHorologistApi::class)
50 @Composable
SinglePasswordScreennull51 fun SinglePasswordScreen(
52     entry: CredentialEntryInfo,
53     columnState: ScalingLazyColumnState,
54     flowEngine: FlowEngine,
55 ) {
56     val selectEntry = flowEngine.getEntrySelector()
57     SingleAccountScreen(
58         headerContent = {
59             SignInHeader(
60                 icon = entry.icon,
61                 title = stringResource(R.string.use_password_title),
62             )
63         },
64         accountContent = {
65             PasswordRow(
66                 email = entry.userName,
67             )
68         },
69         columnState = columnState,
70         modifier = Modifier.padding(horizontal = 10.dp)
71     ) {
72         item {
73             Column {
74                 ContinueChip { selectEntry(entry, false) }
75                 CredentialsScreenChipSpacer()
76                 SignInOptionsChip{ flowEngine.openSecondaryScreen() }
77                 CredentialsScreenChipSpacer()
78                 DismissChip { flowEngine.cancel() }
79                 BottomSpacer()
80             }
81         }
82     }
83 }
84 
85 
86