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 450d2b3..1dc914c 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 @@ -24,6 +24,7 @@ import androidx.navigation.NavHostController import com.example.labwork.database.DAO.BicycleDao import com.example.labwork.models.Bicycle import com.example.labwork.ui.theme.LightBluePolitech +import com.example.labwork.viewmodel.BicycleViewModel import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @Composable @@ -135,7 +136,11 @@ fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController) } @Composable -fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) { +fun FormUpdateProduct( + item: Bicycle, + bicycleViewModel: BicycleViewModel, + navHostController: NavHostController +) { val isFormVisible = remember { mutableStateOf(false) } var brand by remember { mutableStateOf(item.brand) } var model by remember { mutableStateOf(item.model) } @@ -203,14 +208,8 @@ fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: N .fillMaxWidth() .padding(9.dp), onClick = { - GlobalScope.launch { - val newBicycle = bicycleDao.getBicycleById(item.id) - newBicycle.model = model - newBicycle.color = color - newBicycle.brand = brand - - bicycleDao.updateBicycle(newBicycle) - } + val newBicycle = Bicycle(item.id, brand, model, color, null) + bicycleViewModel.updateBicycle(newBicycle) isFormVisible.value = false navHostController.navigate("ListProduct") }, @@ -244,4 +243,4 @@ fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: N } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/labwork/pages/product/ListProduct.kt b/app/src/main/java/com/example/labwork/pages/product/ListProduct.kt index 58d6172..dcefb6d 100644 --- a/app/src/main/java/com/example/labwork/pages/product/ListProduct.kt +++ b/app/src/main/java/com/example/labwork/pages/product/ListProduct.kt @@ -89,7 +89,7 @@ fun ListProduct(item: Bicycle, bicycleViewModel : BicycleViewModel, navHostContr ) } Column { - //FormUpdateProduct(item,bicycleDao, navHostController) + FormUpdateProduct(item, bicycleViewModel, navHostController) Button( colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech), modifier = Modifier