Сдал вторую!
This commit is contained in:
parent
6c7a04d5d4
commit
d40de4701a
@ -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)
|
||||
)
|
||||
}
|
34
app/src/main/java/com/example/shawarma/models/OrderModel.kt
Normal file
34
app/src/main/java/com/example/shawarma/models/OrderModel.kt
Normal 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())
|
||||
)
|
||||
}
|
@ -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),
|
||||
)
|
||||
|
||||
}
|
5
app/src/main/java/com/example/shawarma/models/Status.kt
Normal file
5
app/src/main/java/com/example/shawarma/models/Status.kt
Normal file
@ -0,0 +1,5 @@
|
||||
package com.example.shawarma.models
|
||||
|
||||
enum class OrderStatus {
|
||||
Unpaid, Preparing, Prepared, Processed
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.example.shawarma.models
|
||||
|
||||
data class UserModel(
|
||||
val id: Int,
|
||||
val login: String,
|
||||
val password: String,
|
||||
val role: String
|
||||
)
|
@ -36,7 +36,7 @@ fun MainNavBar() {
|
||||
BottomNavBar(navController = navController)
|
||||
}
|
||||
}
|
||||
) {scaffoldPadding ->
|
||||
) {
|
||||
NavHost(navController = navController, startDestination = ScreenPaths.authorization.name) {
|
||||
composable(ScreenPaths.authorization.name) {
|
||||
AuthorizationScreen(navController)
|
||||
|
@ -38,6 +38,9 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
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.getOrdersByUserId
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightRed
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
@ -57,6 +60,20 @@ fun CartScreen() {
|
||||
|
||||
@Composable
|
||||
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(
|
||||
modifier = Modifier
|
||||
.clip(shape = RoundedCornerShape(30.dp))
|
||||
@ -93,8 +110,8 @@ fun CartWidget(){
|
||||
.width(340.dp)
|
||||
.height(200.dp)
|
||||
) {
|
||||
items(2) {
|
||||
PaidItem()
|
||||
items(preparingOrders.size * 2) {
|
||||
PaidItem(preparingOrders[0])
|
||||
}
|
||||
}
|
||||
Text(
|
||||
@ -109,8 +126,8 @@ fun CartWidget(){
|
||||
.width(340.dp)
|
||||
.height(200.dp)
|
||||
) {
|
||||
items(2) {
|
||||
CartItem()
|
||||
items(unpaidOrders.size * 2) {
|
||||
PaidItem(unpaidOrders[0])
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +158,7 @@ fun CartWidget(){
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PaidItem() {
|
||||
fun PaidItem(order : OrderModel) {
|
||||
Card(
|
||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(size = 20.dp),
|
||||
@ -156,21 +173,21 @@ fun PaidItem() {
|
||||
.padding(horizontal = 20.dp)
|
||||
){
|
||||
Text(
|
||||
text = "Классика",
|
||||
text = order.productsId.keys.first().title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "x2",
|
||||
text = "x" + order.productsId.values.first().toString(),
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "300 руб.",
|
||||
text = order.productsId.keys.first().price.toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
modifier = Modifier.padding(top = 15.dp),
|
||||
@ -207,7 +224,7 @@ fun PaidItem() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun CartItem() {
|
||||
fun CartItem(order : OrderModel) {
|
||||
Card(
|
||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(size = 20.dp),
|
||||
@ -228,20 +245,20 @@ fun CartItem() {
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
){
|
||||
Text(
|
||||
text = "Кока-кола",
|
||||
text = order.productsId.keys.first().title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "x2",
|
||||
text = "x" + order.productsId.values.first().toString(),
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = "300 руб.",
|
||||
text = order.productsId.keys.first().price.toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
|
@ -31,6 +31,8 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
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.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
@ -53,6 +55,9 @@ fun DiscountScreen() {
|
||||
|
||||
@Composable
|
||||
fun DiscountList(){
|
||||
|
||||
val products = getAllDiscountProducts()
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(shape = RoundedCornerShape(30.dp))
|
||||
@ -74,19 +79,19 @@ fun DiscountList(){
|
||||
modifier = Modifier.padding(top = 80.dp)
|
||||
)
|
||||
{
|
||||
items(3) { index ->
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 10.dp)
|
||||
) {
|
||||
DiscountCard()
|
||||
DiscountCard()
|
||||
items(products.size) { index ->
|
||||
if (index % 2 != 1) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 10.dp)
|
||||
) {
|
||||
DiscountCard(products[index])
|
||||
DiscountCard(products[index+1])
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Потом переделать под реальный объем данных
|
||||
if (index == 2) {
|
||||
if (index == products.size - 1) {
|
||||
Spacer(modifier = Modifier.height(70.dp))
|
||||
}
|
||||
}
|
||||
@ -95,7 +100,7 @@ fun DiscountList(){
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DiscountCard(){
|
||||
fun DiscountCard(product : DiscountProductModel){
|
||||
Card(
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
backgroundColor = Color.White,
|
||||
@ -107,7 +112,7 @@ fun DiscountCard(){
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "Классика",
|
||||
text = product.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
@ -132,14 +137,14 @@ fun DiscountCard(){
|
||||
modifier = Modifier.padding(start = 12.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "150 руб. ",
|
||||
text = product.oldPrice.toString() + "руб. ",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
textDecoration = TextDecoration.LineThrough
|
||||
)
|
||||
Text(
|
||||
text = "120 руб. ",
|
||||
text = product.newPrice.toString() + "руб. ",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.ExtraBold,
|
||||
|
@ -31,6 +31,8 @@ import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
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.MyLightYellow
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
@ -51,6 +53,9 @@ fun HomeScreen() {
|
||||
|
||||
@Composable
|
||||
fun HomeList(){
|
||||
|
||||
val products = getProducts()
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.clip(shape = RoundedCornerShape(30.dp))
|
||||
@ -72,19 +77,19 @@ fun HomeList(){
|
||||
modifier = Modifier.padding(top = 80.dp)
|
||||
)
|
||||
{
|
||||
items(3) { index ->
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 10.dp)
|
||||
) {
|
||||
ProductCard()
|
||||
ProductCard()
|
||||
items(products.size) { index ->
|
||||
if (index % 2 != 1) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceAround,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 10.dp)
|
||||
) {
|
||||
ProductCard(products[index])
|
||||
ProductCard(products[index + 1])
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Потом переделать под реальный объем данных
|
||||
if (index == 2) {
|
||||
if (index == products.size - 1) {
|
||||
Spacer(modifier = Modifier.height(70.dp))
|
||||
}
|
||||
}
|
||||
@ -93,7 +98,7 @@ fun HomeList(){
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ProductCard(){
|
||||
fun ProductCard(product: ProductModel){
|
||||
Card(
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
backgroundColor = Color.White,
|
||||
@ -105,7 +110,7 @@ fun ProductCard(){
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
Text(
|
||||
text = "Классика",
|
||||
text = product.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
@ -127,7 +132,7 @@ fun ProductCard(){
|
||||
Row(
|
||||
){
|
||||
Text(
|
||||
text = "150 руб. ",
|
||||
text = product.price.toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.ExtraBold,
|
||||
|
@ -20,27 +20,26 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Alignment.Companion.TopCenter
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
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.MyLightRed
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
import com.example.shawarma.ui.theme.MyOrange
|
||||
import com.example.shawarma.ui.theme.NunitoFamily
|
||||
import com.example.shawarma.widgets.ShawarmaLogo2
|
||||
import java.text.SimpleDateFormat
|
||||
|
||||
@Composable
|
||||
fun OrdersScreen() {
|
||||
@ -54,6 +53,25 @@ fun OrdersScreen() {
|
||||
|
||||
@Composable
|
||||
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(
|
||||
modifier = Modifier
|
||||
.clip(shape = RoundedCornerShape(30.dp))
|
||||
@ -90,8 +108,9 @@ fun OrdersList(){
|
||||
.width(340.dp)
|
||||
.height(250.dp)
|
||||
) {
|
||||
items(2) {
|
||||
PreparingItem()
|
||||
items(preparingOrders.size) {
|
||||
index ->
|
||||
PreparingItem(preparedOrders[index])
|
||||
}
|
||||
}
|
||||
Text(
|
||||
@ -106,8 +125,9 @@ fun OrdersList(){
|
||||
.width(340.dp)
|
||||
.height(250.dp)
|
||||
) {
|
||||
items(2) {
|
||||
PreparedItem()
|
||||
items(preparedOrders.size) {
|
||||
index ->
|
||||
PreparedItem(preparedOrders[index])
|
||||
}
|
||||
}
|
||||
Text(
|
||||
@ -134,7 +154,7 @@ fun OrdersList(){
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PreparingItem(){
|
||||
fun PreparingItem(order : OrderModel){
|
||||
Card(
|
||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(size = 20.dp),
|
||||
@ -150,8 +170,10 @@ fun PreparingItem(){
|
||||
|
||||
modifier = Modifier.fillMaxWidth(0.5f)
|
||||
){
|
||||
val localDateFormat = SimpleDateFormat("HH:mm")
|
||||
val time = localDateFormat.format(order.date)
|
||||
Text(
|
||||
text = "16:24",
|
||||
text = time,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
@ -161,13 +183,13 @@ fun PreparingItem(){
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
){
|
||||
Text(
|
||||
text = "Классика",
|
||||
text = order.productsId.keys.first().title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "x2",
|
||||
text = "x" + order.productsId.values.first().toString(),
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
@ -200,7 +222,7 @@ fun PreparingItem(){
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun PreparedItem(){
|
||||
fun PreparedItem(order : OrderModel){
|
||||
Card(
|
||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(size = 20.dp),
|
||||
@ -216,8 +238,10 @@ fun PreparedItem(){
|
||||
|
||||
modifier = Modifier.fillMaxWidth(0.5f)
|
||||
){
|
||||
val localDateFormat = SimpleDateFormat("HH:mm")
|
||||
val time = localDateFormat.format(order.date)
|
||||
Text(
|
||||
text = "16:24",
|
||||
text = time,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
@ -227,13 +251,13 @@ fun PreparedItem(){
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
){
|
||||
Text(
|
||||
text = "Классика",
|
||||
text = order.productsId.keys.first().title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = "x2",
|
||||
text = "x" + order.productsId.values.first().toString(),
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
|
Loading…
Reference in New Issue
Block a user