This commit is contained in:
Ismailov_Rovshan 2023-11-11 03:13:55 +04:00
parent 98e60a6fb0
commit 27064d323b
14 changed files with 533 additions and 18 deletions

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<targetSelectedWithDropDown> <runningDeviceTargetSelectedWithDropDown>
<Target> <Target>
<type value="QUICK_BOOT_TARGET" /> <type value="RUNNING_DEVICE_TARGET" />
<deviceKey> <deviceKey>
<Key> <Key>
<type value="VIRTUAL_DEVICE_PATH" /> <type value="VIRTUAL_DEVICE_PATH" />
@ -11,7 +11,7 @@
</Key> </Key>
</deviceKey> </deviceKey>
</Target> </Target>
</targetSelectedWithDropDown> </runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-09-29T14:43:07.814095100Z" /> <timeTargetWasSelectedWithDropDown value="2023-11-10T22:33:40.539545300Z" />
</component> </component>
</project> </project>

View File

@ -5,12 +5,12 @@ plugins {
android { android {
namespace = "com.example.myapplication" namespace = "com.example.myapplication"
compileSdk = 33 compileSdk = 34
defaultConfig { defaultConfig {
applicationId = "com.example.myapplication" applicationId = "com.example.myapplication"
minSdk = 24 minSdk = 24
targetSdk = 33 targetSdk = 34
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"
@ -49,13 +49,15 @@ android {
dependencies { dependencies {
implementation("androidx.core:core-ktx:1.9.0") implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.7.0") implementation("androidx.activity:activity-compose:1.7.2")
implementation(platform("androidx.compose:compose-bom:2023.03.00")) implementation(platform("androidx.compose:compose-bom:2023.03.00"))
implementation("androidx.navigation:navigation-compose:2.6.0")
implementation("androidx.compose.ui:ui") implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3") implementation("androidx.compose.material3:material3")
implementation("androidx.navigation:navigation-runtime-ktx:2.7.5")
testImplementation("junit:junit:4.13.2") testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

View File

@ -1,5 +1,6 @@
package com.example.myapplication package com.example.myapplication
import Navbar
import android.os.Bundle import android.os.Bundle
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@ -19,25 +20,17 @@ class MainActivity : ComponentActivity() {
MyApplicationTheme { MyApplicationTheme {
// A surface container using the 'background' color from the theme // A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Android") Navbar()
} }
} }
} }
} }
} }
@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}
@Preview(showBackground = true) @Preview(showBackground = true)
@Composable @Composable
fun GreetingPreview() { fun GreetingPreview() {
MyApplicationTheme { MyApplicationTheme {
Greeting("Android") Navbar()
} }
} }

View File

@ -0,0 +1,34 @@
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, "videocards")
CatalogItem(text = "ОЗУ",navController, "videocards")
}
}
@Preview(showBackground = true)
@Composable
fun CatalogPreview() {
}

View File

@ -0,0 +1,60 @@
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
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.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
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
import com.example.myapplication.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Main(navController: NavController) {
Column(
modifier = Modifier
.fillMaxSize()
.padding(8.dp)
) {
OutlinedTextField(
value = "",
onValueChange = { },
placeholder = { Text("Поиск товара") },
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
)
Text(
text = "Товары дня:",
fontSize = 28.sp,
color = Color.Black,
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)
}
}
@Preview(showBackground = true)
@Composable
fun MainPreview() {
val navController = rememberNavController()
Main(navController = navController)
}

View File

@ -0,0 +1,48 @@
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.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.example.myapplication.R
@Composable
fun Processors (navController: NavController) {
LazyColumn {
item {
Text(
text = "Видеокарты",
fontSize = 28.sp,
color = Color.Black,
modifier = Modifier.padding(8.dp)
)
}
item {
ProductCard("Intel Celeron G5905 OEM", 4099, R.drawable.product3)
}
item {
ProductCard("AMD Ryzen 5 4500 BOX", 9799, R.drawable.product4)
}
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)
}
}
}
}

