Навел марафету перед четвертой лабой

This commit is contained in:
Данила Мочалов 2023-11-18 20:32:54 +04:00
parent 7872460be3
commit e839f69d19
4 changed files with 276 additions and 229 deletions

View File

@ -73,13 +73,29 @@ abstract class AppDatabase : RoomDatabase() {
// OrderProducts // OrderProducts
val orderProductDao = database.orderProductDao() val orderProductDao = database.orderProductDao()
val op1 = OrderProductModel(1, 1, 2, 200) val op1 = OrderProductModel(1, 1, 2, 200)
val op2 = OrderProductModel(2, 4, 3, 150) val op2 = OrderProductModel(1, 4, 3, 150)
val op3 = OrderProductModel(3, 3, 1, 80) val op3 = OrderProductModel(1, 3, 1, 80)
val op4 = OrderProductModel(4, 2, 1, 120) val op4 = OrderProductModel(2, 1, 2, 200)
val op5 = OrderProductModel(2, 4, 3, 150)
val op6 = OrderProductModel(2, 3, 1, 80)
val op7 = OrderProductModel(3, 1, 2, 200)
val op8 = OrderProductModel(3, 4, 3, 150)
val op9 = OrderProductModel(3, 3, 1, 80)
val op10 = OrderProductModel(4, 1, 2, 200)
val op11 = OrderProductModel(4, 4, 3, 150)
val op12 = OrderProductModel(4, 3, 1, 80)
orderProductDao.insert(op1) orderProductDao.insert(op1)
orderProductDao.insert(op2) orderProductDao.insert(op2)
orderProductDao.insert(op3) orderProductDao.insert(op3)
orderProductDao.insert(op4) orderProductDao.insert(op4)
orderProductDao.insert(op5)
orderProductDao.insert(op6)
orderProductDao.insert(op7)
orderProductDao.insert(op8)
orderProductDao.insert(op9)
orderProductDao.insert(op10)
orderProductDao.insert(op11)
orderProductDao.insert(op12)
} }
} }

View File

@ -7,5 +7,5 @@ data class OrderProductModelWithProduct(
@Embedded @Embedded
val orderProductModel: OrderProductModel, val orderProductModel: OrderProductModel,
@Relation(entity = ProductModel::class, parentColumn = "product_id", entityColumn = "id") @Relation(entity = ProductModel::class, parentColumn = "product_id", entityColumn = "id")
val productList: List<ProductModel> val product: ProductModel
) )

View File

