Работает обновление
This commit is contained in:
parent
25cdd9b083
commit
36c001ca2e
@ -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")
|
||||
},
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user