View File

@ -0,0 +1,66 @@
import androidx.compose.foundation.BorderStroke
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.Button
import androidx.compose.material3.ButtonDefaults
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.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.rememberNavController
@Composable
fun Registration (navController: NavController){
Column(
modifier = Modifier
.fillMaxSize()
.padding(start = 10.dp, end = 10.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
){
Input("Имя")
Input("Эл.почта")
Input("Пароль")
Input("Повторите пароль")
Button(
onClick = { /*TODO*/ },
modifier = Modifier.fillMaxWidth(),
)
{
TextNice("Создать аккаунт")
}
Button(
onClick = {navController.navigate("authorization")},
modifier = Modifier.fillMaxWidth(),
border = BorderStroke(1.dp, Color.Black),
colors= ButtonDefaults.buttonColors(
containerColor= Color.White,
contentColor = Color.Gray
))
{
TextNice("Авторизация")
}
}
}
@Preview(showBackground = true)
@Composable
fun RegistrationPreview() {
// Создаем заглушку для NavController
val navController = rememberNavController()
// Выводим превью компонента
Registration(navController = navController)
}

View File

@ -0,0 +1,55 @@
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

@ -0,0 +1,48 @@
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
@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,38 @@
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Input(label: String, height: Dp = 50.dp, modifier: Modifier = Modifier.padding(5.dp)) {
Column(modifier=modifier) {
OutlinedTextField(
placeholder = {
Text(label, fontSize = 15.sp, color = Color.Black)
},
value = "",
onValueChange = {},
colors= TextFieldDefaults.outlinedTextFieldColors(
focusedBorderColor = Color.Transparent,
disabledBorderColor = Color.Transparent,
unfocusedBorderColor = Color.Transparent,
errorBorderColor = Color.Transparent
),
modifier = Modifier.border(1.dp, Color.Black, RoundedCornerShape(10.dp)).fillMaxWidth().height(height),
)
}
}

View File

@ -0,0 +1,69 @@
import android.graphics.Bitmap
import androidx.annotation.DrawableRes
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.asImageBitmap
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 com.example.myapplication.R
@Composable
fun ProductCard(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("Добавить в корзину")
}
}
}
@Preview(showBackground = true)
@Composable
fun ProductCardPreview() {
ProductCard("MSI GeForce RTX 4090 VENTUS 3X OC" ,15000, R.drawable.product1)
}

View File

@ -0,0 +1,9 @@
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.sp
@Composable
fun TextNice(text: String) {
Text(text, fontSize = 25.sp, color = Color.Black)
}

View File

@ -0,0 +1,11 @@
package com.example.myapplication.navigation;
import androidx.annotation.DrawableRes;
class NavItem(
val route : String,
val label : String,
@DrawableRes val icon : Int
) {
}

View File

@ -0,0 +1,82 @@
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import com.example.myapplication.R
import com.example.myapplication.navigation.NavItem
import com.example.myapplication.ui.theme.MyApplicationTheme
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Navbar() {
val navController = rememberNavController()
val items = listOf(
NavItem("main", "Главная", R.drawable.home),
NavItem("catalog", "Каталог", R.drawable.search),
NavItem("cart", "Корзина", R.drawable.cart),
)
Scaffold(
bottomBar = {
NavigationBar {
items.forEach{item ->
NavigationBarItem(
icon = {
Image(
painter = painterResource(item.icon),
contentDescription = null,
modifier = Modifier.size(35.dp)
)
},
label={ Text(item.label) },
onClick = {
navController.navigate(item.route)
},
selected = false,
modifier = Modifier.fillMaxSize()
)
}
}
}
) {innerPaddings ->
NavHost(
navController = navController,
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) }
}
}
}
@Preview(name="Navbar")
@Composable
fun PreviewNavbar() {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Navbar()
}
}
}