Compare commits
No commits in common. "7872460be3a3956d3839cb79a07ca2d3514cd9d6" and "761d76d4aacc07a2276fa6f678c6aab9a378202f" have entirely different histories.
7872460be3
...
761d76d4aa
@ -20,7 +20,7 @@ interface OrderDao {
|
||||
@Delete
|
||||
suspend fun delete(order: OrderModel)
|
||||
|
||||
@Query("select * from orders")
|
||||
@Query("select * from orders where orders.user_id is not null")
|
||||
fun getAll() : Flow<List<OrderWithProducts>>
|
||||
@Query("select * from orders where orders.id =:id")
|
||||
fun getById(id: Int): Flow<List<OrderWithProducts>>
|
||||
|
@ -25,9 +25,6 @@ interface ProductDao {
|
||||
@Query("select * from products where products.product_old_price is not null")
|
||||
fun getDiscounts() : Flow<List<ProductModel>>
|
||||
|
||||
@Query("select * from products")
|
||||
fun getItems() : Flow<List<ProductModel>>
|
||||
|
||||
@Query("select * from products where products.id = :id")
|
||||
fun getById(id: Int): Flow<ProductModel>
|
||||
fun getById(id: Int): ProductModel
|
||||
}
|
@ -8,19 +8,15 @@ import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import com.example.shawarma.screens.authorization.AuthorizationScreen
|
||||
import com.example.shawarma.screens.cart.CartScreen
|
||||
import com.example.shawarma.screens.discount.DiscountScreen
|
||||
import com.example.shawarma.screens.home.HomeScreen
|
||||
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.registration.RegistrationScreen
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
import com.example.shawarma.utils.ScreenPaths
|
||||
@ -60,23 +56,6 @@ fun MainNavBar() {
|
||||
composable(ScreenPaths.orders.name) {
|
||||
OrdersScreen()
|
||||
}
|
||||
composable(ScreenPaths.products.name) {
|
||||
ProductsScreen(navController)
|
||||
}
|
||||
composable(
|
||||
route = ScreenPaths.product.name + "?productId={productId}",
|
||||
arguments = listOf(
|
||||
navArgument("productId") {
|
||||
defaultValue = 0
|
||||
type = NavType.IntType
|
||||
}
|
||||
)
|
||||
|
||||
) { navBackStackEntry ->
|
||||
/* Extracting the id from the route */
|
||||
val productId = navBackStackEntry.arguments?.getInt("productId")
|
||||
ProductScreen(navController, productId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -98,10 +98,10 @@ fun AuthorizationCard(navHostController: NavHostController) {
|
||||
Button(
|
||||
onClick = {
|
||||
navHostController.navigate(ScreenPaths.home.name) {
|
||||
popUpTo(ScreenPaths.authorization.name) {
|
||||
inclusive = true
|
||||
}
|
||||
} },
|
||||
popUpTo(ScreenPaths.home.name) {
|
||||
inclusive = true
|
||||
}
|
||||
}},
|
||||
colors = ButtonDefaults.buttonColors(MyLightRed, Color.White),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
modifier = Modifier
|
||||
|
@ -36,7 +36,10 @@ import androidx.compose.ui.unit.sp
|
||||
import androidx.compose.ui.zIndex
|
||||
import com.example.shawarma.R
|
||||
import com.example.shawarma.data.db.AppDatabase
|
||||
import com.example.shawarma.data.models.DiscountProductModel
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import com.example.shawarma.data.models.getAllDiscountProducts
|
||||
import com.example.shawarma.screens.home.HomeList
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightYellow
|
||||
import com.example.shawarma.ui.theme.MyMainBackground
|
||||
@ -146,7 +149,6 @@ fun DiscountCard(product : ProductModel){
|
||||
.size(160.dp, 36.dp)
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
){
|
||||
Box(
|
||||
modifier = Modifier.padding(start = 12.dp)
|
||||
|
@ -1,155 +0,0 @@
|
||||
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.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
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.platform.LocalContext
|
||||
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.data.db.AppDatabase
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
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
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun ProductScreen(navHostController: NavHostController, productId: Int?) {
|
||||
Box(
|
||||
contentAlignment = Alignment.TopCenter
|
||||
) {
|
||||
ProductWidget(navHostController, productId)
|
||||
ShawarmaLogo2()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ProductWidget(navHostController: NavHostController, productId: Int?) {
|
||||
val title = remember { mutableStateOf(TextFieldValue(""))}
|
||||
val price = remember { mutableStateOf(TextFieldValue(""))}
|
||||
val oldPrice = remember { mutableStateOf(TextFieldValue(""))}
|
||||
|
||||
if (productId != 0 && productId != null) {
|
||||
val context = LocalContext.current
|
||||
var product = remember {
|
||||
mutableStateOf(ProductModel(id = -1, title = "", price = 0, oldPrice = null))
|
||||
}
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).productDao().getById(productId).collect { data ->
|
||||
product.value = data
|
||||
}
|
||||
}
|
||||
}
|
||||
title.value = TextFieldValue(text = product.value.title)
|
||||
price.value = TextFieldValue(text = product.value.price.toString())
|
||||
oldPrice.value = TextFieldValue(text = product.value.oldPrice.toString())
|
||||
}
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
package com.example.shawarma.screens.products
|
||||
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
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.lazy.LazyColumn
|
||||
import androidx.compose.foundation.magnifier
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Card
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
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.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
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.R
|
||||
import com.example.shawarma.data.db.AppDatabase
|
||||
import com.example.shawarma.data.models.ProductModel
|
||||
import com.example.shawarma.screens.home.HomeList
|
||||
import com.example.shawarma.screens.home.ProductCard
|
||||
import com.example.shawarma.ui.theme.MarckFamily
|
||||
import com.example.shawarma.ui.theme.MyLightRed
|
||||
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.utils.ScreenPaths
|
||||
import com.example.shawarma.widgets.ShawarmaLogo2
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
@Composable
|
||||
fun ProductsScreen(navHostController: NavHostController) {
|
||||
Box(
|
||||
contentAlignment = Alignment.TopCenter
|
||||
) {
|
||||
ProductsList(navHostController)
|
||||
ShawarmaLogo2()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Composable
|
||||
fun ProductsList(navHostController: NavHostController){
|
||||
val context = LocalContext.current
|
||||
val products = remember { mutableStateListOf<ProductModel>() }
|
||||
LaunchedEffect(Unit) {
|
||||
withContext(Dispatchers.IO) {
|
||||
AppDatabase.getInstance(context).productDao().getItems().collect { data ->
|
||||
products.clear()
|
||||
products.addAll(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
)
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.padding(top = 80.dp)
|
||||
.size(340.dp, 60.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = MyLightYellow
|
||||
),
|
||||
border = BorderStroke(2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
onClick = {
|
||||
navHostController.navigate(ScreenPaths.product.name)
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = "Добавить товар",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
LazyColumn(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.padding(top = 160.dp)
|
||||
)
|
||||
{
|
||||
items(products.size) { index ->
|
||||
ProductItem(products[index], navHostController)
|
||||
Spacer(modifier = Modifier.height(20.dp))
|
||||
if (index == products.size - 1) {
|
||||
Spacer(modifier = Modifier.height(70.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ProductItem(product: ProductModel, navHostController: NavHostController){
|
||||
Card(
|
||||
border = BorderStroke(width = 2.dp, color = MyOrange),
|
||||
shape = RoundedCornerShape(size = 20.dp),
|
||||
backgroundColor = Color.White,
|
||||
modifier = Modifier.size(340.dp, 100.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(20.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.SpaceAround
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(0.5f)
|
||||
) {
|
||||
Text(
|
||||
text = product.title,
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
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 = product.price.toString() + " руб.",
|
||||
fontFamily = NunitoFamily,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier.size(60.dp),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = MyLightYellow
|
||||
),
|
||||
onClick = {
|
||||
navHostController.navigate(
|
||||
route = ScreenPaths.product.name + "?productId=" + product.id.toString()
|
||||
)
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.pen_icon),
|
||||
contentDescription = "pen",
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
Button(
|
||||
modifier = Modifier.size(60.dp),
|
||||
shape = RoundedCornerShape(10.dp),
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = MyLightRed
|
||||
),
|
||||
onClick = { /*TODO*/ }
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.trash),
|
||||
contentDescription = "trash",
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,4 @@ sealed class BottomNavItem(var title:String, var icon:Int, var screen_route:Stri
|
||||
object Discount : BottomNavItem("Discount", R.drawable.discount_icon,ScreenPaths.discount.name)
|
||||
object Cart : BottomNavItem("Cart", R.drawable.cart_icon,ScreenPaths.cart.name)
|
||||
object Orders: BottomNavItem("Orders", R.drawable.orders_icon,ScreenPaths.orders.name)
|
||||
object Products: BottomNavItem("Products", R.drawable.pen_icon, ScreenPaths.products.name)
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
package com.example.shawarma.utils
|
||||
|
||||
enum class ScreenPaths {
|
||||
authorization, registration, home, discount, cart, orders, products, product
|
||||
authorization, registration, home, discount, cart, orders
|
||||
}
|
@ -23,8 +23,7 @@ fun BottomNavBar(navController: NavController) {
|
||||
BottomNavItem.Discount,
|
||||
BottomNavItem.Home,
|
||||
BottomNavItem.Cart,
|
||||
BottomNavItem.Orders,
|
||||
BottomNavItem.Products
|
||||
BottomNavItem.Orders
|
||||
)
|
||||
BottomNavigation(
|
||||
backgroundColor = Color.White,
|
||||
|
@ -32,7 +32,7 @@ fun MyTextField(
|
||||
placeholder = {
|
||||
Text(
|
||||
text = placeholder,
|
||||
fontSize = 16.sp,
|
||||
fontSize = 14.sp,
|
||||
style = TextStyle(
|
||||
fontFamily = JejuFamily
|
||||
)
|
||||
@ -41,7 +41,7 @@ fun MyTextField(
|
||||
singleLine = singleLine,
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
textStyle = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
fontSize = 14.sp,
|
||||
fontFamily = JejuFamily
|
||||
),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 6.9 KiB |
Loading…
Reference in New Issue
Block a user