From 96d09edf51c1dc231e9c7a5bb023cf4660ce6524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC?= Date: Thu, 23 Nov 2023 15:31:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/labwork/button_navigation/Screens.kt | 2 +- .../com/example/labwork/pages/product/FormProduct.kt | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/example/labwork/button_navigation/Screens.kt b/app/src/main/java/com/example/labwork/button_navigation/Screens.kt index 8e1c7f3..6c20ba9 100644 --- a/app/src/main/java/com/example/labwork/button_navigation/Screens.kt +++ b/app/src/main/java/com/example/labwork/button_navigation/Screens.kt @@ -50,7 +50,7 @@ fun ScreenListProduct( Column( modifier = Modifier.fillMaxHeight().padding(bottom = 65.dp) ) { - //FormNewProduct(bicycleViewModel, navHostController) + FormNewProduct(bicycleViewModel, navHostController) LazyColumn { itemsIndexed(bicycles) { index, item -> ListProduct( diff --git a/app/src/main/java/com/example/labwork/pages/product/FormProduct.kt b/app/src/main/java/com/example/labwork/pages/product/FormProduct.kt index 1dc914c..4c5fe3c 100644 --- a/app/src/main/java/com/example/labwork/pages/product/FormProduct.kt +++ b/app/src/main/java/com/example/labwork/pages/product/FormProduct.kt @@ -28,7 +28,10 @@ import com.example.labwork.viewmodel.BicycleViewModel import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @Composable -fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController) { +fun FormNewProduct( + bicycleViewModel: BicycleViewModel, + navHostController: NavHostController +) { val isFormVisible = remember { mutableStateOf(false) } var brand by remember { mutableStateOf("") } var model by remember { mutableStateOf("") } @@ -96,10 +99,8 @@ fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController) .fillMaxWidth() .padding(9.dp), onClick = { - GlobalScope.launch { - val newBicycle = Bicycle(null, brand, model, color, null) - bicycleDao.insertBicycle(newBicycle) - } + val newBicycle = Bicycle(null, brand, model, color, null) + bicycleViewModel.insertBicycle(newBicycle) isFormVisible.value = false navHostController.navigate("ListProduct") },