|
17 | 17 |
|
18 | 18 | package org.nsh07.pomodoro.ui.timerScreen |
19 | 19 |
|
| 20 | +import androidx.compose.foundation.background |
20 | 21 | import androidx.compose.foundation.clickable |
| 22 | +import androidx.compose.foundation.layout.Box |
21 | 23 | import androidx.compose.foundation.layout.Column |
22 | 24 | import androidx.compose.foundation.layout.Spacer |
| 25 | +import androidx.compose.foundation.layout.fillMaxSize |
23 | 26 | import androidx.compose.foundation.layout.height |
24 | 27 | import androidx.compose.foundation.layout.padding |
25 | | -import androidx.compose.foundation.layout.wrapContentHeight |
26 | | -import androidx.compose.foundation.layout.wrapContentWidth |
27 | | -import androidx.compose.material3.AlertDialogDefaults |
28 | | -import androidx.compose.material3.BasicAlertDialog |
| 28 | +import androidx.compose.foundation.layout.size |
| 29 | +import androidx.compose.material3.Button |
29 | 30 | import androidx.compose.material3.ExperimentalMaterial3Api |
30 | 31 | import androidx.compose.material3.Icon |
31 | | -import androidx.compose.material3.MaterialTheme |
| 32 | +import androidx.compose.material3.LocalContentColor |
| 33 | +import androidx.compose.material3.MaterialTheme.colorScheme |
32 | 34 | import androidx.compose.material3.MaterialTheme.typography |
33 | | -import androidx.compose.material3.Surface |
34 | 35 | import androidx.compose.material3.Text |
35 | | -import androidx.compose.material3.TextButton |
36 | 36 | import androidx.compose.runtime.Composable |
| 37 | +import androidx.compose.runtime.CompositionLocalProvider |
37 | 38 | import androidx.compose.ui.Alignment |
38 | 39 | import androidx.compose.ui.Modifier |
39 | 40 | import androidx.compose.ui.res.painterResource |
40 | 41 | import androidx.compose.ui.res.stringResource |
| 42 | +import androidx.compose.ui.text.style.TextAlign |
| 43 | +import androidx.compose.ui.tooling.preview.Preview |
41 | 44 | import androidx.compose.ui.unit.dp |
| 45 | +import androidx.compose.ui.window.Dialog |
| 46 | +import androidx.compose.ui.window.DialogProperties |
42 | 47 | import org.nsh07.pomodoro.R |
| 48 | +import org.nsh07.pomodoro.ui.theme.TomatoTheme |
43 | 49 |
|
44 | 50 | @OptIn(ExperimentalMaterial3Api::class) |
45 | 51 | @Composable |
46 | 52 | fun AlarmDialog( |
47 | 53 | modifier: Modifier = Modifier, |
48 | 54 | stopAlarm: () -> Unit |
49 | 55 | ) { |
50 | | - BasicAlertDialog( |
| 56 | + Dialog( |
51 | 57 | onDismissRequest = stopAlarm, |
52 | | - modifier = modifier |
| 58 | + properties = DialogProperties( |
| 59 | + usePlatformDefaultWidth = false, |
| 60 | + decorFitsSystemWindows = false |
| 61 | + ) |
53 | 62 | ) { |
54 | | - Surface( |
55 | | - modifier = Modifier |
56 | | - .wrapContentWidth() |
57 | | - .wrapContentHeight() |
58 | | - .clickable(onClick = stopAlarm), |
59 | | - shape = MaterialTheme.shapes.extraLarge, |
60 | | - tonalElevation = AlertDialogDefaults.TonalElevation, |
| 63 | + Box( |
| 64 | + contentAlignment = Alignment.Center, |
| 65 | + modifier = modifier |
| 66 | + .fillMaxSize() |
| 67 | + .background(colorScheme.primaryContainer) |
| 68 | + .clickable(onClick = stopAlarm) |
61 | 69 | ) { |
62 | | - Column(modifier = Modifier.padding(24.dp)) { |
63 | | - Icon( |
64 | | - painter = painterResource(R.drawable.alarm), |
65 | | - contentDescription = stringResource(R.string.alarm), |
66 | | - modifier = Modifier.align(Alignment.CenterHorizontally) |
67 | | - ) |
68 | | - Spacer(Modifier.height(16.dp)) |
69 | | - Text( |
70 | | - text = stringResource(R.string.stop_alarm_question), |
71 | | - style = typography.headlineSmall, |
72 | | - modifier = Modifier.align(Alignment.CenterHorizontally) |
73 | | - ) |
74 | | - Spacer(Modifier.height(16.dp)) |
75 | | - Text( |
76 | | - text = stringResource(R.string.stop_alarm_dialog_text) |
77 | | - ) |
78 | | - Spacer(modifier = Modifier.height(24.dp)) |
79 | | - TextButton( |
80 | | - onClick = stopAlarm, |
81 | | - modifier = Modifier.align(Alignment.End), |
82 | | - ) { |
83 | | - Text(stringResource(R.string.stop_alarm)) |
| 70 | + CompositionLocalProvider(LocalContentColor provides colorScheme.onPrimaryContainer) { |
| 71 | + Column(modifier = Modifier.padding(24.dp)) { |
| 72 | + Icon( |
| 73 | + painter = painterResource(R.drawable.alarm), |
| 74 | + contentDescription = stringResource(R.string.alarm), |
| 75 | + modifier = Modifier |
| 76 | + .align(Alignment.CenterHorizontally) |
| 77 | + .size(40.dp) |
| 78 | + ) |
| 79 | + Spacer(Modifier.height(16.dp)) |
| 80 | + Text( |
| 81 | + text = stringResource(R.string.stop_alarm_question), |
| 82 | + style = typography.headlineSmall, |
| 83 | + modifier = Modifier.align(Alignment.CenterHorizontally) |
| 84 | + ) |
| 85 | + Spacer(Modifier.height(16.dp)) |
| 86 | + Text( |
| 87 | + text = stringResource(R.string.stop_alarm_dialog_text), |
| 88 | + textAlign = TextAlign.Center |
| 89 | + ) |
| 90 | + Spacer(modifier = Modifier.height(24.dp)) |
| 91 | + Button( |
| 92 | + onClick = stopAlarm, |
| 93 | + modifier = Modifier.align(Alignment.End), |
| 94 | + ) { |
| 95 | + Text(stringResource(R.string.stop_alarm)) |
| 96 | + } |
84 | 97 | } |
85 | 98 | } |
86 | 99 | } |
87 | 100 | } |
88 | 101 | } |
| 102 | + |
| 103 | +@Preview |
| 104 | +@Composable |
| 105 | +fun AlarmDialogPreview() { |
| 106 | + TomatoTheme { |
| 107 | + AlarmDialog(stopAlarm = {}) |
| 108 | + } |
| 109 | +} |
0 commit comments