Абалдеть, я сделал редактирование....

This commit is contained in:
Кашин Максим 2023-11-21 01:04:47 +04:00
parent 0b8c882823
commit d9cb297f65
6 changed files with 145 additions and 41 deletions

View File

@ -22,7 +22,7 @@ interface BicycleDao {
suspend fun getAllBicycles(): List<Bicycle> suspend fun getAllBicycles(): List<Bicycle>
@Query("SELECT * FROM bicycles WHERE id = :bicycleId") @Query("SELECT * FROM bicycles WHERE id = :bicycleId")
suspend fun getBicycleById(bicycleId: Int): Bicycle suspend fun getBicycleById(bicycleId: Int?): Bicycle
@Query("SELECT * FROM bicycles WHERE userId = :userId") @Query("SELECT * FROM bicycles WHERE userId = :userId")
suspend fun getBicyclesByUserId(userId: Int): List<Bicycle> suspend fun getBicyclesByUserId(userId: Int): List<Bicycle>

View File

@ -7,8 +7,8 @@ import androidx.room.PrimaryKey
data class Bicycle( data class Bicycle(
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
val id: Int?, val id: Int?,
val brand: String, var brand: String,
val model: String, var model: String,
val color: String, var color: String,
val userId: Int? val userId: Int?
) )

View File

@ -12,3 +12,4 @@ data class User(
val email: String, val email: String,
val password: String, val password: String,
) )

View File

@ -3,6 +3,7 @@ package com.example.labwork.pages.product
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults import androidx.compose.material.ButtonDefaults
@ -132,3 +133,115 @@ fun FormNewProduct(bicycleDao: BicycleDao, navHostController: NavHostController)
} }
} }
@Composable
fun FormUpdateProduct(item:Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) {
val isFormVisible = remember { mutableStateOf(false) }
var brand by remember { mutableStateOf(item.brand) }
var model by remember { mutableStateOf(item.model) }
var color by remember { mutableStateOf(item.color) }
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.padding(start = 9.dp, bottom = 9.dp)
.size(height = 32.dp, width = 128.dp),
onClick = {
// Установите значение состояния открытия формы как true
isFormVisible.value = true
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Редактировать",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
if (isFormVisible.value) {
Column(
modifier = Modifier.fillMaxWidth()
) {
// Поле ввода для бренда
TextField(
value = brand,
onValueChange = { brand = it },
placeholder = { Text("Бренд") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
// Поле ввода для модели
TextField(
value = model,
onValueChange = { model = it },
placeholder = { Text("Модель") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
// Поле ввода для цвета
TextField(
value = color,
onValueChange = { color = it },
placeholder = { Text("Цвет") },
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = TextFieldDefaults.textFieldColors(backgroundColor = Color.White)
)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.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)
}
isFormVisible.value = false
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Принять",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
isFormVisible.value = false
navHostController.navigate("ListProduct")
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Отменить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
}
}
}

View File

@ -86,35 +86,13 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
) )
} }
Row { Column {
FormUpdateProduct(item,bicycleDao, navHostController)
Button( Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech), colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier modifier = Modifier
.padding(start = 9.dp, bottom = 9.dp) .padding(start = 9.dp, bottom = 9.dp)
.size(height = 32.dp, width = 40.dp), .size(height = 32.dp, width = 128.dp),
onClick = {
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "+",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center,
)
}
Text(
text = "1000",
color = Color.Black,
fontSize = 14.sp,
textAlign = TextAlign.Center,
modifier = Modifier.padding(start = 8.dp, top = 4.dp)
)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.padding(start = 9.dp, bottom = 9.dp)
.size(height = 32.dp, width = 40.dp),
onClick = { onClick = {
// СУПЕР ЖОСКИЙ КОСТЫЛЬ ЭТО ВООБЩЕ ТРЕШ // СУПЕР ЖОСКИЙ КОСТЫЛЬ ЭТО ВООБЩЕ ТРЕШ
GlobalScope.launch { GlobalScope.launch {
@ -125,7 +103,7 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
shape = RoundedCornerShape(15.dp) shape = RoundedCornerShape(15.dp)
) { ) {
Text( Text(
text = "-", text = "Удалить",
color = Color.White, color = Color.White,
fontSize = 10.sp, fontSize = 10.sp,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
@ -144,12 +122,14 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
.fillMaxWidth() .fillMaxWidth()
.padding(top = 8.dp) .padding(top = 8.dp)
) )
AnimatedVisibility( AnimatedVisibility(
visible = isFullAbout, visible = isFullAbout,
enter = fadeIn() + expandIn(), enter = fadeIn() + expandIn(),
exit = fadeOut() + shrinkOut(), exit = fadeOut() + shrinkOut(),
modifier = Modifier.scale(scale) modifier = Modifier.scale(scale)
) { ) {
Column {
Text( Text(
color = Color.Black, color = Color.Black,
text = item.brand, text = item.brand,
@ -158,7 +138,15 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(bottom = 8.dp) )
Text(
color = Color.Black,
text = item.color,
maxLines = 10,
fontSize = 14.sp,
textAlign = TextAlign.Center,
modifier = Modifier
.fillMaxWidth()
) )
} }
} }
@ -166,3 +154,4 @@ fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHos
} }
} }
} }
}

View File

@ -120,7 +120,8 @@ fun LoginPage(navController: NavController, userDao: UserDao, navHostController:
userPassword = userDao.getPasswordByEmail(email) userPassword = userDao.getPasswordByEmail(email)
} }
if(userPassword == password) { if(userPassword == password) {
navHostController.navigate("ListProduct") acceptLogin = true
navHostController.navigate("Profile")
} }
}, },
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech, ), colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech, ),