Экран создания продукта готов, теперь его надо переделать так чтобы он работал и для редактирования

This commit is contained in:
Данила Мочалов 2023-11-08 06:54:32 +04:00
parent 93978b0b42
commit d6d2ef8f52
5 changed files with 166 additions and 16 deletions

View File

@ -17,6 +17,7 @@ import com.example.shawarma.screens.cart.CartScreen
import com.example.shawarma.screens.discount.DiscountScreen import com.example.shawarma.screens.discount.DiscountScreen
import com.example.shawarma.screens.home.HomeScreen import com.example.shawarma.screens.home.HomeScreen
import com.example.shawarma.screens.orders.OrdersScreen 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.products.ProductsScreen
import com.example.shawarma.screens.registration.RegistrationScreen import com.example.shawarma.screens.registration.RegistrationScreen
import com.example.shawarma.ui.theme.MyLightYellow import com.example.shawarma.ui.theme.MyLightYellow
@ -58,7 +59,10 @@ fun MainNavBar() {
OrdersScreen() OrdersScreen()
} }
composable(ScreenPaths.products.name) { composable(ScreenPaths.products.name) {
ProductsScreen() ProductsScreen(navController)
}
composable(ScreenPaths.product.name) {
ProductScreen(navController)
} }
} }
} }

View File

@ -98,10 +98,10 @@ fun AuthorizationCard(navHostController: NavHostController) {
Button( Button(
onClick = { onClick = {
navHostController.navigate(ScreenPaths.home.name) { navHostController.navigate(ScreenPaths.home.name) {
popUpTo(ScreenPaths.home.name) { popUpTo(ScreenPaths.authorization.name) {
inclusive = true inclusive = true
} }
}}, } },
colors = ButtonDefaults.buttonColors(MyLightRed, Color.White), colors = ButtonDefaults.buttonColors(MyLightRed, Color.White),
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
modifier = Modifier modifier = Modifier

View File

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

View File

@ -34,6 +34,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex import androidx.compose.ui.zIndex
import androidx.navigation.NavHostController
import com.example.shawarma.R import com.example.shawarma.R
import com.example.shawarma.data.db.AppDatabase import com.example.shawarma.data.db.AppDatabase
import com.example.shawarma.data.models.ProductModel 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.MyMainBackground
import com.example.shawarma.ui.theme.MyOrange import com.example.shawarma.ui.theme.MyOrange
import com.example.shawarma.ui.theme.NunitoFamily import com.example.shawarma.ui.theme.NunitoFamily
import com.example.shawarma.utils.ScreenPaths
import com.example.shawarma.widgets.ShawarmaLogo2 import com.example.shawarma.widgets.ShawarmaLogo2
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
@Composable @Composable
fun ProductsScreen() { fun ProductsScreen(navHostController: NavHostController) {
Box( Box(
contentAlignment = Alignment.TopCenter contentAlignment = Alignment.TopCenter
) { ) {
ProductsList() ProductsList(navHostController)
ShawarmaLogo2() ShawarmaLogo2()
} }
} }
@ -62,7 +64,7 @@ fun ProductsScreen() {
@Composable @Composable
fun ProductsList(){ fun ProductsList(navHostController: NavHostController){
val context = LocalContext.current val context = LocalContext.current
val products = remember { mutableStateListOf<ProductModel>() } val products = remember { mutableStateListOf<ProductModel>() }
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
@ -99,7 +101,9 @@ fun ProductsList(){
), ),
border = BorderStroke(2.dp, color = MyOrange), border = BorderStroke(2.dp, color = MyOrange),
shape = RoundedCornerShape(20.dp), shape = RoundedCornerShape(20.dp),
onClick = { /*TODO*/ } onClick = {
navHostController.navigate(ScreenPaths.product.name)
}
) { ) {
Text( Text(
text = "Добавить товар", text = "Добавить товар",
@ -148,6 +152,16 @@ fun ProductItem(product: ProductModel){
fontSize = 20.sp, fontSize = 20.sp,
fontWeight = FontWeight.Bold 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(
text = product.price.toString() + " руб.", text = product.price.toString() + " руб.",
fontFamily = NunitoFamily, fontFamily = NunitoFamily,
@ -156,6 +170,8 @@ fun ProductItem(product: ProductModel){
) )
} }
}
Button( Button(
modifier = Modifier.size(60.dp), modifier = Modifier.size(60.dp),
shape = RoundedCornerShape(10.dp), shape = RoundedCornerShape(10.dp),

View File

@ -1,5 +1,5 @@
package com.example.shawarma.utils package com.example.shawarma.utils
enum class ScreenPaths { enum class ScreenPaths {
authorization, registration, home, discount, cart, orders, products authorization, registration, home, discount, cart, orders, products, product
} }