This commit is contained in:
Ismailov_Rovshan 2023-11-24 12:19:09 +04:00
parent 9fd9110d90
commit 861c47ab9b
14 changed files with 87 additions and 183 deletions

View File

@ -55,9 +55,6 @@ fun Cart(navController: NavController){
@Preview(showBackground = true)
@Composable
fun CartPreview() {
// Создаем заглушку для NavController
val navController = rememberNavController()
// Выводим превью компонента
Cart(navController = navController)
}

View File

@ -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() {
}

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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)),

View File

@ -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)
}
}
}

View File

@ -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 )
}

View File

@ -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<Product>){
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, {})
}
}
}

View File

@ -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")})
}

View File

@ -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)

View File

@ -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") })
}

View File

@ -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() {
}

View File

@ -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)}
}
}
}

View File

@ -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)
val myColor2 = Color(156, 39, 176, 255)