From 9fd9110d90c33233e1530c469689d6585b852a86 Mon Sep 17 00:00:00 2001 From: Ismailov_Rovshan Date: Sun, 12 Nov 2023 20:58:46 +0400 Subject: [PATCH] 12.11 --- .idea/deploymentTargetDropDown.xml | 17 ----- .../myapplication/components/AddProduct.kt | 8 +++ .../example/myapplication/components/Cart.kt | 63 +++++++++++++++++++ .../myapplication/components/Catalog.kt | 8 +-- .../example/myapplication/components/Main.kt | 5 +- .../myapplication/components/Processors.kt | 6 +- .../myapplication/components/Videocards.kt | 6 +- .../components/common/ButtonNice.kt | 31 +++++++++ .../components/common/CatalogItem.kt | 2 +- .../components/common/ProductCard.kt | 23 +++---- .../components/common/ProductCardInCart.kt | 49 +++++++++++++++ .../components/common/ProductPage.kt | 58 +++++++++++++++++ .../myapplication/navigation/Navbar.kt | 4 +- .../example/myapplication/styles/myColors.kt | 4 ++ 14 files changed, 236 insertions(+), 48 deletions(-) delete mode 100644 .idea/deploymentTargetDropDown.xml create mode 100644 app/src/main/java/com/example/myapplication/components/AddProduct.kt create mode 100644 app/src/main/java/com/example/myapplication/components/Cart.kt create mode 100644 app/src/main/java/com/example/myapplication/components/common/ButtonNice.kt create mode 100644 app/src/main/java/com/example/myapplication/components/common/ProductCardInCart.kt create mode 100644 app/src/main/java/com/example/myapplication/components/common/ProductPage.kt create mode 100644 app/src/main/java/com/example/myapplication/styles/myColors.kt diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml deleted file mode 100644 index a685b6d..0000000 --- a/.idea/deploymentTargetDropDown.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/AddProduct.kt b/app/src/main/java/com/example/myapplication/components/AddProduct.kt new file mode 100644 index 0000000..18ec699 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/AddProduct.kt @@ -0,0 +1,8 @@ +import androidx.compose.foundation.layout.Column +import androidx.compose.runtime.Composable +import androidx.navigation.NavController + +@Composable +fun Authorization() { + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/Cart.kt b/app/src/main/java/com/example/myapplication/components/Cart.kt new file mode 100644 index 0000000..da2225e --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/Cart.kt @@ -0,0 +1,63 @@ +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController +import com.example.myapplication.R + +@Composable +fun Cart(navController: NavController){ + + LazyColumn { + item { + Text( + text = "Корзина: ", + fontSize = 28.sp, + color = Color.Black, + modifier = Modifier.padding(8.dp) + ) + } + item { + ProductCardInCart("Intel Celeron G5905 OEM", 4099, R.drawable.product3) + } + item { + ProductCardInCart("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1) + } + item { + ProductCardInCart("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2) + } + item { + Button( + onClick = { }, + modifier = Modifier.fillMaxWidth().padding(top = 20.dp, bottom = 20.dp), + border = BorderStroke(1.dp, Color.Black), + colors = ButtonDefaults.buttonColors( + containerColor = Color.Magenta, + ) + ) { + TextNice("Оплатить: 240 097 рублей") + } + } + + } +} + +@Preview(showBackground = true) +@Composable +fun CartPreview() { + // Создаем заглушку для NavController + val navController = rememberNavController() + + // Выводим превью компонента + Cart(navController = navController) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/Catalog.kt b/app/src/main/java/com/example/myapplication/components/Catalog.kt index c586c62..b42c87d 100644 --- a/app/src/main/java/com/example/myapplication/components/Catalog.kt +++ b/app/src/main/java/com/example/myapplication/components/Catalog.kt @@ -21,10 +21,10 @@ fun Catalog(navController: NavController){ Column(modifier = Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, top = 20.dp, ), horizontalAlignment = Alignment.End ){ - CatalogItem(text = "Видеокарты",navController, "videocards") - CatalogItem(text = "Процессоры",navController, "processors") - CatalogItem(text = "ПЗУ",navController, "videocards") - CatalogItem(text = "ОЗУ",navController, "videocards") + CatalogItem(text = "Видеокарты", navController, "videocards") + CatalogItem(text = "Процессоры", navController, "processors") + CatalogItem(text = "ПЗУ", navController, "processors") + CatalogItem(text = "ОЗУ", navController, "processors") } } diff --git a/app/src/main/java/com/example/myapplication/components/Main.kt b/app/src/main/java/com/example/myapplication/components/Main.kt index 9d87a18..9c120d9 100644 --- a/app/src/main/java/com/example/myapplication/components/Main.kt +++ b/app/src/main/java/com/example/myapplication/components/Main.kt @@ -46,8 +46,8 @@ fun Main(navController: NavController) { modifier = Modifier.padding(8.dp) ) - ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1) - ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2) + ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1, navController) + ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2, navController) } } @@ -55,6 +55,5 @@ fun Main(navController: NavController) { @Composable fun MainPreview() { val navController = rememberNavController() - Main(navController = navController) } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/Processors.kt b/app/src/main/java/com/example/myapplication/components/Processors.kt index 9acc4fb..3b437dd 100644 --- a/app/src/main/java/com/example/myapplication/components/Processors.kt +++ b/app/src/main/java/com/example/myapplication/components/Processors.kt @@ -18,17 +18,17 @@ fun Processors (navController: NavController) { LazyColumn { item { Text( - text = "Видеокарты", + text = "Процессоры", fontSize = 28.sp, color = Color.Black, modifier = Modifier.padding(8.dp) ) } item { - ProductCard("Intel Celeron G5905 OEM", 4099, R.drawable.product3) + ProductCard("Intel Celeron G5905 OEM", 4099, R.drawable.product3, navController) } item { - ProductCard("AMD Ryzen 5 4500 BOX", 9799, R.drawable.product4) + ProductCard("AMD Ryzen 5 4500 BOX", 9799, R.drawable.product4, navController) } item { diff --git a/app/src/main/java/com/example/myapplication/components/Videocards.kt b/app/src/main/java/com/example/myapplication/components/Videocards.kt index d22db61..98cacd4 100644 --- a/app/src/main/java/com/example/myapplication/components/Videocards.kt +++ b/app/src/main/java/com/example/myapplication/components/Videocards.kt @@ -26,10 +26,10 @@ fun Videocards (navController: NavController) { ) } item { - ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1) + //ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1) } item { - ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2) + //ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2) } item { @@ -51,5 +51,5 @@ fun Videocards (navController: NavController) { @Composable fun Videocards() { val navController = rememberNavController() - Videocards(navController = navController) + //Videocards(navController = navController) } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/common/ButtonNice.kt b/app/src/main/java/com/example/myapplication/components/common/ButtonNice.kt new file mode 100644 index 0000000..4ca931f --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/common/ButtonNice.kt @@ -0,0 +1,31 @@ +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.foundation.shape.CutCornerShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.navigation.NavController + +@Composable +fun ButtonNice(text: String, color: Color, route: String, navController: NavController){ + Button( + onClick = { navController.navigate(route) }, + modifier = Modifier.fillMaxWidth(), + border = BorderStroke(1.dp, Color.Black), + shape = RoundedCornerShape(corner = CornerSize(5.dp)), + colors = ButtonDefaults.buttonColors( + containerColor = color, + ) + ) { + Text(text, fontSize = 20.sp, color = Color.Black) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/common/CatalogItem.kt b/app/src/main/java/com/example/myapplication/components/common/CatalogItem.kt index 34cd199..092d19a 100644 --- a/app/src/main/java/com/example/myapplication/components/common/CatalogItem.kt +++ b/app/src/main/java/com/example/myapplication/components/common/CatalogItem.kt @@ -23,6 +23,7 @@ import android.graphics.Bitmap import androidx.compose.foundation.Image import androidx.compose.foundation.layout.size import androidx.navigation.NavController +import com.example.myapplication.R @Composable fun CatalogItem(text: String, navController: NavController, route: String) { @@ -45,4 +46,3 @@ fun CatalogItem(text: String, navController: NavController, route: String) { } } - diff --git a/app/src/main/java/com/example/myapplication/components/common/ProductCard.kt b/app/src/main/java/com/example/myapplication/components/common/ProductCard.kt index e28450b..c9a3c5e 100644 --- a/app/src/main/java/com/example/myapplication/components/common/ProductCard.kt +++ b/app/src/main/java/com/example/myapplication/components/common/ProductCard.kt @@ -27,11 +27,12 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController import com.example.myapplication.R @Composable -fun ProductCard(name: String, price: Int, @DrawableRes imgId: Int) { - +fun ProductCard(name: String, price: Int, @DrawableRes imgId: Int, navController: NavController) { Column (modifier = Modifier.padding(top = 20.dp, start = 10.dp, end=10.dp)) { Row { Image( @@ -44,26 +45,16 @@ fun ProductCard(name: String, price: Int, @DrawableRes imgId: Int) { Column (modifier = Modifier.padding(start = 15.dp, end = 15.dp)){ Text(text = name, fontSize = 24.sp, color = Color.Black) Text(text = price.toString() + " ₽", fontSize = 16.sp, color = Color.Black) + ButtonNice(text = "Инфо" , color = myColor2, route = "", navController = navController) } } - Button( - onClick = { }, - modifier = Modifier.fillMaxWidth(), - border = BorderStroke(1.dp, Color.Black), - colors = ButtonDefaults.buttonColors( - containerColor = Color.White, - ) - ) { - TextNice("Добавить в корзину") - } - - + ButtonNice(text ="Добавить в корзину" , color = myColor1, route = "", navController = navController) } - } @Preview(showBackground = true) @Composable fun ProductCardPreview() { - ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC" ,15000, R.drawable.product1) + val navController = rememberNavController() + ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC" ,15000, R.drawable.product1, navController) } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/common/ProductCardInCart.kt b/app/src/main/java/com/example/myapplication/components/common/ProductCardInCart.kt new file mode 100644 index 0000000..5d2dd0f --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/common/ProductCardInCart.kt @@ -0,0 +1,49 @@ +import androidx.annotation.DrawableRes +import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp + +@Composable +fun ProductCardInCart(name: String, price: Int, @DrawableRes imgId: Int) { + + Column (modifier = Modifier.padding(top = 20.dp, start = 10.dp, end=10.dp)) { + Row { + Image( + painter = painterResource(id = imgId), + contentDescription = null, + modifier = Modifier + .size(200.dp) + .aspectRatio(1f) // Устанавливаем соотношение сторон 1:1 (квадрат) + ) + Column (modifier = Modifier.padding(start = 15.dp, end = 15.dp)){ + Text(text = name, fontSize = 24.sp, color = Color.Black) + Text(text = price.toString() + " ₽", fontSize = 16.sp, color = Color.Black) + } + } + Button( + onClick = { }, + modifier = Modifier.fillMaxWidth(), + border = BorderStroke(1.dp, Color.Black), + colors = ButtonDefaults.buttonColors( + containerColor = Color.White, + ) + ) { + TextNice("Убрать из корзины") + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/common/ProductPage.kt b/app/src/main/java/com/example/myapplication/components/common/ProductPage.kt new file mode 100644 index 0000000..143b15f --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/common/ProductPage.kt @@ -0,0 +1,58 @@ +import androidx.annotation.DrawableRes +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.aspectRatio +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController +import com.example.myapplication.R + +@Composable +fun ProductPage(name: String,info: String, price: Int, @DrawableRes imgId: Int, navController: NavController){ + LazyColumn (modifier = Modifier.fillMaxSize().padding(10.dp)) { + + item{ + TextNice(name) + } + item { + Image( + painter = painterResource(id = imgId), + contentDescription = null, + modifier = Modifier + .size(400.dp) + .aspectRatio(1f) // Устанавливаем соотношение сторон 1:1 (квадрат) + )} + + item{TextNice("Характеристики: ")} + item{Text(info)} + item{ButtonNice("Добавить в корзину", Color(185, 20, 255, 255), "",navController )} + } +} + +@Preview +@Composable +fun ProductPagePreview(){ + val navController = rememberNavController() + ProductPage("MSI GeForce RTX 4090 VENTUS 3X OC" ,"Общая информация: Дата выхода на рынок 2022 г.\n" + + "Основные характеристики: Подбор в один клик с трассировкой лучей, для игр в 4K, для рендеринга, профессиональная\n" + + "Интерфейс: PCI Express x16 4.0\n" + + "Производитель графического процессора: NVIDIA\n" + + "Микроархитектура: NVIDIA Ada Lovelace\n" + + "Кодовое имя чипа: AD102\n" + + "Графический процессор: GeForce RTX 4090\n" + + "«Разогнанная» версия: Нет\n" + + "Трассировка лучей: Да\n" + + "Защита от майнинга (LHR): Нет\n" + + "Внешняя видеокарта: Нет",15000, R.drawable.product1, navController) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/navigation/Navbar.kt b/app/src/main/java/com/example/myapplication/navigation/Navbar.kt index cd25279..81c4fc0 100644 --- a/app/src/main/java/com/example/myapplication/navigation/Navbar.kt +++ b/app/src/main/java/com/example/myapplication/navigation/Navbar.kt @@ -54,7 +54,8 @@ fun Navbar() { } } } - ) {innerPaddings -> + ) + { innerPaddings -> NavHost( navController = navController, startDestination = "authorization", @@ -66,6 +67,7 @@ fun Navbar() { composable("registration") { Registration(navController) } composable("catalog") { Catalog(navController) } composable("videocards") { Videocards(navController) } + composable("cart") { Cart(navController)} } } } diff --git a/app/src/main/java/com/example/myapplication/styles/myColors.kt b/app/src/main/java/com/example/myapplication/styles/myColors.kt new file mode 100644 index 0000000..b254ec7 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/styles/myColors.kt @@ -0,0 +1,4 @@ +import androidx.compose.ui.graphics.Color + +val myColor1 = Color(68, 228, 208) +val myColor2 = Color(233, 30, 165, 255) \ No newline at end of file