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.focus.searchwidget
7 import androidx.compose.foundation.Image
8 import androidx.compose.foundation.background
9 import androidx.compose.foundation.layout.Arrangement
10 import androidx.compose.foundation.layout.Column
11 import androidx.compose.foundation.layout.fillMaxWidth
12 import androidx.compose.foundation.layout.padding
13 import androidx.compose.foundation.layout.size
14 import androidx.compose.foundation.layout.wrapContentHeight
15 import androidx.compose.foundation.layout.wrapContentSize
16 import androidx.compose.foundation.shape.CircleShape
17 import androidx.compose.foundation.shape.RoundedCornerShape
18 import androidx.compose.material.Button
19 import androidx.compose.material.ButtonDefaults
20 import androidx.compose.material.Icon
21 import androidx.compose.material.IconButton
22 import androidx.compose.material.Text
23 import androidx.compose.runtime.Composable
24 import androidx.compose.runtime.MutableState
25 import androidx.compose.runtime.mutableStateOf
26 import androidx.compose.runtime.remember
27 import androidx.compose.ui.Alignment
28 import androidx.compose.ui.Modifier
29 import androidx.compose.ui.draw.clip
30 import androidx.compose.ui.platform.LocalContext
31 import androidx.compose.ui.res.colorResource
32 import androidx.compose.ui.res.painterResource
33 import androidx.compose.ui.res.stringResource
34 import androidx.compose.ui.text.AnnotatedString
35 import androidx.compose.ui.text.style.TextAlign
36 import androidx.compose.ui.tooling.preview.Preview
37 import androidx.compose.ui.unit.dp
38 import androidx.compose.ui.window.Dialog
39 import androidx.compose.ui.window.DialogProperties
40 import androidx.constraintlayout.compose.ConstraintLayout
41 import mozilla.components.ui.colors.PhotonColors
42 import org.mozilla.focus.R
43 import org.mozilla.focus.ui.theme.FocusTheme
44 import org.mozilla.focus.ui.theme.focusColors
45 import org.mozilla.focus.ui.theme.focusTypography
49 private fun PromoteSearchWidgetDialogComposePreview() {
51 PromoteSearchWidgetDialogCompose({}, {})
55 @Suppress("LongMethod")
57 fun PromoteSearchWidgetDialogCompose(
58 onAddSearchWidgetButtonClick: () -> Unit,
59 onDismiss: () -> Unit,
61 val openDialog = remember { mutableStateOf(true) }
62 if (openDialog.value) {
67 DialogProperties(dismissOnBackPress = true, dismissOnClickOutside = false),
71 .clip(RoundedCornerShape(20.dp)),
77 colorResource(id = R.color.promote_search_widget_dialog_background),
80 val (closeButton, content) = createRefs()
85 .padding(top = 8.dp, end = 16.dp)
86 .constrainAs(closeButton) {
87 top.linkTo(parent.top)
88 start.linkTo(parent.start)
89 end.linkTo(parent.end)
91 verticalArrangement = Arrangement.Center,
92 horizontalAlignment = Alignment.End,
94 CloseButton(openDialog, onDismiss)
97 modifier = Modifier.constrainAs(content) {
98 top.linkTo(closeButton.bottom)
99 start.linkTo(parent.start)
100 end.linkTo(parent.end)
102 verticalArrangement = Arrangement.Center,
103 horizontalAlignment = Alignment.CenterHorizontally,
106 text = stringResource(
107 id = R.string.promote_search_widget_dialog_title,
111 color = focusColors.dialogTextColor,
112 textAlign = TextAlign.Center,
113 style = focusTypography.dialogTitle,
116 text = stringResource(
117 id = R.string.promote_search_widget_dialog_subtitle,
118 LocalContext.current.getString(R.string.onboarding_short_app_name),
121 .padding(top = 16.dp, start = 16.dp, end = 16.dp),
122 color = focusColors.dialogTextColor,
123 textAlign = TextAlign.Center,
124 style = focusTypography.dialogContent,
127 painter = painterResource(R.drawable.focus_search_widget_promote_dialog),
128 contentDescription = LocalContext.current.getString(
129 R.string.promote_search_widget_dialog_picture_content_description,
133 .padding(start = 10.dp, end = 10.dp)
135 colorResource(id = R.color.promote_search_widget_dialog_background),
138 ComponentAddWidgetButton({ onAddSearchWidgetButtonClick() }, { onDismiss() }, openDialog)
147 private fun ComponentAddWidgetButton(
148 onAddSearchWidgetButtonClick: () -> Unit,
149 onDismiss: () -> Unit,
150 openState: MutableState<Boolean>,
154 openState.value = false
155 onAddSearchWidgetButtonClick()
161 shape = RoundedCornerShape(8.dp),
162 colors = ButtonDefaults.textButtonColors(
163 backgroundColor = colorResource(R.color.promote_search_widget_dialog_add_widget_button_background),
167 text = AnnotatedString(
168 LocalContext.current.resources.getString(
169 R.string.promote_search_widget_button_text,
172 color = PhotonColors.White,
178 private fun CloseButton(
179 openState: MutableState<Boolean>,
180 onDismiss: () -> Unit,
185 openState.value = false
189 colorResource(id = R.color.promote_search_widget_dialog_close_button_background),
196 painter = painterResource(R.drawable.mozac_ic_cross_24),
197 contentDescription = stringResource(id = R.string.promote_search_widget_dialog_content_description),
198 tint = focusColors.closeIcon,