@ -24,7 +24,9 @@ import androidx.compose.material.Icon
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -73,12 +75,12 @@ fun CartWidget(){
} }
} }
val unpaidOrders = mutableListOf<OrderWithProducts>() var unpaidOrder: OrderWithProducts? = null
val preparingOrders = mutableListOf<OrderWithProducts>() val preparingOrders = mutableListOf<OrderWithProducts>()
for(order in orders) { for(order in orders) {
if (order.order.status == OrderStatus.Неоплачено.toString()) { if (order.order.status == OrderStatus.Неоплачено.toString()) {
unpaidOrders.add(order) unpaidOrder = order
} }
if (order.order.status == OrderStatus.Готовится.toString() || order.order.status == OrderStatus.Готово.toString()) { if (order.order.status == OrderStatus.Готовится.toString() || order.order.status == OrderStatus.Готово.toString()) {
preparingOrders.add(order) preparingOrders.add(order)
@ -105,7 +107,7 @@ fun CartWidget(){
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top=55.dp) .padding(top = 55.dp)
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
) { ) {
@ -132,14 +134,8 @@ fun CartWidget(){
modifier = Modifier.padding(top = 15.dp), modifier = Modifier.padding(top = 15.dp),
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
LazyColumn( if (unpaidOrder != null) {
modifier = Modifier CartItem(order = unpaidOrder)
.width(340.dp)
.height(200.dp)
) {
items(unpaidOrders.size) {index ->
CartItem(unpaidOrders[index])
}
} }
Spacer(modifier = Modifier.height(20.dp)) Spacer(modifier = Modifier.height(20.dp))
@ -175,59 +171,62 @@ fun PaidItem(order : OrderWithProducts) {
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
modifier = Modifier.size(340.dp, 100.dp) modifier = Modifier.size(340.dp, 100.dp)
) { ) {
Column { LazyColumn {
Row( items(order.orderWithProducts.size) { index ->
horizontalArrangement = Arrangement.SpaceBetween, if (index == 0) {
modifier = Modifier Row(
.fillMaxWidth() horizontalArrangement = Arrangement.SpaceBetween,
.padding(horizontal = 20.dp) modifier = Modifier
){ .fillMaxWidth()
Text( .padding(start = 20.dp, end = 20.dp)
text = order.orderWithProducts[0].productList[0].title, ){
fontFamily = NunitoFamily, Text(
fontSize = 20.sp, text = "Статус: ",
modifier = Modifier.padding(top = 15.dp), fontFamily = NunitoFamily,
fontWeight = FontWeight.Bold fontSize = 20.sp,
) modifier = Modifier.padding(top = 15.dp),
Text( fontWeight = FontWeight.Bold,
text = "x" + order.orderWithProducts[0].orderProductModel.quantity, color = Color.Gray
fontFamily = NunitoFamily, )
fontSize = 20.sp, Text(
modifier = Modifier.padding(top = 15.dp), text = order.order.status,
fontWeight = FontWeight.Bold fontFamily = NunitoFamily,
) fontSize = 20.sp,
Text( modifier = Modifier.padding(top = 15.dp),
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.", fontWeight = FontWeight.Bold,
fontFamily = NunitoFamily, color = Color.Gray
fontSize = 20.sp, )
modifier = Modifier.padding(top = 15.dp), }
fontWeight = FontWeight.Bold }
) Row(
} horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
Row( .fillMaxWidth()
horizontalArrangement = Arrangement.SpaceBetween, .padding(horizontal = 20.dp)
modifier = Modifier ) {
.fillMaxWidth() Text(
.padding(horizontal = 20.dp) text = order.orderWithProducts[index].product.title,
){ fontFamily = NunitoFamily,
Text( fontSize = 20.sp,
text = "Статус: ", modifier = Modifier.padding(top = 15.dp),
fontFamily = NunitoFamily, fontWeight = FontWeight.Bold
fontSize = 20.sp, )
modifier = Modifier.padding(top = 15.dp), Text(
fontWeight = FontWeight.Bold, text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
color = Color.Gray fontFamily = NunitoFamily,
) fontSize = 20.sp,
Text( modifier = Modifier.padding(top = 15.dp),
text = order.order.status, fontWeight = FontWeight.Bold
fontFamily = NunitoFamily, )
fontSize = 20.sp, Text(
modifier = Modifier.padding(top = 15.dp), text = order.orderWithProducts[index].orderProductModel.totalPrice.toString() + " руб.",
fontWeight = FontWeight.Bold, fontFamily = NunitoFamily,
color = Color.Gray fontSize = 20.sp,
) modifier = Modifier.padding(top = 15.dp),
fontWeight = FontWeight.Bold
)
}
} }
} }
} }
@ -240,60 +239,64 @@ fun CartItem(order : OrderWithProducts) {
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
modifier = Modifier.size(340.dp, 100.dp) modifier = Modifier.size(340.dp, 180.dp)
) { ) {
Row( LazyColumn (
verticalAlignment = Alignment.CenterVertically, horizontalAlignment = Alignment.CenterHorizontally
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp)
) { ) {
Column( items(order.orderWithProducts.size) {index ->
modifier = Modifier.fillMaxWidth(0.5f)
) {
Row( Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween, horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth() modifier = Modifier.padding(20.dp).size(340.dp, 60.dp)
){ ) {
Text( Column(
text = order.orderWithProducts[0].productList[0].title, modifier = Modifier.fillMaxWidth(0.5f)
fontFamily = NunitoFamily, ) {
fontSize = 20.sp, Row(
fontWeight = FontWeight.Bold horizontalArrangement = Arrangement.SpaceBetween,
) modifier = Modifier.fillMaxWidth()
Text( ) {
text = "x" + order.orderWithProducts[0].orderProductModel.quantity, Text(
fontFamily = NunitoFamily, text = order.orderWithProducts[index].product.title,
fontSize = 20.sp, fontFamily = NunitoFamily,
fontWeight = FontWeight.Bold fontSize = 20.sp,
) fontWeight = FontWeight.Bold
} )
Text( Text(
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.", text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
} }
Text(
text = order.orderWithProducts[index].orderProductModel.totalPrice.toString() + " руб.",
fontFamily = NunitoFamily,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
}
Button(
colors = ButtonDefaults.buttonColors(
backgroundColor = MyLightRed
),
shape = RoundedCornerShape(size = 10.dp),
modifier = Modifier
.size(100.dp, 60.dp)
.fillMaxSize(0.5f),
onClick = { /*TODO*/ }
) {
Icon(
painter = painterResource(id = R.drawable.trash),
contentDescription = "Delete",
modifier = Modifier.size(42.dp)
)
}
Button( }
colors = ButtonDefaults.buttonColors(
backgroundColor = MyLightRed
),
shape = RoundedCornerShape(size = 10.dp),
modifier = Modifier
.size(100.dp, 60.dp)
.fillMaxSize(0.5f),
onClick = { /*TODO*/ }
) {
Icon(
painter = painterResource(id = R.drawable.trash),
contentDescription = "Delete",
modifier = Modifier.size(42.dp)
)
} }
} }
} }
Spacer(modifier = Modifier.height(20.dp))
} }

View File

@ -5,6 +5,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
@ -180,61 +182,72 @@ fun PreparingItem(order : OrderWithProducts){
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
modifier = Modifier.size(340.dp, 100.dp) modifier = Modifier.size(340.dp, 200.dp)
){ ){
Row( Column(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp)
){
Column(
modifier = Modifier.fillMaxWidth(0.5f) ) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp).size(340.dp,60.dp)
){ ){
val localDateFormat = SimpleDateFormat("HH:mm") Column(
val time = localDateFormat.format(order.order.date) modifier = Modifier.fillMaxWidth(0.5f)
Text(
text = time,
fontFamily = NunitoFamily,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
){ ){
val localDateFormat = SimpleDateFormat("HH:mm")
val time = localDateFormat.format(order.order.date)
Text( Text(
text = order.orderWithProducts[0].productList[0].title, text = time,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
}
Button(
colors = ButtonDefaults.buttonColors(
backgroundColor = MyLightYellow
),
shape = RoundedCornerShape(size = 10.dp),
modifier = Modifier
.size(170.dp, 80.dp)
.fillMaxSize(),
onClick = { /*TODO*/ }
) {
Text( Text(
text = "x" + order.orderWithProducts[0].orderProductModel.quantity, text = "Готово!",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 14.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
} }
} }
LazyColumn(
modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp)
){
items(order.orderWithProducts.size) {index ->
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
Button( ) {
colors = ButtonDefaults.buttonColors( Text(
backgroundColor = MyLightYellow text = order.orderWithProducts[index].product.title,
), fontFamily = NunitoFamily,
shape = RoundedCornerShape(size = 10.dp), fontSize = 20.sp,
modifier = Modifier fontWeight = FontWeight.Bold
.size(100.dp, 60.dp) )
.fillMaxSize(0.5f), Text(
onClick = { /*TODO*/ } text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
) { fontFamily = NunitoFamily,
Text( fontSize = 20.sp,
text = "Готово!", fontWeight = FontWeight.Bold
fontFamily = NunitoFamily, )
fontSize = 14.sp, }
fontWeight = FontWeight.Bold }
)
} }
} }
} }
@ -248,61 +261,72 @@ fun PreparedItem(order : OrderWithProducts){
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
modifier = Modifier.size(340.dp, 100.dp) modifier = Modifier.size(340.dp, 200.dp)
){ ){
Row( Column(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp)
){
Column(
modifier = Modifier.fillMaxWidth(0.5f) ) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp).size(340.dp,60.dp)
){ ){
val localDateFormat = SimpleDateFormat("HH:mm") Column(
val time = localDateFormat.format(order.order.date) modifier = Modifier.fillMaxWidth(0.5f)
Text(
text = time,
fontFamily = NunitoFamily,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
){ ){
val localDateFormat = SimpleDateFormat("HH:mm")
val time = localDateFormat.format(order.order.date)
Text( Text(
text = order.orderWithProducts[0].productList[0].title, text = time,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
}
Button(
colors = ButtonDefaults.buttonColors(
backgroundColor = MyLightYellow
),
shape = RoundedCornerShape(size = 10.dp),
modifier = Modifier
.size(170.dp, 80.dp)
.fillMaxSize(),
onClick = { /*TODO*/ }
) {
Text( Text(
text = "x" + order.orderWithProducts[0].orderProductModel.quantity, text = "Выдано!",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 14.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
} }
} }
LazyColumn(
modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp)
){
items(order.orderWithProducts.size) {index ->
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
Button( ) {
colors = ButtonDefaults.buttonColors( Text(
backgroundColor = MyLightYellow text = order.orderWithProducts[index].product.title,
), fontFamily = NunitoFamily,
shape = RoundedCornerShape(size = 10.dp), fontSize = 20.sp,
modifier = Modifier fontWeight = FontWeight.Bold
.size(100.dp, 60.dp) )
.fillMaxSize(0.5f), Text(
onClick = { /*TODO*/ } text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
) { fontFamily = NunitoFamily,
Text( fontSize = 20.sp,
text = "Выдано!", fontWeight = FontWeight.Bold
fontFamily = NunitoFamily, )
fontSize = 14.sp, }
fontWeight = FontWeight.Bold }
)
} }
} }
} }
@ -316,61 +340,65 @@ fun ProcessedItem(order : OrderWithProducts){
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
modifier = Modifier.size(340.dp, 100.dp) modifier = Modifier.size(340.dp, 200.dp)
){ ){
Row( Column(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp)
){
Column(
modifier = Modifier.fillMaxWidth(0.5f) ) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.padding(20.dp).size(340.dp,60.dp)
){ ){
val localDateFormat = SimpleDateFormat("HH:mm") Column(
val time = localDateFormat.format(order.order.date) modifier = Modifier.fillMaxWidth(0.5f)
Text(
text = time,
fontFamily = NunitoFamily,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
){ ){
val localDateFormat = SimpleDateFormat("HH:mm")
val time = localDateFormat.format(order.order.date)
Text( Text(
text = order.orderWithProducts[0].productList[0].title, text = time,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
}
Column(
modifier = Modifier.fillMaxWidth(0.5f)
){
Text( Text(
text = "x" + order.orderWithProducts[0].orderProductModel.quantity, text = order.order.date.toString(),
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 16.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
} }
} }
LazyColumn(
Column( modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp)
modifier = Modifier.fillMaxWidth(0.5f)
){ ){
Text( items(order.orderWithProducts.size) {index ->
text = order.orderWithProducts[0].orderProductModel.totalPrice.toString(), Row(
fontFamily = NunitoFamily, modifier = Modifier.fillMaxWidth(),
fontSize = 14.sp, horizontalArrangement = Arrangement.SpaceBetween,
fontWeight = FontWeight.Bold
) ) {
Text( Text(
text = order.order.date.toString(), text = order.orderWithProducts[index].product.title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 14.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text(
text = "x" + order.orderWithProducts[index].orderProductModel.quantity,
fontFamily = NunitoFamily,
fontSize = 20.sp,
fontWeight = FontWeight.Bold
)
}
}
} }
} }
} }