|
|
|
@ -35,6 +35,7 @@ import androidx.compose.ui.tooling.preview.Preview
@@ -35,6 +35,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle |
|
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel |
|
|
|
|
import androidx.navigation.NavHostController |
|
|
|
|
import androidx.navigation.NavType |
|
|
|
|
import androidx.navigation.compose.NavHost |
|
|
|
|
import androidx.navigation.compose.composable |
|
|
|
@ -81,13 +82,13 @@ fun DemoApp(modifier: Modifier = Modifier) {
@@ -81,13 +82,13 @@ fun DemoApp(modifier: Modifier = Modifier) {
|
|
|
|
|
modifier = Modifier.padding(innerPadding) |
|
|
|
|
) { |
|
|
|
|
composable(DemoRoutes.List.route){ |
|
|
|
|
ListScreen( onEditClick = { |
|
|
|
|
ListScreen(onEditClick = { |
|
|
|
|
navController.navigate(DemoRoutes.Edit.route.replace("{taskId}", "$it")) |
|
|
|
|
}){ |
|
|
|
|
navController.navigate(DemoRoutes.Detail.route.replace("{taskId}", "$it")) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
composable(DemoRoutes.Add.route) { AddScreen() } |
|
|
|
|
composable(DemoRoutes.Add.route) { AddScreen(navController = navController) } |
|
|
|
|
composable( |
|
|
|
|
route = DemoRoutes.Detail.route, |
|
|
|
|
arguments = listOf(navArgument("taskId") { |
|
|
|
@ -115,7 +116,7 @@ fun ListScreen(
@@ -115,7 +116,7 @@ fun ListScreen(
|
|
|
|
|
modifier: Modifier = Modifier, |
|
|
|
|
demoViewModel: DemoViewModel = viewModel(factory = AppViewModelProvider.Factory), |
|
|
|
|
onEditClick: (Int) -> Unit, |
|
|
|
|
onCardClick: (Int) -> Unit |
|
|
|
|
onCardClick: (Int) -> Unit, |
|
|
|
|
) { |
|
|
|
|
Box(Modifier.fillMaxSize()) { |
|
|
|
|
val state by demoViewModel.taskUiState.collectAsStateWithLifecycle(); |
|
|
|
@ -160,6 +161,7 @@ fun AddScreen(
@@ -160,6 +161,7 @@ fun AddScreen(
|
|
|
|
|
//task: Task, |
|
|
|
|
modifier: Modifier = Modifier, |
|
|
|
|
demoViewModel: DemoViewModel = viewModel(factory = AppViewModelProvider.Factory), |
|
|
|
|
navController: NavHostController |
|
|
|
|
) { |
|
|
|
|
var taskText by remember { mutableStateOf("") } |
|
|
|
|
var descText by remember { mutableStateOf("") } |
|
|
|
@ -195,7 +197,8 @@ fun AddScreen(
@@ -195,7 +197,8 @@ fun AddScreen(
|
|
|
|
|
FilledTonalButton( |
|
|
|
|
modifier = Modifier.fillMaxWidth(), |
|
|
|
|
onClick = { |
|
|
|
|
demoViewModel.onAddButtonClicked(Task{0, "", ""}) |
|
|
|
|
demoViewModel.onAddButtonClicked(Task(0, taskText, descText)) |
|
|
|
|
navController.navigate(DemoRoutes.List.route) |
|
|
|
|
}) { |
|
|
|
|
Text("Save") |
|
|
|
|
} |
|
|
|
|