Работает обновление
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.database.DAO.BicycleDao
|
||||||
import com.example.labwork.models.Bicycle
|
import com.example.labwork.models.Bicycle
|
||||||
import com.example.labwork.ui.theme.LightBluePolitech
|
import com.example.labwork.ui.theme.LightBluePolitech
|
||||||
|
import com.example.labwork.viewmodel.BicycleViewModel
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@Composable
|
@Composable
|
||||||
@ -135,7 +136,11 @@ fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) {
|
fun FormUpdateProduct(
|
||||||
|
item: Bicycle,
|
||||||
|
bicycleViewModel: BicycleViewModel,
|
||||||
|
navHostController: NavHostController
|
||||||
|
) {
|
||||||
val isFormVisible = remember { mutableStateOf(false) }
|
val isFormVisible = remember { mutableStateOf(false) }
|
||||||
var brand by remember { mutableStateOf(item.brand) }
|
var brand by remember { mutableStateOf(item.brand) }
|
||||||
var model by remember { mutableStateOf(item.model) }
|
var model by remember { mutableStateOf(item.model) }
|
||||||
@ -203,14 +208,8 @@ fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: N
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(9.dp),
|
.padding(9.dp),
|
||||||
onClick = {
|
onClick = {
|
||||||
GlobalScope.launch {
|
val newBicycle = Bicycle(item.id, brand, model, color, null)
|
||||||
val newBicycle = bicycleDao.getBicycleById(item.id)
|
bicycleViewModel.updateBicycle(newBicycle)
|
||||||
newBicycle.model = model
|
|
||||||
newBicycle.color = color
|
|
||||||
newBicycle.brand = brand
|
|
||||||
|
|
||||||
bicycleDao.updateBicycle(newBicycle)
|
|
||||||
}
|
|
||||||
isFormVisible.value = false
|
isFormVisible.value = false
|
||||||
navHostController.navigate("ListProduct")
|
navHostController.navigate("ListProduct")
|
||||||
},
|
},
|
||||||
|
@ -89,7 +89,7 @@ fun ListProduct(item: Bicycle, bicycleViewModel : BicycleViewModel, navHostContr
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Column {
|
Column {
|
||||||
//FormUpdateProduct(item,bicycleDao, navHostController)
|
FormUpdateProduct(item, bicycleViewModel, navHostController)
|
||||||
Button(
|
Button(
|
||||||
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
Loading…
x
Reference in New Issue
Block a user