From d6d2ef8f52c6acbad20066fce06ca1f3b663fe3a Mon Sep 17 00:00:00 2001 From: Danya_Mochalov Date: Wed, 8 Nov 2023 06:54:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AD=D0=BA=D1=80=D0=B0=D0=BD=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2,=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B4=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D1=82=D1=8C=20=D1=82=D0=B0=D0=BA=20=D1=87=D1=82?= =?UTF-8?q?=D0=BE=D0=B1=D1=8B=20=D0=BE=D0=BD=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=20=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/shawarma/screens/MainNavBar.kt | 6 +- .../authorization/AuthorizationScreen.kt | 8 +- .../screens/products/ProductScreen.kt | 130 ++++++++++++++++++ .../screens/products/ProductsScreen.kt | 36 +++-- .../com/example/shawarma/utils/ScreenPaths.kt | 2 +- 5 files changed, 166 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/com/example/shawarma/screens/products/ProductScreen.kt diff --git a/app/src/main/java/com/example/shawarma/screens/MainNavBar.kt b/app/src/main/java/com/example/shawarma/screens/MainNavBar.kt index 7658f60..22e24a8 100644 --- a/app/src/main/java/com/example/shawarma/screens/MainNavBar.kt +++ b/app/src/main/java/com/example/shawarma/screens/MainNavBar.kt @@ -17,6 +17,7 @@ import com.example.shawarma.screens.cart.CartScreen import com.example.shawarma.screens.discount.DiscountScreen import com.example.shawarma.screens.home.HomeScreen import com.example.shawarma.screens.orders.OrdersScreen +import com.example.shawarma.screens.products.ProductScreen import com.example.shawarma.screens.products.ProductsScreen import com.example.shawarma.screens.registration.RegistrationScreen import com.example.shawarma.ui.theme.MyLightYellow @@ -58,7 +59,10 @@ fun MainNavBar() { OrdersScreen() } composable(ScreenPaths.products.name) { - ProductsScreen() + ProductsScreen(navController) + } + composable(ScreenPaths.product.name) { + ProductScreen(navController) } } } diff --git a/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt b/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt index 328c6db..a359865 100644 --- a/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/authorization/AuthorizationScreen.kt @@ -98,10 +98,10 @@ fun AuthorizationCard(navHostController: NavHostController) { Button( onClick = { navHostController.navigate(ScreenPaths.home.name) { - popUpTo(ScreenPaths.home.name) { - inclusive = true - } - }}, + popUpTo(ScreenPaths.authorization.name) { + inclusive = true + } + } }, colors = ButtonDefaults.buttonColors(MyLightRed, Color.White), shape = RoundedCornerShape(20.dp), modifier = Modifier diff --git a/app/src/main/java/com/example/shawarma/screens/products/ProductScreen.kt b/app/src/main/java/com/example/shawarma/screens/products/ProductScreen.kt new file mode 100644 index 0000000..88935fc --- /dev/null +++ b/app/src/main/java/com/example/shawarma/screens/products/ProductScreen.kt @@ -0,0 +1,130 @@ +package com.example.shawarma.screens.products + +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.zIndex +import androidx.navigation.NavHostController +import com.example.shawarma.ui.theme.MarckFamily +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.MyTextField +import com.example.shawarma.widgets.ShawarmaLogo2 + +@Composable +fun ProductScreen(navHostController: NavHostController) { + Box( + contentAlignment = Alignment.TopCenter + ) { + ProductWidget(navHostController) + ShawarmaLogo2() + } +} + +@Composable +fun ProductWidget(navHostController: NavHostController) { + val title = remember { mutableStateOf(TextFieldValue(""))} + val price = remember { mutableStateOf(TextFieldValue(""))} + val oldPrice = remember { mutableStateOf(TextFieldValue(""))} + Box( + modifier = Modifier + .clip(shape = RoundedCornerShape(30.dp)) + .padding(top = 100.dp) + .fillMaxSize() + .background(color = MyMainBackground) + .zIndex(2f), + + contentAlignment = Alignment.TopCenter + ){ + Text( + text = "Товар", + fontFamily = MarckFamily, + fontSize = 40.sp, + modifier = Modifier.padding(top = 15.dp) + ) + Column( + modifier = Modifier + .padding(top = 60.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + MyTextField( + text = title, + onTextChanged = {title.value = it}, + modifier = Modifier + .padding( + top = (20).dp + ) + .size(300.dp, (60).dp), + placeholder = "Наименование", + singleLine = true + ) + MyTextField( + text = price, + onTextChanged = {price.value = it}, + modifier = Modifier + .padding( + top = (20).dp + ) + .size(300.dp, (60).dp), + placeholder = "Цена", + singleLine = true + ) + MyTextField( + text = oldPrice, + onTextChanged = {oldPrice.value = it}, + modifier = Modifier + .padding( + top = (20).dp + ) + .size(300.dp, (60).dp), + placeholder = "Старая цена", + singleLine = true + ) + Button( + modifier = Modifier + .padding(top = 80.dp) + .size(300.dp, 50.dp), + colors = ButtonDefaults.buttonColors( + backgroundColor = MyLightYellow + ), + border = BorderStroke(2.dp, color = MyOrange), + shape = RoundedCornerShape(20.dp), + onClick = { + // TODO + navHostController.popBackStack() + } + ) { + Text( + text = "Добавить", + fontFamily = NunitoFamily, + fontSize = 24.sp, + fontWeight = FontWeight.Bold + ) + } + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt b/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt index 473d5c8..b28cafd 100644 --- a/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt +++ b/app/src/main/java/com/example/shawarma/screens/products/ProductsScreen.kt @@ -34,6 +34,7 @@ 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 androidx.navigation.NavHostController import com.example.shawarma.R import com.example.shawarma.data.db.AppDatabase import com.example.shawarma.data.models.ProductModel @@ -45,16 +46,17 @@ 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.utils.ScreenPaths import com.example.shawarma.widgets.ShawarmaLogo2 import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext @Composable -fun ProductsScreen() { +fun ProductsScreen(navHostController: NavHostController) { Box( contentAlignment = Alignment.TopCenter ) { - ProductsList() + ProductsList(navHostController) ShawarmaLogo2() } } @@ -62,7 +64,7 @@ fun ProductsScreen() { @Composable -fun ProductsList(){ +fun ProductsList(navHostController: NavHostController){ val context = LocalContext.current val products = remember { mutableStateListOf() } LaunchedEffect(Unit) { @@ -99,7 +101,9 @@ fun ProductsList(){ ), border = BorderStroke(2.dp, color = MyOrange), shape = RoundedCornerShape(20.dp), - onClick = { /*TODO*/ } + onClick = { + navHostController.navigate(ScreenPaths.product.name) + } ) { Text( text = "Добавить товар", @@ -148,12 +152,24 @@ fun ProductItem(product: ProductModel){ fontSize = 20.sp, fontWeight = FontWeight.Bold ) - Text( - text = product.price.toString() + " руб.", - fontFamily = NunitoFamily, - fontSize = 20.sp, - fontWeight = FontWeight.Bold - ) + if (product.oldPrice != null) { + Text( + text = product.price.toString() + " руб.", + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold, + color = Color.Red + ) + } + else { + Text( + text = product.price.toString() + " руб.", + fontFamily = NunitoFamily, + fontSize = 20.sp, + fontWeight = FontWeight.Bold + ) + } + } Button( diff --git a/app/src/main/java/com/example/shawarma/utils/ScreenPaths.kt b/app/src/main/java/com/example/shawarma/utils/ScreenPaths.kt index df263ef..75b5ccb 100644 --- a/app/src/main/java/com/example/shawarma/utils/ScreenPaths.kt +++ b/app/src/main/java/com/example/shawarma/utils/ScreenPaths.kt @@ -1,5 +1,5 @@ package com.example.shawarma.utils enum class ScreenPaths { - authorization, registration, home, discount, cart, orders, products + authorization, registration, home, discount, cart, orders, products, product } \ No newline at end of file