Чуть чуть сделал красивее, расскидал по папочкам :3

This commit is contained in:
Кашин Максим 2023-11-20 22:30:30 +04:00
parent 9c8d38f9f4
commit b622cb235b
3 changed files with 139 additions and 110 deletions

View File

@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateListOf
@ -15,7 +14,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.pages.ListInfo import com.example.labwork.pages.ListInfo
import com.example.labwork.pages.ListProduct import com.example.labwork.pages.product.ListProduct
import com.example.labwork.pages.RegisteryOrLogin import com.example.labwork.pages.RegisteryOrLogin
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext

View File

@ -0,0 +1,136 @@
package com.example.labwork.pages.product
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
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 kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@Composable
fun FormProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) {
val isFormVisible = remember { mutableStateOf(false) }
var brand by remember { mutableStateOf("") }
var model by remember { mutableStateOf("") }
var color by remember { mutableStateOf("") }
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
// Установите значение состояния открытия формы как true
isFormVisible.value = true
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Добавить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
// После кнопки "Добавить" добавьте код, который будет отображать форму при isFormVisible равном true
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 = Bicycle(null, brand, model, color, null)
bicycleDao.insertBicycle(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

@ -1,4 +1,4 @@
package com.example.labwork.pages package com.example.labwork.pages.product
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateDpAsState import androidx.compose.animation.core.animateDpAsState
@ -40,124 +40,18 @@ import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import com.example.labwork.R import com.example.labwork.R
import com.example.labwork.database.DAO.BicycleDao import com.example.labwork.database.DAO.BicycleDao
import com.example.labwork.database.DAO.UserDao
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 kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@Composable @Composable
fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) { fun ListProduct(item: Bicycle, bicycleDao: BicycleDao, navHostController: NavHostController) {
var isFullAbout by remember { mutableStateOf(false) } var isFullAbout by remember { mutableStateOf(false) }
val scale by animateFloatAsState(if (isFullAbout) 1f else 0f) val scale by animateFloatAsState(if (isFullAbout) 1f else 0f)
val textSize by animateDpAsState(if (isFullAbout) 18.dp else 24.dp) val textSize by animateDpAsState(if (isFullAbout) 18.dp else 24.dp)
val isFormVisible = remember { mutableStateOf(false) }
var brand by remember { mutableStateOf("") }
var model by remember { mutableStateOf("") }
var color by remember { mutableStateOf("") }
// Внутри вашего кода Composable обработчик нажатия кнопки "Добавить" FormProduct(item, bicycleDao, navHostController)
Button(
colors = ButtonDefaults.buttonColors(backgroundColor = LightBluePolitech),
modifier = Modifier
.fillMaxWidth()
.padding(9.dp),
onClick = {
// Установите значение состояния открытия формы как true
isFormVisible.value = true
},
shape = RoundedCornerShape(15.dp)
) {
Text(
text = "Добавить",
color = Color.White,
fontSize = 10.sp,
textAlign = TextAlign.Center
)
}
// После кнопки "Добавить" добавьте код, который будет отображать форму при isFormVisible равном true
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 = Bicycle(null, brand, model, color, null)
bicycleDao.insertBicycle(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
)
}
}
}
Card( Card(
modifier = Modifier modifier = Modifier