1 /*
2  * Copyright (C) 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  *      http://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 package com.android.settingslib.spa.widget.dialog
18 
19 import androidx.compose.foundation.layout.Column
20 import androidx.compose.foundation.layout.fillMaxWidth
21 import androidx.compose.foundation.layout.width
22 import androidx.compose.foundation.rememberScrollState
23 import androidx.compose.foundation.verticalScroll
24 import androidx.compose.material.icons.Icons
25 import androidx.compose.material.icons.filled.WarningAmber
26 import androidx.compose.material3.AlertDialog
27 import androidx.compose.material3.Button
28 import androidx.compose.material3.Icon
29 import androidx.compose.material3.OutlinedButton
30 import androidx.compose.material3.Text
31 import androidx.compose.runtime.Composable
32 import androidx.compose.ui.Modifier
33 import androidx.compose.ui.text.style.TextAlign
34 import androidx.compose.ui.window.DialogProperties
35 
36 @Composable
SettingsAlertDialogWithIconnull37 fun SettingsAlertDialogWithIcon(
38     onDismissRequest: () -> Unit,
39     confirmButton: AlertDialogButton?,
40     dismissButton: AlertDialogButton?,
41     title: String?,
42     icon: @Composable (() -> Unit)? = {
43         Icon(
44             Icons.Default.WarningAmber,
45             contentDescription = null
46         )
47     },
48     text: @Composable (() -> Unit)?,
49 ) {
50     AlertDialog(
51         onDismissRequest = onDismissRequest,
52         icon = icon,
53         modifier = Modifier.width(getDialogWidth()),
<lambda>null54         confirmButton = {
55             confirmButton?.let {
56                 Button(
57                     onClick = {
58                         it.onClick()
59                     },
60                 ) {
61                     Text(it.text)
62                 }
63             }
64         },
<lambda>null65         dismissButton = dismissButton?.let {
66             {
67                 OutlinedButton(
68                     onClick = {
69                         it.onClick()
70                     },
71                 ) {
72                     Text(it.text)
73                 }
74             }
75         },
<lambda>null76         title = title?.let {
77             {
78                 Text(
79                     it,
80                     modifier = Modifier.fillMaxWidth(),
81                     textAlign = TextAlign.Center
82                 )
83             }
84         },
<lambda>null85         text = text?.let {
86             {
87                 Column(Modifier.verticalScroll(rememberScrollState())) {
88                     text()
89                 }
90             }
91         },
92         properties = DialogProperties(usePlatformDefaultWidth = false),
93     )
94 }