1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 package org.mozilla.fenix.components.menu.compose.header
7 import androidx.compose.foundation.background
8 import androidx.compose.foundation.clickable
9 import androidx.compose.foundation.layout.Arrangement
10 import androidx.compose.foundation.layout.Column
11 import androidx.compose.foundation.layout.Row
12 import androidx.compose.foundation.layout.Spacer
13 import androidx.compose.foundation.layout.defaultMinSize
14 import androidx.compose.foundation.layout.padding
15 import androidx.compose.foundation.layout.width
16 import androidx.compose.foundation.shape.RoundedCornerShape
17 import androidx.compose.material.Icon
18 import androidx.compose.material.Text
19 import androidx.compose.runtime.Composable
20 import androidx.compose.ui.Alignment
21 import androidx.compose.ui.Modifier
22 import androidx.compose.ui.draw.clip
23 import androidx.compose.ui.res.painterResource
24 import androidx.compose.ui.res.stringResource
25 import androidx.compose.ui.tooling.preview.Preview
26 import androidx.compose.ui.unit.dp
27 import mozilla.components.service.fxa.store.Account
28 import org.mozilla.fenix.R
29 import org.mozilla.fenix.components.accounts.AccountState
30 import org.mozilla.fenix.components.accounts.AccountState.AUTHENTICATED
31 import org.mozilla.fenix.components.accounts.AccountState.NEEDS_REAUTHENTICATION
32 import org.mozilla.fenix.components.accounts.AccountState.NO_ACCOUNT
33 import org.mozilla.fenix.compose.annotation.LightDarkPreview
34 import org.mozilla.fenix.theme.FirefoxTheme
35 import org.mozilla.fenix.theme.Theme
37 private val BUTTON_HEIGHT = 56.dp
38 private val BUTTON_SHAPE = RoundedCornerShape(size = 8.dp)
41 internal fun MozillaAccountMenuButton(
43 accountState: AccountState,
44 onSignInButtonClick: () -> Unit,
45 modifier: Modifier = Modifier,
50 color = FirefoxTheme.colors.layer3,
53 .clip(shape = BUTTON_SHAPE)
54 .clickable { onSignInButtonClick() }
55 .defaultMinSize(minHeight = BUTTON_HEIGHT),
56 verticalAlignment = Alignment.CenterVertically,
58 Spacer(modifier = Modifier.width(4.dp))
64 .padding(horizontal = 8.dp)
70 text = stringResource(id = R.string.browser_menu_sign_in),
71 color = FirefoxTheme.colors.textSecondary,
73 style = FirefoxTheme.typography.headline7,
77 text = stringResource(id = R.string.browser_menu_sign_in_caption),
78 color = FirefoxTheme.colors.textSecondary,
80 style = FirefoxTheme.typography.caption,
84 NEEDS_REAUTHENTICATION -> {
86 text = stringResource(id = R.string.browser_menu_sign_back_in_to_sync),
87 color = FirefoxTheme.colors.textSecondary,
89 style = FirefoxTheme.typography.headline7,
93 text = stringResource(id = R.string.browser_menu_syncing_paused_caption),
94 color = FirefoxTheme.colors.textWarning,
96 style = FirefoxTheme.typography.caption,
102 text = account?.displayName ?: account?.email
103 ?: stringResource(id = R.string.browser_menu_account_settings),
104 color = FirefoxTheme.colors.textSecondary,
106 style = FirefoxTheme.typography.headline7,
112 if (accountState == NEEDS_REAUTHENTICATION) {
114 painter = painterResource(R.drawable.mozac_ic_warning_fill_24),
115 contentDescription = null,
116 tint = FirefoxTheme.colors.iconWarning,
119 Spacer(modifier = Modifier.width(8.dp))
125 private fun AvatarIcon() {
127 painter = painterResource(id = R.drawable.mozac_ic_avatar_circle_24),
128 contentDescription = null,
131 color = FirefoxTheme.colors.layer2,
132 shape = RoundedCornerShape(size = 24.dp),
134 .padding(all = 4.dp),
135 tint = FirefoxTheme.colors.iconSecondary,
140 private fun MenuHeaderPreviewContent() {
143 .background(color = FirefoxTheme.colors.layer2)
144 .padding(all = 16.dp),
145 verticalArrangement = Arrangement.spacedBy(16.dp),
147 MozillaAccountMenuButton(
149 accountState = NO_ACCOUNT,
150 onSignInButtonClick = {},
153 MozillaAccountMenuButton(
155 accountState = NEEDS_REAUTHENTICATION,
156 onSignInButtonClick = {},
159 MozillaAccountMenuButton(
163 email = "test@example.com",
164 displayName = "test profile",
165 currentDeviceId = null,
168 accountState = AUTHENTICATED,
169 onSignInButtonClick = {},
172 MozillaAccountMenuButton(
176 email = "test@example.com",
178 currentDeviceId = null,
181 accountState = AUTHENTICATED,
182 onSignInButtonClick = {},
185 MozillaAccountMenuButton(
191 currentDeviceId = null,
194 accountState = AUTHENTICATED,
195 onSignInButtonClick = {},
202 private fun MenuHeaderPreview() {
204 MenuHeaderPreviewContent()
210 private fun MenuHeaderPrivatePreview() {
211 FirefoxTheme(theme = Theme.Private) {
212 MenuHeaderPreviewContent()