Сдал вторую!

This commit is contained in:
Данила Мочалов 2023-10-11 10:27:20 +04:00
parent 6c7a04d5d4
commit d40de4701a
10 changed files with 193 additions and 61 deletions

View File

@ -0,0 +1,15 @@
package com.example.shawarma.models
data class DiscountProductModel(
val id: Int,
val title: String,
val oldPrice: Int,
val newPrice: Int
)
fun getAllDiscountProducts() : List<DiscountProductModel> {
return listOf(
DiscountProductModel(1, "Шаурма", 150, 120),
DiscountProductModel(1, "Шаурма", 150, 120)
)
}

View File

@ -0,0 +1,34 @@
package com.example.shawarma.models
import java.util.Date
data class OrderModel(
val id: Int,
val status: OrderStatus,
val productsId: HashMap<ProductModel, Int>,
val userId: Int,
val date: Date
)
fun getOrdersByUserId() : List<OrderModel> {
val map1 = HashMap<ProductModel, Int>()
map1[ProductModel(1, "Классика", 150)] = 2
val map2 = HashMap<ProductModel, Int>()
map2[ProductModel(1, "Классика", 150)] = 2
return listOf(
OrderModel(1, OrderStatus.Unpaid, map1, 1, Date()),
OrderModel(2, OrderStatus.Preparing, map2 , 1, Date())
)
}
fun getAllOrders() : List<OrderModel> {
val map1 = HashMap<ProductModel, Int>()
map1[ProductModel(1, "Классика", 150)] = 2
return listOf(
OrderModel(1, OrderStatus.Prepared, map1, 1, Date()),
OrderModel(2, OrderStatus.Preparing, map1 , 1, Date()),
OrderModel(2, OrderStatus.Processed, map1 , 1, Date())
)
}

View File

@ -0,0 +1,19 @@
package com.example.shawarma.models
data class ProductModel(
val id: Int,
val title: String,
val price: Int
)
fun getProducts() :List<ProductModel> {
return listOf(
ProductModel(1, "Классика", 150),
ProductModel(1, "Классика", 150),
ProductModel(1, "Классика", 150),
ProductModel(1, "Классика", 150),
ProductModel(1, "Классика", 150),
ProductModel(1, "Классика", 150),
)
}

View File

@ -0,0 +1,5 @@
package com.example.shawarma.models
enum class OrderStatus {
Unpaid, Preparing, Prepared, Processed
}

View File

@ -0,0 +1,8 @@
package com.example.shawarma.models
data class UserModel(
val id: Int,
val login: String,
val password: String,
val role: String
)

View File

