From e839f69d191655caea5fefc6326243d7748dd0a8 Mon Sep 17 00:00:00 2001 From: danyasedoy Date: Sat, 18 Nov 2023 20:32:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=B2=D0=B5=D0=BB=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=80=D0=B0=D1=84=D0=B5=D1=82=D1=83=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=20=D1=87=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82=D0=BE=D0=B9?= =?UTF-8?q?=20=D0=BB=D0=B0=D0=B1=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/shawarma/data/db/AppDatabase.kt | 22 +- .../models/OrderProductModelWithProduct.kt | 2 +- .../shawarma/screens/cart/CartScreen.kt | 225 +++++++-------- .../shawarma/screens/orders/OrdersScreen.kt | 256 ++++++++++-------- 4 files changed, 276 insertions(+), 229 deletions(-) diff --git a/app/src/main/java/com/example/shawarma/data/db/AppDatabase.kt b/app/src/main/java/com/example/shawarma/data/db/AppDatabase.kt index e1001ef..3c0f6f6 100644 --- a/app/src/main/java/com/example/shawarma/data/db/AppDatabase.kt +++ b/app/src/main/java/com/example/shawarma/data/db/AppDatabase.kt @@ -73,13 +73,29 @@ abstract class AppDatabase : RoomDatabase() { // OrderProducts val orderProductDao = database.orderProductDao() val op1 = OrderProductModel(1, 1, 2, 200) - val op2 = OrderProductModel(2, 4, 3, 150) - val op3 = OrderProductModel(3, 3, 1, 80) - val op4 = OrderProductModel(4, 2, 1, 120) + val op2 = OrderProductModel(1, 4, 3, 150) + val op3 = OrderProductModel(1, 3, 1, 80) + 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(op2) orderProductDao.insert(op3) 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) } } diff --git a/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt b/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt index 378d6c5..d0de22f 100644 --- a/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt +++ b/app/src/main/java/com/example/shawarma/data/models/OrderProductModelWithProduct.kt @@ -7,5 +7,5 @@ data class OrderProductModelWithProduct( @Embedded val orderProductModel: OrderProductModel, @Relation(entity = ProductModel::class, parentColumn = "product_id", entityColumn = "id") - val productList: List + val product: ProductModel ) diff --git a/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt b/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt index 80a16ed..49681cd 100644 --- a/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/cart/CartScreen.kt @@ -24,7 +24,9 @@ import androidx.compose.material.Icon import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateListOf +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -73,12 +75,12 @@ fun CartWidget(){ } } - val unpaidOrders = mutableListOf() + var unpaidOrder: OrderWithProducts? = null val preparingOrders = mutableListOf() for(order in orders) { if (order.order.status == OrderStatus.Неоплачено.toString()) { - unpaidOrders.add(order) + unpaidOrder = order } if (order.order.status == OrderStatus.Готовится.toString() || order.order.status == OrderStatus.Готово.toString()) { preparingOrders.add(order) @@ -105,7 +107,7 @@ fun CartWidget(){ horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier .fillMaxWidth() - .padding(top=55.dp) + .padding(top = 55.dp) .verticalScroll(rememberScrollState()) ) { @@ -132,14 +134,8 @@ fun CartWidget(){ modifier = Modifier.padding(top = 15.dp), fontWeight = FontWeight.Bold ) - LazyColumn( - modifier = Modifier - .width(340.dp) - .height(200.dp) - ) { - items(unpaidOrders.size) {index -> - CartItem(unpaidOrders[index]) - } + if (unpaidOrder != null) { + CartItem(order = unpaidOrder) } Spacer(modifier = Modifier.height(20.dp)) @@ -175,59 +171,62 @@ fun PaidItem(order : OrderWithProducts) { shape = RoundedCornerShape(size = 20.dp), backgroundColor = Color.White, modifier = Modifier.size(340.dp, 100.dp) - ) { - Column { - Row( - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp) - ){ - Text( - text = order.orderWithProducts[0].productList[0].title, - fontFamily = NunitoFamily, - fontSize = 20.sp, - modifier = Modifier.padding(top = 15.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = "x" + order.orderWithProducts[0].orderProductModel.quantity, - fontFamily = NunitoFamily, - fontSize = 20.sp, - modifier = Modifier.padding(top = 15.dp), - fontWeight = FontWeight.Bold - ) - Text( - text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.", - fontFamily = NunitoFamily, - fontSize = 20.sp, - modifier = Modifier.padding(top = 15.dp), - fontWeight = FontWeight.Bold - ) - } - - Row( - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 20.dp) - ){ - Text( - text = "Статус: ", - fontFamily = NunitoFamily, - fontSize = 20.sp, - modifier = Modifier.padding(top = 15.dp), - fontWeight = FontWeight.Bold, - color = Color.Gray - ) - Text( - text = order.order.status, - fontFamily = NunitoFamily, - fontSize = 20.sp, - modifier = Modifier.padding(top = 15.dp), - fontWeight = FontWeight.Bold, - color = Color.Gray - ) + ) { + LazyColumn { + items(order.orderWithProducts.size) { index -> + if (index == 0) { + Row( + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier + .fillMaxWidth() + .padding(start = 20.dp, end = 20.dp) + ){ + Text( + text = "Статус: ", + fontFamily = NunitoFamily, + fontSize = 20.sp, + modifier = Modifier.padding(top = 15.dp), + fontWeight = FontWeight.Bold, + color = Color.Gray + ) + Text( + text = order.order.status, + fontFamily = NunitoFamily, + fontSize = 20.sp, + modifier = Modifier.padding(top = 15.dp), + fontWeight = FontWeight.Bold, + color = Color.Gray + ) + } + } + Row( + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 20.dp) + ) { + Text( + text = order.orderWithProducts[index].product.title, + fontFamily = NunitoFamily, + fontSize = 20.sp, + modifier = Modifier.padding(top = 15.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = "x" + order.orderWithProducts[index].orderProductModel.quantity, + fontFamily = NunitoFamily, + fontSize = 20.sp, + modifier = Modifier.padding(top = 15.dp), + fontWeight = FontWeight.Bold + ) + Text( + text = order.orderWithProducts[index].orderProductModel.totalPrice.toString() + " руб.", + fontFamily = NunitoFamily, + 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), shape = RoundedCornerShape(size = 20.dp), backgroundColor = Color.White, - modifier = Modifier.size(340.dp, 100.dp) + modifier = Modifier.size(340.dp, 180.dp) ) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.padding(20.dp) + LazyColumn ( + horizontalAlignment = Alignment.CenterHorizontally ) { - Column( - - modifier = Modifier.fillMaxWidth(0.5f) - ) { + items(order.orderWithProducts.size) {index -> Row( + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth() - ){ - Text( - text = order.orderWithProducts[0].productList[0].title, - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) - Text( - text = "x" + order.orderWithProducts[0].orderProductModel.quantity, - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) - } - Text( - text = order.orderWithProducts[0].orderProductModel.totalPrice.toString() + " руб.", - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) - } + modifier = Modifier.padding(20.dp).size(340.dp, 60.dp) + ) { + Column( + modifier = Modifier.fillMaxWidth(0.5f) + ) { + Row( + horizontalArrangement = Arrangement.SpaceBetween, + modifier = Modifier.fillMaxWidth() + ) { + Text( + text = order.orderWithProducts[index].product.title, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + Text( + text = "x" + order.orderWithProducts[index].orderProductModel.quantity, + fontFamily = NunitoFamily, + fontSize = 20.sp, + 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)) } \ No newline at end of file diff --git a/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt b/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt index bd94d53..480e3f8 100644 --- a/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/orders/OrdersScreen.kt @@ -5,6 +5,8 @@ import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box 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.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -180,61 +182,72 @@ fun PreparingItem(order : OrderWithProducts){ border = BorderStroke(width = 2.dp, color = MyOrange), shape = RoundedCornerShape(size = 20.dp), backgroundColor = Color.White, - modifier = Modifier.size(340.dp, 100.dp) + modifier = Modifier.size(340.dp, 200.dp) ){ - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.padding(20.dp) - ){ - Column( + 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") - val time = localDateFormat.format(order.order.date) - Text( - text = time, - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) - Row( - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth() + Column( + modifier = Modifier.fillMaxWidth(0.5f) ){ + val localDateFormat = SimpleDateFormat("HH:mm") + val time = localDateFormat.format(order.order.date) Text( - text = order.orderWithProducts[0].productList[0].title, + text = time, fontFamily = NunitoFamily, fontSize = 20.sp, 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 = "x" + order.orderWithProducts[0].orderProductModel.quantity, + text = "Готово!", fontFamily = NunitoFamily, - fontSize = 20.sp, + fontSize = 14.sp, 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( - backgroundColor = MyLightYellow - ), - shape = RoundedCornerShape(size = 10.dp), - modifier = Modifier - .size(100.dp, 60.dp) - .fillMaxSize(0.5f), - onClick = { /*TODO*/ } - ) { - Text( - text = "Готово!", - fontFamily = NunitoFamily, - fontSize = 14.sp, - fontWeight = FontWeight.Bold - ) + ) { + Text( + text = order.orderWithProducts[index].product.title, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + Text( + text = "x" + order.orderWithProducts[index].orderProductModel.quantity, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + } + } } } } @@ -248,61 +261,72 @@ fun PreparedItem(order : OrderWithProducts){ border = BorderStroke(width = 2.dp, color = MyOrange), shape = RoundedCornerShape(size = 20.dp), backgroundColor = Color.White, - modifier = Modifier.size(340.dp, 100.dp) + modifier = Modifier.size(340.dp, 200.dp) ){ - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.padding(20.dp) - ){ - Column( + 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") - val time = localDateFormat.format(order.order.date) - Text( - text = time, - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) - Row( - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth() + Column( + modifier = Modifier.fillMaxWidth(0.5f) ){ + val localDateFormat = SimpleDateFormat("HH:mm") + val time = localDateFormat.format(order.order.date) Text( - text = order.orderWithProducts[0].productList[0].title, + text = time, fontFamily = NunitoFamily, fontSize = 20.sp, 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 = "x" + order.orderWithProducts[0].orderProductModel.quantity, + text = "Выдано!", fontFamily = NunitoFamily, - fontSize = 20.sp, + fontSize = 14.sp, 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( - backgroundColor = MyLightYellow - ), - shape = RoundedCornerShape(size = 10.dp), - modifier = Modifier - .size(100.dp, 60.dp) - .fillMaxSize(0.5f), - onClick = { /*TODO*/ } - ) { - Text( - text = "Выдано!", - fontFamily = NunitoFamily, - fontSize = 14.sp, - fontWeight = FontWeight.Bold - ) + ) { + Text( + text = order.orderWithProducts[index].product.title, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + Text( + text = "x" + order.orderWithProducts[index].orderProductModel.quantity, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + } + } } } } @@ -316,61 +340,65 @@ fun ProcessedItem(order : OrderWithProducts){ border = BorderStroke(width = 2.dp, color = MyOrange), shape = RoundedCornerShape(size = 20.dp), backgroundColor = Color.White, - modifier = Modifier.size(340.dp, 100.dp) + modifier = Modifier.size(340.dp, 200.dp) ){ - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.padding(20.dp) - ){ - Column( + 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") - val time = localDateFormat.format(order.order.date) - Text( - text = time, - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) - Row( - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth() + Column( + modifier = Modifier.fillMaxWidth(0.5f) ){ + val localDateFormat = SimpleDateFormat("HH:mm") + val time = localDateFormat.format(order.order.date) Text( - text = order.orderWithProducts[0].productList[0].title, + text = time, fontFamily = NunitoFamily, fontSize = 20.sp, fontWeight = FontWeight.Bold ) + + } + Column( + modifier = Modifier.fillMaxWidth(0.5f) + ){ Text( - text = "x" + order.orderWithProducts[0].orderProductModel.quantity, + text = order.order.date.toString(), fontFamily = NunitoFamily, - fontSize = 20.sp, + fontSize = 16.sp, fontWeight = FontWeight.Bold ) } + } - - Column( - - modifier = Modifier.fillMaxWidth(0.5f) + LazyColumn( + modifier = Modifier.fillMaxWidth().padding(horizontal = 20.dp) ){ - Text( - text = order.orderWithProducts[0].orderProductModel.totalPrice.toString(), - fontFamily = NunitoFamily, - fontSize = 14.sp, - fontWeight = FontWeight.Bold - ) - Text( - text = order.order.date.toString(), - fontFamily = NunitoFamily, - fontSize = 14.sp, - fontWeight = FontWeight.Bold - ) + items(order.orderWithProducts.size) {index -> + Row( + modifier = Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.SpaceBetween, + + ) { + Text( + text = order.orderWithProducts[index].product.title, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + Text( + text = "x" + order.orderWithProducts[index].orderProductModel.quantity, + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + } + } } } }