|
9 | 9 |
|
10 | 10 | package it.unibo.alchemist.boundary.composeui |
11 | 11 |
|
12 | | -import androidx.compose.animation.AnimatedVisibility |
| 12 | +import androidx.compose.foundation.layout.Arrangement |
13 | 13 | import androidx.compose.foundation.layout.Column |
| 14 | +import androidx.compose.foundation.layout.Row |
14 | 15 | import androidx.compose.foundation.layout.fillMaxWidth |
15 | 16 | import androidx.compose.material.Button |
16 | 17 | import androidx.compose.material.MaterialTheme |
17 | 18 | import androidx.compose.material.Text |
18 | 19 | import androidx.compose.runtime.Composable |
19 | 20 | import androidx.compose.runtime.getValue |
20 | | -import androidx.compose.runtime.mutableStateOf |
21 | | -import androidx.compose.runtime.remember |
22 | | -import androidx.compose.runtime.setValue |
23 | 21 | import androidx.compose.ui.Alignment |
24 | 22 | import androidx.compose.ui.Modifier |
| 23 | +import androidx.compose.ui.unit.dp |
| 24 | +import androidx.lifecycle.compose.collectAsStateWithLifecycle |
| 25 | +import androidx.lifecycle.viewmodel.compose.viewModel |
| 26 | +import it.unibo.alchemist.boundary.composeui.viewmodels.SimulationStatusViewModel |
25 | 27 |
|
26 | 28 | /** |
27 | 29 | * Application entry point, this will be rendered the same in all the platforms. |
28 | 30 | */ |
29 | 31 | @Composable |
30 | 32 | fun app() { |
31 | 33 | MaterialTheme { |
32 | | - var showContent by remember { mutableStateOf(false) } |
33 | 34 | Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { |
34 | | - Button(onClick = { showContent = !showContent }) { |
35 | | - Text("Click me!") |
36 | | - } |
37 | | - AnimatedVisibility(showContent) { |
38 | | - val greeting = remember { getPlatform() } |
39 | | - Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { |
40 | | - Text("Compose: $greeting") |
41 | | - } |
42 | | - } |
| 35 | + simulationStatus() |
| 36 | + } |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +@Composable |
| 41 | +fun simulationStatus(viewModel: SimulationStatusViewModel = viewModel { SimulationStatusViewModel() }) { |
| 42 | + val uiState by viewModel.uiState.collectAsStateWithLifecycle() |
| 43 | + Text("Simulation status: ${uiState.status}") |
| 44 | + Text("Simulation time: ${uiState.time}") |
| 45 | + Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) { |
| 46 | + Button(onClick = { viewModel.pause() }) { |
| 47 | + Text("Pause") |
| 48 | + } |
| 49 | + Button(onClick = { viewModel.play() }) { |
| 50 | + Text("Play") |
43 | 51 | } |
44 | 52 | } |
45 | 53 | } |
0 commit comments