@ -36,7 +36,7 @@ fun MainNavBar() {
BottomNavBar(navController = navController) BottomNavBar(navController = navController)
} }
} }
) {scaffoldPadding -> ) {
NavHost(navController = navController, startDestination = ScreenPaths.authorization.name) { NavHost(navController = navController, startDestination = ScreenPaths.authorization.name) {
composable(ScreenPaths.authorization.name) { composable(ScreenPaths.authorization.name) {
AuthorizationScreen(navController) AuthorizationScreen(navController)

View File

@ -38,6 +38,9 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import com.example.shawarma.R import com.example.shawarma.R
import com.example.shawarma.models.OrderModel
import com.example.shawarma.models.OrderStatus
import com.example.shawarma.models.getOrdersByUserId
import com.example.shawarma.ui.theme.MarckFamily import com.example.shawarma.ui.theme.MarckFamily
import com.example.shawarma.ui.theme.MyLightRed import com.example.shawarma.ui.theme.MyLightRed
import com.example.shawarma.ui.theme.MyMainBackground import com.example.shawarma.ui.theme.MyMainBackground
@ -57,6 +60,20 @@ fun CartScreen() {
@Composable @Composable
fun CartWidget(){ fun CartWidget(){
val orders = getOrdersByUserId()
val unpaidOrders = mutableListOf<OrderModel>()
val preparingOrders = mutableListOf<OrderModel>()
for(order in orders) {
if (order.status == OrderStatus.Unpaid) {
unpaidOrders.add(order)
}
if (order.status == OrderStatus.Preparing) {
preparingOrders.add(order)
}
}
Box( Box(
modifier = Modifier modifier = Modifier
.clip(shape = RoundedCornerShape(30.dp)) .clip(shape = RoundedCornerShape(30.dp))
@ -93,8 +110,8 @@ fun CartWidget(){
.width(340.dp) .width(340.dp)
.height(200.dp) .height(200.dp)
) { ) {
items(2) { items(preparingOrders.size * 2) {
PaidItem() PaidItem(preparingOrders[0])
} }
} }
Text( Text(
@ -109,8 +126,8 @@ fun CartWidget(){
.width(340.dp) .width(340.dp)
.height(200.dp) .height(200.dp)
) { ) {
items(2) { items(unpaidOrders.size * 2) {
CartItem() PaidItem(unpaidOrders[0])
} }
} }
@ -141,7 +158,7 @@ fun CartWidget(){
} }
@Composable @Composable
fun PaidItem() { fun PaidItem(order : OrderModel) {
Card( Card(
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
@ -156,21 +173,21 @@ fun PaidItem() {
.padding(horizontal = 20.dp) .padding(horizontal = 20.dp)
){ ){
Text( Text(
text = "Классика", text = order.productsId.keys.first().title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
modifier = Modifier.padding(top = 15.dp), modifier = Modifier.padding(top = 15.dp),
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text( Text(
text = "x2", text = "x" + order.productsId.values.first().toString(),
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
modifier = Modifier.padding(top = 15.dp), modifier = Modifier.padding(top = 15.dp),
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text( Text(
text = "300 руб.", text = order.productsId.keys.first().price.toString() + " руб.",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
modifier = Modifier.padding(top = 15.dp), modifier = Modifier.padding(top = 15.dp),
@ -207,7 +224,7 @@ fun PaidItem() {
} }
@Composable @Composable
fun CartItem() { fun CartItem(order : OrderModel) {
Card( Card(
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
@ -228,20 +245,20 @@ fun CartItem() {
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
Text( Text(
text = "Кока-кола", text = order.productsId.keys.first().title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text( Text(
text = "x2", text = "x" + order.productsId.values.first().toString(),
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
} }
Text( Text(
text = "300 руб.", text = order.productsId.keys.first().price.toString() + " руб.",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold

View File

@ -31,6 +31,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import com.example.shawarma.R import com.example.shawarma.R
import com.example.shawarma.models.DiscountProductModel
import com.example.shawarma.models.getAllDiscountProducts
import com.example.shawarma.screens.home.HomeList import com.example.shawarma.screens.home.HomeList
import com.example.shawarma.ui.theme.MarckFamily import com.example.shawarma.ui.theme.MarckFamily
import com.example.shawarma.ui.theme.MyLightYellow import com.example.shawarma.ui.theme.MyLightYellow
@ -53,6 +55,9 @@ fun DiscountScreen() {
@Composable @Composable
fun DiscountList(){ fun DiscountList(){
val products = getAllDiscountProducts()
Box( Box(
modifier = Modifier modifier = Modifier
.clip(shape = RoundedCornerShape(30.dp)) .clip(shape = RoundedCornerShape(30.dp))
@ -74,19 +79,19 @@ fun DiscountList(){
modifier = Modifier.padding(top = 80.dp) modifier = Modifier.padding(top = 80.dp)
) )
{ {
items(3) { index -> items(products.size) { index ->
if (index % 2 != 1) {
Row( Row(
horizontalArrangement = Arrangement.SpaceAround, horizontalArrangement = Arrangement.SpaceAround,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 10.dp) .padding(top = 10.dp)
) { ) {
DiscountCard() DiscountCard(products[index])
DiscountCard() DiscountCard(products[index+1])
} }
}
// TODO Потом переделать под реальный объем данных if (index == products.size - 1) {
if (index == 2) {
Spacer(modifier = Modifier.height(70.dp)) Spacer(modifier = Modifier.height(70.dp))
} }
} }
@ -95,7 +100,7 @@ fun DiscountList(){
} }
@Composable @Composable
fun DiscountCard(){ fun DiscountCard(product : DiscountProductModel){
Card( Card(
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
@ -107,7 +112,7 @@ fun DiscountCard(){
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text( Text(
text = "Классика", text = product.title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
@ -132,14 +137,14 @@ fun DiscountCard(){
modifier = Modifier.padding(start = 12.dp) modifier = Modifier.padding(start = 12.dp)
) { ) {
Text( Text(
text = "150 руб. ", text = product.oldPrice.toString() + "руб. ",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 10.sp, fontSize = 10.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
textDecoration = TextDecoration.LineThrough textDecoration = TextDecoration.LineThrough
) )
Text( Text(
text = "120 руб. ", text = product.newPrice.toString() + "руб. ",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 16.sp, fontSize = 16.sp,
fontWeight = FontWeight.ExtraBold, fontWeight = FontWeight.ExtraBold,

View File

@ -31,6 +31,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import com.example.shawarma.R import com.example.shawarma.R
import com.example.shawarma.models.ProductModel
import com.example.shawarma.models.getProducts
import com.example.shawarma.ui.theme.MarckFamily import com.example.shawarma.ui.theme.MarckFamily
import com.example.shawarma.ui.theme.MyLightYellow import com.example.shawarma.ui.theme.MyLightYellow
import com.example.shawarma.ui.theme.MyMainBackground import com.example.shawarma.ui.theme.MyMainBackground
@ -51,6 +53,9 @@ fun HomeScreen() {
@Composable @Composable
fun HomeList(){ fun HomeList(){
val products = getProducts()
Box( Box(
modifier = Modifier modifier = Modifier
.clip(shape = RoundedCornerShape(30.dp)) .clip(shape = RoundedCornerShape(30.dp))
@ -72,19 +77,19 @@ fun HomeList(){
modifier = Modifier.padding(top = 80.dp) modifier = Modifier.padding(top = 80.dp)
) )
{ {
items(3) { index -> items(products.size) { index ->
if (index % 2 != 1) {
Row( Row(
horizontalArrangement = Arrangement.SpaceAround, horizontalArrangement = Arrangement.SpaceAround,
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.padding(top = 10.dp) .padding(top = 10.dp)
) { ) {
ProductCard() ProductCard(products[index])
ProductCard() ProductCard(products[index + 1])
} }
}
// TODO Потом переделать под реальный объем данных if (index == products.size - 1) {
if (index == 2) {
Spacer(modifier = Modifier.height(70.dp)) Spacer(modifier = Modifier.height(70.dp))
} }
} }
@ -93,7 +98,7 @@ fun HomeList(){
} }
@Composable @Composable
fun ProductCard(){ fun ProductCard(product: ProductModel){
Card( Card(
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
backgroundColor = Color.White, backgroundColor = Color.White,
@ -105,7 +110,7 @@ fun ProductCard(){
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text( Text(
text = "Классика", text = product.title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
@ -127,7 +132,7 @@ fun ProductCard(){
Row( Row(
){ ){
Text( Text(
text = "150 руб. ", text = product.price.toString() + " руб.",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 16.sp, fontSize = 16.sp,
fontWeight = FontWeight.ExtraBold, fontWeight = FontWeight.ExtraBold,

View File

@ -20,27 +20,26 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Card import androidx.compose.material.Card
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.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.TopCenter
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import com.example.shawarma.R import com.example.shawarma.models.OrderModel
import com.example.shawarma.models.OrderStatus
import com.example.shawarma.models.getAllOrders
import com.example.shawarma.ui.theme.MarckFamily import com.example.shawarma.ui.theme.MarckFamily
import com.example.shawarma.ui.theme.MyLightRed
import com.example.shawarma.ui.theme.MyLightYellow import com.example.shawarma.ui.theme.MyLightYellow
import com.example.shawarma.ui.theme.MyMainBackground import com.example.shawarma.ui.theme.MyMainBackground
import com.example.shawarma.ui.theme.MyOrange import com.example.shawarma.ui.theme.MyOrange
import com.example.shawarma.ui.theme.NunitoFamily import com.example.shawarma.ui.theme.NunitoFamily
import com.example.shawarma.widgets.ShawarmaLogo2 import com.example.shawarma.widgets.ShawarmaLogo2
import java.text.SimpleDateFormat
@Composable @Composable
fun OrdersScreen() { fun OrdersScreen() {
@ -54,6 +53,25 @@ fun OrdersScreen() {
@Composable @Composable
fun OrdersList(){ fun OrdersList(){
val allOrders = getAllOrders()
val preparingOrders = mutableListOf<OrderModel>()
val preparedOrders = mutableListOf<OrderModel>()
val processedOrders = mutableListOf<OrderModel>()
for (order in allOrders){
if (order.status == OrderStatus.Preparing) {
preparingOrders.add(order)
}
if (order.status == OrderStatus.Prepared) {
preparedOrders.add(order)
}
if (order.status == OrderStatus.Processed) {
processedOrders.add(order)
}
}
Box( Box(
modifier = Modifier modifier = Modifier
.clip(shape = RoundedCornerShape(30.dp)) .clip(shape = RoundedCornerShape(30.dp))
@ -90,8 +108,9 @@ fun OrdersList(){
.width(340.dp) .width(340.dp)
.height(250.dp) .height(250.dp)
) { ) {
items(2) { items(preparingOrders.size) {
PreparingItem() index ->
PreparingItem(preparedOrders[index])
} }
} }
Text( Text(
@ -106,8 +125,9 @@ fun OrdersList(){
.width(340.dp) .width(340.dp)
.height(250.dp) .height(250.dp)
) { ) {
items(2) { items(preparedOrders.size) {
PreparedItem() index ->
PreparedItem(preparedOrders[index])
} }
} }
Text( Text(
@ -134,7 +154,7 @@ fun OrdersList(){
} }
@Composable @Composable
fun PreparingItem(){ fun PreparingItem(order : OrderModel){
Card( Card(
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
@ -150,8 +170,10 @@ fun PreparingItem(){
modifier = Modifier.fillMaxWidth(0.5f) modifier = Modifier.fillMaxWidth(0.5f)
){ ){
val localDateFormat = SimpleDateFormat("HH:mm")
val time = localDateFormat.format(order.date)
Text( Text(
text = "16:24", text = time,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
@ -161,13 +183,13 @@ fun PreparingItem(){
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
Text( Text(
text = "Классика", text = order.productsId.keys.first().title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text( Text(
text = "x2", text = "x" + order.productsId.values.first().toString(),
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
@ -200,7 +222,7 @@ fun PreparingItem(){
} }
@Composable @Composable
fun PreparedItem(){ fun PreparedItem(order : OrderModel){
Card( Card(
border = BorderStroke(width = 2.dp, color = MyOrange), border = BorderStroke(width = 2.dp, color = MyOrange),
shape = RoundedCornerShape(size = 20.dp), shape = RoundedCornerShape(size = 20.dp),
@ -216,8 +238,10 @@ fun PreparedItem(){
modifier = Modifier.fillMaxWidth(0.5f) modifier = Modifier.fillMaxWidth(0.5f)
){ ){
val localDateFormat = SimpleDateFormat("HH:mm")
val time = localDateFormat.format(order.date)
Text( Text(
text = "16:24", text = time,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
@ -227,13 +251,13 @@ fun PreparedItem(){
modifier = Modifier.fillMaxWidth() modifier = Modifier.fillMaxWidth()
){ ){
Text( Text(
text = "Классика", text = order.productsId.keys.first().title,
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
) )
Text( Text(
text = "x2", text = "x" + order.productsId.values.first().toString(),
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold