@@ -55,22 +55,6 @@ class MainActivity : AppCompatActivity() {
55
55
// Start building your app here!
56
56
@Composable
57
57
fun MyApp () {
58
- Surface (
59
- color = MaterialTheme .colors.background,
60
- ) {
61
- Card (
62
- elevation = 4 .dp,
63
- modifier = Modifier
64
- .padding(32 .dp)
65
- .fillMaxWidth(),
66
- ) {
67
- CountDownUI ()
68
- }
69
- }
70
- }
71
-
72
- @Composable
73
- fun CountDownUI () {
74
58
var progress by remember { mutableStateOf(1f ) }
75
59
var timer: Long by remember { mutableStateOf(10_000 ) }
76
60
var tempTimer by remember { mutableStateOf(timer) }
@@ -94,7 +78,6 @@ fun CountDownUI() {
94
78
}
95
79
)
96
80
var changeClockCountDown by remember { mutableStateOf(false ) }
97
-
98
81
var counterCancel by remember { mutableStateOf(false ) }
99
82
var counterPause by remember { mutableStateOf(false ) }
100
83
var counterStarted by remember { mutableStateOf(false ) }
@@ -122,119 +105,130 @@ fun CountDownUI() {
122
105
}
123
106
}
124
107
125
-
126
- Column (
127
- horizontalAlignment = Alignment .CenterHorizontally ,
128
- modifier = Modifier
129
- .fillMaxWidth()
130
- .padding(16 .dp)
108
+ Surface (
109
+ color = animatedColor,
110
+ modifier = Modifier .fillMaxHeight()
131
111
) {
132
- Box (
112
+ Card (
113
+ elevation = 4 .dp,
133
114
modifier = Modifier
134
- .wrapContentHeight()
135
- .padding(bottom = 16 .dp)
136
-
115
+ .padding(32 .dp)
116
+ .fillMaxWidth().wrapContentHeight()
137
117
) {
138
- CircularProgressIndicator (
139
- progress = 1f ,
140
- strokeWidth = 2 .dp,
141
- color = teal200,
118
+ Column (
119
+ horizontalAlignment = Alignment .CenterHorizontally ,
142
120
modifier = Modifier
143
- .height(300 .dp)
144
- .width(300 .dp)
145
- )
146
- CircularProgressIndicator (
147
- progress = progress,
148
- strokeWidth = 2 .dp,
149
- color = animatedColor,
150
- modifier = Modifier .width(300 .dp)
151
- )
152
- Row (
153
- modifier = Modifier
154
- .height(300 .dp)
155
- .width(300 .dp),
156
- horizontalArrangement = Arrangement .Center ,
157
- verticalAlignment = Alignment .CenterVertically
121
+ .fillMaxWidth()
122
+ .padding(16 .dp)
158
123
) {
159
- if (! changeClockCountDown)
160
- Text (
161
- text = time,
162
- style = typography.h3,
124
+ Box (
125
+ modifier = Modifier
126
+ .wrapContentHeight()
127
+ .padding(bottom = 16 .dp)
128
+
129
+ ) {
130
+ CircularProgressIndicator (
131
+ progress = 1f ,
132
+ strokeWidth = 2 .dp,
133
+ color = teal200,
134
+ modifier = Modifier
135
+ .height(300 .dp)
136
+ .width(300 .dp)
137
+ )
138
+ CircularProgressIndicator (
139
+ progress = progress,
140
+ strokeWidth = 2 .dp,
163
141
color = animatedColor,
164
- modifier = Modifier .clickable(onClick = {
165
- changeClockCountDown = true
166
- if (counterPause)
167
- countDownTimer.onFinish()
168
- else {
169
- counterPause = true
170
- counterCancel = true
171
- }
172
- })
142
+ modifier = Modifier .width(300 .dp)
173
143
)
174
- else {
175
- Column {
176
- Box {
177
- TextField (
178
- value = (timer / 1000 ).toString(),
179
- onValueChange = {
180
- timer = if (it != " " )
181
- it.toLong() * 1000
182
- else
183
- 0
184
- },
185
- textStyle = typography.h3,
186
- keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .NumberPassword ),
187
- singleLine = true ,
144
+ Row (
145
+ modifier = Modifier
146
+ .height(300 .dp)
147
+ .width(300 .dp),
148
+ horizontalArrangement = Arrangement .Center ,
149
+ verticalAlignment = Alignment .CenterVertically
150
+ ) {
151
+ if (! changeClockCountDown)
152
+ Text (
153
+ text = time,
154
+ style = typography.h3,
155
+ color = animatedColor,
156
+ modifier = Modifier .clickable(onClick = {
157
+ changeClockCountDown = true
158
+ if (counterPause)
159
+ countDownTimer.onFinish()
160
+ else {
161
+ counterPause = true
162
+ counterCancel = true
163
+ }
164
+ })
188
165
)
189
- Text (text = " seconds" )
190
- }
191
- Button (onClick = {
192
- changeClockCountDown = false
193
- tempTimer = timer
194
- countDownTimer.start()
195
- }) {
196
- Text (text = " Set" )
197
- }
198
- }
166
+ else {
167
+ Column {
168
+ Box {
169
+ TextField (
170
+ value = (timer / 1000 ).toString(),
171
+ onValueChange = {
172
+ timer = if (it != " " )
173
+ it.toLong() * 1000
174
+ else
175
+ 0
176
+ },
177
+ textStyle = typography.h3,
178
+ keyboardOptions = KeyboardOptions (keyboardType = KeyboardType .NumberPassword ),
179
+ singleLine = true ,
180
+ )
181
+ Text (text = " seconds" )
182
+ }
183
+ Button (onClick = {
184
+ changeClockCountDown = false
185
+ tempTimer = timer
186
+ countDownTimer.start()
187
+ }) {
188
+ Text (text = " Set" )
189
+ }
190
+ }
199
191
200
192
201
- }
193
+ }
202
194
203
- }
204
- }
195
+ }
196
+ }
205
197
206
- Row {
198
+ Row {
207
199
208
200
209
- if (! counterStarted) {
210
- Button (onClick = {
211
- progress = 0.0f
212
- countDownTimer.start()
213
- counterCancel = false
214
- counterStarted = true
215
- counterPause = false
201
+ if (! counterStarted) {
202
+ Button (onClick = {
203
+ progress = 0.0f
204
+ countDownTimer.start()
205
+ counterCancel = false
206
+ counterStarted = true
207
+ counterPause = false
216
208
217
- }) {
218
- Icon (imageVector = Icons .Filled .PlayArrow , contentDescription = " " )
219
- }
220
- } else {
221
- Button (onClick = {
222
- counterStarted = false
223
- counterPause = true
224
- }) {
225
- Icon (imageVector = Icons .Filled .Pause , contentDescription = " " )
226
- }
227
- }
228
- Spacer (modifier = Modifier .padding(8 .dp))
229
- Button (onClick = {
230
- if (counterPause)
231
- countDownTimer.onFinish()
232
- else {
233
- counterPause = true
234
- counterCancel = true
209
+ }) {
210
+ Icon (imageVector = Icons .Filled .PlayArrow , contentDescription = " " )
211
+ }
212
+ } else {
213
+ Button (onClick = {
214
+ counterStarted = false
215
+ counterPause = true
216
+ }) {
217
+ Icon (imageVector = Icons .Filled .Pause , contentDescription = " " )
218
+ }
219
+ }
220
+ Spacer (modifier = Modifier .padding(8 .dp))
221
+ Button (onClick = {
222
+ if (counterPause)
223
+ countDownTimer.onFinish()
224
+ else {
225
+ counterPause = true
226
+ counterCancel = true
227
+ }
228
+ }) {
229
+ Icon (imageVector = Icons .Filled .Stop , contentDescription = " " )
230
+ }
235
231
}
236
- }) {
237
- Icon (imageVector = Icons .Filled .Stop , contentDescription = " " )
238
232
}
239
233
}
240
234
}
0 commit comments