From 861c47ab9b0c042bfb16576c304dfb1a845bd9eb Mon Sep 17 00:00:00 2001 From: Ismailov_Rovshan Date: Fri, 24 Nov 2023 12:19:09 +0400 Subject: [PATCH] 24.11 --- .../example/myapplication/components/Cart.kt | 3 - .../myapplication/components/Catalog.kt | 34 ------------ .../example/myapplication/components/Main.kt | 4 +- .../myapplication/components/Videocards.kt | 55 ------------------- .../components/common/ButtonNice.kt | 4 +- .../components/common/CatalogItem.kt | 48 ---------------- .../components/templates/CatalogItem.kt | 7 +++ .../CatalogItems.kt} | 35 +++++------- .../{common => templates}/ProductCard.kt | 16 +++--- .../ProductCardInCart.kt | 2 +- .../{common => templates}/ProductPage.kt | 9 +-- .../myapplication/components/Сategory.kt | 28 ++++++++++ .../myapplication/navigation/Navbar.kt | 21 +++++-- .../example/myapplication/styles/myColors.kt | 4 +- 14 files changed, 87 insertions(+), 183 deletions(-) delete mode 100644 app/src/main/java/com/example/myapplication/components/Catalog.kt delete mode 100644 app/src/main/java/com/example/myapplication/components/Videocards.kt delete mode 100644 app/src/main/java/com/example/myapplication/components/common/CatalogItem.kt create mode 100644 app/src/main/java/com/example/myapplication/components/templates/CatalogItem.kt rename app/src/main/java/com/example/myapplication/components/{Processors.kt => templates/CatalogItems.kt} (54%) rename app/src/main/java/com/example/myapplication/components/{common => templates}/ProductCard.kt (77%) rename app/src/main/java/com/example/myapplication/components/{common => templates}/ProductCardInCart.kt (93%) rename app/src/main/java/com/example/myapplication/components/{common => templates}/ProductPage.kt (90%) create mode 100644 app/src/main/java/com/example/myapplication/components/Сategory.kt diff --git a/app/src/main/java/com/example/myapplication/components/Cart.kt b/app/src/main/java/com/example/myapplication/components/Cart.kt index da2225e..3d1b302 100644 --- a/app/src/main/java/com/example/myapplication/components/Cart.kt +++ b/app/src/main/java/com/example/myapplication/components/Cart.kt @@ -55,9 +55,6 @@ fun Cart(navController: NavController){ @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 deleted file mode 100644 index b42c87d..0000000 --- a/app/src/main/java/com/example/myapplication/components/Catalog.kt +++ /dev/null @@ -1,34 +0,0 @@ -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -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 - -@Composable -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, "processors") - CatalogItem(text = "ОЗУ", navController, "processors") - } -} - -@Preview(showBackground = true) -@Composable -fun CatalogPreview() { -} \ No newline at end of file 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 9c120d9..0face11 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, navController) - ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2, navController) + //ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1, navController) + //ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2, navController) } } diff --git a/app/src/main/java/com/example/myapplication/components/Videocards.kt b/app/src/main/java/com/example/myapplication/components/Videocards.kt deleted file mode 100644 index 98cacd4..0000000 --- a/app/src/main/java/com/example/myapplication/components/Videocards.kt +++ /dev/null @@ -1,55 +0,0 @@ -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 Videocards (navController: NavController) { - LazyColumn { - item { - Text( - text = "Видеокарты", - fontSize = 28.sp, - color = Color.Black, - modifier = Modifier.padding(8.dp) - ) - } - item { - //ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC", 210999, R.drawable.product1) - } - item { - //ProductCard("Palit GeForce GTX 1660 SUPER", 25999, R.drawable.product2) - } - - item { - Button( - onClick = { }, - modifier = Modifier.fillMaxWidth(0.5f).padding(start = 10.dp, top = 10.dp), - border = BorderStroke(1.dp, Color.Black), - - colors = ButtonDefaults.buttonColors( - Color.Green, - ) - ) { - Text("Добавить товар", fontSize = 14.sp, color = Color.Black) - } - } - } -} -@Preview(showBackground = true) -@Composable -fun Videocards() { - val navController = rememberNavController() - //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 index 4ca931f..b493978 100644 --- a/app/src/main/java/com/example/myapplication/components/common/ButtonNice.kt +++ b/app/src/main/java/com/example/myapplication/components/common/ButtonNice.kt @@ -16,9 +16,9 @@ import androidx.compose.ui.unit.sp import androidx.navigation.NavController @Composable -fun ButtonNice(text: String, color: Color, route: String, navController: NavController){ +fun ButtonNice(text: String, color: Color, onClickAction: () -> Unit = {}){ Button( - onClick = { navController.navigate(route) }, + onClick = onClickAction, modifier = Modifier.fillMaxWidth(), border = BorderStroke(1.dp, Color.Black), shape = RoundedCornerShape(corner = CornerSize(5.dp)), 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 deleted file mode 100644 index 092d19a..0000000 --- a/app/src/main/java/com/example/myapplication/components/common/CatalogItem.kt +++ /dev/null @@ -1,48 +0,0 @@ -import androidx.compose.runtime.Composable -import androidx.compose.foundation.BorderStroke -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.Button -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material3.Button -import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.Text -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.RectangleShape -import androidx.compose.ui.graphics.painter.Painter -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.compose.ui.unit.sp -import androidx.navigation.compose.rememberNavController -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) { - - Button( - onClick = { navController.navigate(route) }, - modifier = Modifier.fillMaxWidth().padding(3.dp), - border = BorderStroke(1.dp, Color.Black), - shape = RoundedCornerShape(15.dp), - colors = ButtonDefaults.buttonColors( - containerColor = Color.White, - ) - ) { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically - ) { - TextNice(text) - } - } -} - diff --git a/app/src/main/java/com/example/myapplication/components/templates/CatalogItem.kt b/app/src/main/java/com/example/myapplication/components/templates/CatalogItem.kt new file mode 100644 index 0000000..6ce26f7 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/templates/CatalogItem.kt @@ -0,0 +1,7 @@ +import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color + +@Composable +fun CategoryItem (text: String, onClickAction: () -> Unit){ + ButtonNice(text, color = Color.White, onClickAction ) +} diff --git a/app/src/main/java/com/example/myapplication/components/Processors.kt b/app/src/main/java/com/example/myapplication/components/templates/CatalogItems.kt similarity index 54% rename from app/src/main/java/com/example/myapplication/components/Processors.kt rename to app/src/main/java/com/example/myapplication/components/templates/CatalogItems.kt index 3b437dd..3eaec82 100644 --- a/app/src/main/java/com/example/myapplication/components/Processors.kt +++ b/app/src/main/java/com/example/myapplication/components/templates/CatalogItems.kt @@ -1,6 +1,9 @@ import androidx.compose.foundation.BorderStroke +import androidx.compose.foundation.Image import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults @@ -8,41 +11,33 @@ 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.compose.ui.unit.sp import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController import com.example.myapplication.R @Composable -fun Processors (navController: NavController) { +fun CatalogItems (navController: NavController, title: String, products: List){ LazyColumn { item { Text( - text = "Процессоры", + text = title, fontSize = 28.sp, color = Color.Black, modifier = Modifier.padding(8.dp) ) } - item { - ProductCard("Intel Celeron G5905 OEM", 4099, R.drawable.product3, navController) - } - item { - ProductCard("AMD Ryzen 5 4500 BOX", 9799, R.drawable.product4, navController) - } - - item { - Button( - onClick = { }, - modifier = Modifier.fillMaxWidth(0.5f).padding(start = 10.dp, top = 10.dp), - border = BorderStroke(1.dp, Color.Black), - - colors = ButtonDefaults.buttonColors( - Color.Green, - ) - ) { - Text("Добавить товар", fontSize = 14.sp, color = Color.Black) + item{ + for (product in products){ + product.createProductCard({}) } } + + item { + ButtonNice("Инфо: " , myColor1, {}) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/common/ProductCard.kt b/app/src/main/java/com/example/myapplication/components/templates/ProductCard.kt similarity index 77% rename from app/src/main/java/com/example/myapplication/components/common/ProductCard.kt rename to app/src/main/java/com/example/myapplication/components/templates/ProductCard.kt index c9a3c5e..c52e742 100644 --- a/app/src/main/java/com/example/myapplication/components/common/ProductCard.kt +++ b/app/src/main/java/com/example/myapplication/components/templates/ProductCard.kt @@ -32,29 +32,29 @@ import androidx.navigation.compose.rememberNavController import com.example.myapplication.R @Composable -fun ProductCard(name: String, price: Int, @DrawableRes imgId: Int, navController: NavController) { +fun ProductCard(product: Product, onClickAction: () -> Unit) { Column (modifier = Modifier.padding(top = 20.dp, start = 10.dp, end=10.dp)) { Row { Image( - painter = painterResource(id = imgId), + painter = painterResource(id = product.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) - ButtonNice(text = "Инфо" , color = myColor2, route = "", navController = navController) + Text(text = product.name, fontSize = 24.sp, color = Color.Black) + Text(text = product.price.toString() + " ₽", fontSize = 16.sp, color = Color.Black) + // ButtonNice(text = "Инфо" , color = myColor2, navController.navigate("main")) } } - ButtonNice(text ="Добавить в корзину" , color = myColor1, route = "", navController = navController) + ButtonNice(text ="Добавить в корзину" , color = myColor1, onClickAction) } } - @Preview(showBackground = true) @Composable fun ProductCardPreview() { val navController = rememberNavController() - ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC" ,15000, R.drawable.product1, navController) + //val product: Product = Product("MSI GeForce RTX 4090 VENTUS 3X OC" ,"Инфо",15000, R.drawable.product1) + //ProductCard(product, {navController.navigate("main")}) } \ 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/templates/ProductCardInCart.kt similarity index 93% rename from app/src/main/java/com/example/myapplication/components/common/ProductCardInCart.kt rename to app/src/main/java/com/example/myapplication/components/templates/ProductCardInCart.kt index 5d2dd0f..bca8c85 100644 --- a/app/src/main/java/com/example/myapplication/components/common/ProductCardInCart.kt +++ b/app/src/main/java/com/example/myapplication/components/templates/ProductCardInCart.kt @@ -27,7 +27,7 @@ fun ProductCardInCart(name: String, price: Int, @DrawableRes imgId: Int) { contentDescription = null, modifier = Modifier .size(200.dp) - .aspectRatio(1f) // Устанавливаем соотношение сторон 1:1 (квадрат) + .aspectRatio(1f) ) Column (modifier = Modifier.padding(start = 15.dp, end = 15.dp)){ Text(text = name, fontSize = 24.sp, color = Color.Black) diff --git a/app/src/main/java/com/example/myapplication/components/common/ProductPage.kt b/app/src/main/java/com/example/myapplication/components/templates/ProductPage.kt similarity index 90% rename from app/src/main/java/com/example/myapplication/components/common/ProductPage.kt rename to app/src/main/java/com/example/myapplication/components/templates/ProductPage.kt index 143b15f..986b409 100644 --- a/app/src/main/java/com/example/myapplication/components/common/ProductPage.kt +++ b/app/src/main/java/com/example/myapplication/components/templates/ProductPage.kt @@ -19,24 +19,25 @@ import androidx.navigation.compose.rememberNavController import com.example.myapplication.R @Composable -fun ProductPage(name: String,info: String, price: Int, @DrawableRes imgId: Int, navController: NavController){ +fun ProductPage(name: String,info: String, price: Int, @DrawableRes imgId: Int, onClickAction: () -> Unit){ 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 (квадрат) + .aspectRatio(1f) )} item{TextNice("Характеристики: ")} item{Text(info)} - item{ButtonNice("Добавить в корзину", Color(185, 20, 255, 255), "",navController )} + item{ButtonNice("Добавить в корзину", Color(185, 20, 255, 255), onClickAction )} } } @@ -54,5 +55,5 @@ fun ProductPagePreview(){ "«Разогнанная» версия: Нет\n" + "Трассировка лучей: Да\n" + "Защита от майнинга (LHR): Нет\n" + - "Внешняя видеокарта: Нет",15000, R.drawable.product1, navController) + "Внешняя видеокарта: Нет",15000, R.drawable.product1, onClickAction = { navController.navigate("main") }) } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/components/Сategory.kt b/app/src/main/java/com/example/myapplication/components/Сategory.kt new file mode 100644 index 0000000..bddfed5 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/components/Сategory.kt @@ -0,0 +1,28 @@ +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController + +@Composable +fun Сategory(navController: NavController){ + Column(modifier = Modifier.fillMaxWidth().padding(start = 10.dp, end = 10.dp, top = 20.dp, ), + horizontalAlignment = Alignment.End + ){ + + CategoryItem(text = "Процессоры", { navController.navigate("processors") }) + CategoryItem(text = "Видеокарты", { navController.navigate("videocards") }) + + CategoryItem(text = "ПЗУ", { navController.navigate("processors") }) + CategoryItem(text = "ОЗУ", { navController.navigate("processors") }) + } +} + +@Preview(showBackground = true) +@Composable +fun CatalogPreview() { +} \ 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 81c4fc0..dce5221 100644 --- a/app/src/main/java/com/example/myapplication/navigation/Navbar.kt +++ b/app/src/main/java/com/example/myapplication/navigation/Navbar.kt @@ -29,9 +29,18 @@ fun Navbar() { val navController = rememberNavController() val items = listOf( NavItem("main", "Главная", R.drawable.home), - NavItem("catalog", "Каталог", R.drawable.search), + NavItem("category", "Каталог", R.drawable.search), NavItem("cart", "Корзина", R.drawable.cart), ) + val videocars = listOf( + Product(3, "MSI GeForce RTX 4090 VENTUS 3X OC", "Info", 210999, R.drawable.product1), + Product(4, "Palit GeForce GTX 1660 SUPER", "Info", 25999, R.drawable.product2), + ) + val processors = listOf( + Product(1,"Intel Celeron G5905 OEM","Info",4099, R.drawable.product3), + Product(2,"AMD Ryzen 5 4500 BOX","Info",9799, R.drawable.product4), + ) + Scaffold( bottomBar = { NavigationBar { @@ -61,13 +70,15 @@ fun Navbar() { startDestination = "authorization", modifier = Modifier.padding(innerPaddings) ) { - composable("main") { Main(navController) } composable("authorization") { Authorization(navController) } - composable("processors") { Processors(navController) } composable("registration") { Registration(navController) } - composable("catalog") { Catalog(navController) } - composable("videocards") { Videocards(navController) } + + composable("main") { Main(navController) } + composable("category") { Сategory(navController) } composable("cart") { Cart(navController)} + + composable("processors") { CatalogItems(navController,"Процессоры", processors)} + composable("videocards") { CatalogItems(navController,"Видеокарты", videocars)} } } } diff --git a/app/src/main/java/com/example/myapplication/styles/myColors.kt b/app/src/main/java/com/example/myapplication/styles/myColors.kt index b254ec7..e22c875 100644 --- a/app/src/main/java/com/example/myapplication/styles/myColors.kt +++ b/app/src/main/java/com/example/myapplication/styles/myColors.kt @@ -1,4 +1,6 @@ +import androidx.compose.ui.graphics.Brush 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 +val myColor2 = Color(156, 39, 176, 255) +