Лаб 3: готова и сдана, забыл закоммитить
This commit is contained in:
parent
270e1fdcf8
commit
442d1202b2
@ -34,11 +34,11 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_1_8
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
kotlinOptions {
|
||||||
jvmTarget = "1.8"
|
jvmTarget = "17"
|
||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
compose = true
|
compose = true
|
||||||
|
@ -3,7 +3,21 @@ package com.example.mobileapp
|
|||||||
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
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import com.example.mobileapp.db.AppDatabase
|
||||||
|
import com.example.mobileapp.models.Category
|
||||||
|
import com.example.mobileapp.models.OrderWithProducts
|
||||||
|
import com.example.mobileapp.models.Product
|
||||||
|
import com.example.mobileapp.models.Role
|
||||||
|
import com.example.mobileapp.models.Status
|
||||||
|
import com.example.mobileapp.models.User
|
||||||
import com.example.mobileapp.navigation.AppNavigation
|
import com.example.mobileapp.navigation.AppNavigation
|
||||||
|
import com.example.mobileapp.navigation.listOfAdminNavItems
|
||||||
|
import com.example.mobileapp.navigation.listOfUserNavItems
|
||||||
|
import com.example.mobileapp.navigation.listOfWorkerNavItems
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -20,5 +20,5 @@ interface CategoryDao {
|
|||||||
fun getByName(name: String) : Flow<CategoryWithProducts>
|
fun getByName(name: String) : Flow<CategoryWithProducts>
|
||||||
|
|
||||||
@Query("select * from category")
|
@Query("select * from category")
|
||||||
fun getCatgoryWithProducts() : Flow<List<CategoryWithProducts>>
|
fun getCategoryWithProducts() : Flow<List<CategoryWithProducts>>
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,16 @@ interface OrderDao {
|
|||||||
@Delete
|
@Delete
|
||||||
suspend fun delete(order: Order)
|
suspend fun delete(order: Order)
|
||||||
|
|
||||||
@Query("select * from 'order'")
|
@Query("select * from `order`")
|
||||||
fun getAll() : Flow<List<OrderWithProducts>>
|
fun getAll() : Flow<List<OrderWithProducts>>
|
||||||
@Query("select * from 'order' where 'order.id' =:id")
|
@Query("select * from `order` where `order`.`user_id` =:id")
|
||||||
fun getById(id: Int): Flow<List<OrderWithProducts>>
|
fun getById(id: Int): Flow<List<OrderWithProducts>>
|
||||||
@Query("select * from 'order' where ('order.user_id' =:userId and 'order.status_id' != 1 and 'order.status_id' != 4)")
|
@Query("select * from `order` where `order`.`user_id` =:userId and `order`.`status_id` != 1 and `order`.`status_id` != 4")
|
||||||
fun getByUserId(userId: Int): Flow<List<OrderWithProducts>>
|
fun getByUserId(userId: Int): Flow<List<OrderWithProducts>>
|
||||||
|
|
||||||
@Query("select * from 'order' where ('order.user_id' =:userId and 'order.status_id' = 1)")
|
@Query("select * from `order` where `order`.`user_id` =:userId and `order`.`status_id` = 1")
|
||||||
fun getCartByUserId(userId: Int): Flow<OrderWithProducts>
|
fun getCartByUserId(userId: Int): Flow<OrderWithProducts>
|
||||||
|
|
||||||
@Query("select * from 'order' where ('order.status_id' != 1 and 'order.status_id' != 4)")
|
@Query("select * from `order` where `order`.`status_id` != 1 and `order`.`status_id` != 4")
|
||||||
fun getOrdersToWork(): Flow<List<OrderWithProducts>>
|
fun getOrdersToWork(): Flow<List<OrderWithProducts>>
|
||||||
}
|
}
|
@ -4,7 +4,9 @@ import androidx.room.*
|
|||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import com.example.mobileapp.dao.*
|
import com.example.mobileapp.dao.*
|
||||||
import com.example.mobileapp.models.*
|
import com.example.mobileapp.models.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities =
|
entities =
|
||||||
@ -38,36 +40,32 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
private suspend fun populateDatabase() {
|
private suspend fun populateDatabase() {
|
||||||
INSTANCE?.let { database ->
|
INSTANCE?.let { database ->
|
||||||
|
|
||||||
//region Roles
|
//Roles
|
||||||
val roleDao = database.roleDao()
|
val roleDao = database.roleDao()
|
||||||
roleDao.insert(Role(1, "admin"))
|
roleDao.insert(Role(1, "admin"))
|
||||||
roleDao.insert(Role(2, "worker"))
|
roleDao.insert(Role(2, "worker"))
|
||||||
roleDao.insert(Role(3, "user"))
|
roleDao.insert(Role(3, "user"))
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Statuses
|
//Statuses
|
||||||
val statusDao = database.statusDao()
|
val statusDao = database.statusDao()
|
||||||
statusDao.insert(Status(1, "Корзина"))
|
statusDao.insert(Status(1, "Корзина"))
|
||||||
statusDao.insert(Status(2, "Принят"))
|
statusDao.insert(Status(2, "Принят"))
|
||||||
statusDao.insert(Status(3, "Готов"))
|
statusDao.insert(Status(3, "Готов"))
|
||||||
statusDao.insert(Status(4, "Выдан"))
|
statusDao.insert(Status(4, "Выдан"))
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Categories
|
//Categories
|
||||||
val categoryDao = database.categoryDao()
|
val categoryDao = database.categoryDao()
|
||||||
categoryDao.insert(Category(1, "Бургеры"))
|
categoryDao.insert(Category(1, "Бургеры"))
|
||||||
categoryDao.insert(Category(2, "Картошка"))
|
categoryDao.insert(Category(2, "Картошка"))
|
||||||
categoryDao.insert(Category(3, "Напитки"))
|
categoryDao.insert(Category(3, "Напитки"))
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Users
|
//Users
|
||||||
val userDao = database.userDao()
|
val userDao = database.userDao()
|
||||||
userDao.insert(User(1, "admin", "admin", 1))
|
userDao.insert(User(1, "admin", "admin", 1))
|
||||||
userDao.insert(User(2, "worker", "worker", 2))
|
userDao.insert(User(2, "worker", "worker", 2))
|
||||||
userDao.insert(User(3, "user", "user", 3))
|
userDao.insert(User(3, "user", "user", 3))
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Products
|
//Products
|
||||||
val productDao = database.productDao()
|
val productDao = database.productDao()
|
||||||
//Бургеры
|
//Бургеры
|
||||||
productDao.insert(Product(1, "Бургер1", 1, 150))
|
productDao.insert(Product(1, "Бургер1", 1, 150))
|
||||||
@ -81,67 +79,36 @@ abstract class AppDatabase : RoomDatabase() {
|
|||||||
productDao.insert(Product(7, "Напиток1", 3, 100))
|
productDao.insert(Product(7, "Напиток1", 3, 100))
|
||||||
productDao.insert(Product(8, "Напиток2", 3, 200))
|
productDao.insert(Product(8, "Напиток2", 3, 200))
|
||||||
productDao.insert(Product(9, "Напиток3", 3, 300))
|
productDao.insert(Product(9, "Напиток3", 3, 300))
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Orders
|
//Orders
|
||||||
val orderDao = database.orderDao()
|
val orderDao = database.orderDao()
|
||||||
//Корзины
|
//Корзины
|
||||||
orderDao.insert(Order(1,1,400,1))
|
orderDao.insert(Order(1,1,400,1))
|
||||||
orderDao.insert(Order(2,2,600,1))
|
|
||||||
orderDao.insert(Order(3,3,1800,1))
|
|
||||||
//Заказы
|
//Заказы
|
||||||
orderDao.insert(Order(4,1,250,3))
|
orderDao.insert(Order(2,1,250,3))
|
||||||
orderDao.insert(Order(5,1,400,2))
|
orderDao.insert(Order(3,1,400,2))
|
||||||
orderDao.insert(Order(6,2,750,3))
|
|
||||||
orderDao.insert(Order(7,2,550,2))
|
|
||||||
orderDao.insert(Order(8,3,400,3))
|
|
||||||
orderDao.insert(Order(9,3,250,2))
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region OrderProducts
|
//region OrderProducts
|
||||||
val orderProductDao = database.orderProductDao()
|
val orderProductDao = database.orderProductDao()
|
||||||
//Корзины
|
//Корзины
|
||||||
//1
|
|
||||||
orderProductDao.insert(OrderProduct(1,1,2))
|
orderProductDao.insert(OrderProduct(1,1,2))
|
||||||
orderProductDao.insert(OrderProduct(1,7,1))
|
orderProductDao.insert(OrderProduct(1,7,1))
|
||||||
//2
|
|
||||||
orderProductDao.insert(OrderProduct(2,2,1))
|
|
||||||
orderProductDao.insert(OrderProduct(2,5,1))
|
|
||||||
orderProductDao.insert(OrderProduct(2,8,1))
|
|
||||||
//3
|
|
||||||
orderProductDao.insert(OrderProduct(3,3,2))
|
|
||||||
orderProductDao.insert(OrderProduct(3,6,2))
|
|
||||||
orderProductDao.insert(OrderProduct(3,9,2))
|
|
||||||
//Заказы
|
//Заказы
|
||||||
//1
|
orderProductDao.insert(OrderProduct(2,1,1))
|
||||||
orderProductDao.insert(OrderProduct(4,1,1))
|
orderProductDao.insert(OrderProduct(2,7,1))
|
||||||
orderProductDao.insert(OrderProduct(4,7,1))
|
orderProductDao.insert(OrderProduct(3,2,1))
|
||||||
//2
|
orderProductDao.insert(OrderProduct(3,5,1))
|
||||||
orderProductDao.insert(OrderProduct(5,2,1))
|
|
||||||
orderProductDao.insert(OrderProduct(5,5,1))
|
|
||||||
//3
|
|
||||||
orderProductDao.insert(OrderProduct(6,2,1))
|
|
||||||
orderProductDao.insert(OrderProduct(6,3,1))
|
|
||||||
//4
|
|
||||||
orderProductDao.insert(OrderProduct(7,3,1))
|
|
||||||
orderProductDao.insert(OrderProduct(7,7,1))
|
|
||||||
//5
|
|
||||||
orderProductDao.insert(OrderProduct(8,2,1))
|
|
||||||
orderProductDao.insert(OrderProduct(8,7,1))
|
|
||||||
//6
|
|
||||||
orderProductDao.insert(OrderProduct(9,4,1))
|
|
||||||
orderProductDao.insert(OrderProduct(9,8,1))
|
|
||||||
//endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getInstance(appContext: Context): AppDatabase {
|
fun getInstance(appContext: Context): AppDatabase {
|
||||||
return INSTANCE ?: synchronized(this) {
|
return INSTANCE ?: synchronized(this) {
|
||||||
Room.databaseBuilder(
|
Room
|
||||||
appContext,
|
.databaseBuilder(
|
||||||
AppDatabase::class.java,
|
appContext,
|
||||||
DB_NAME
|
AppDatabase::class.java,
|
||||||
)
|
DB_NAME
|
||||||
|
)
|
||||||
.addCallback(object : Callback() {
|
.addCallback(object : Callback() {
|
||||||
override fun onCreate(db: SupportSQLiteDatabase) {
|
override fun onCreate(db: SupportSQLiteDatabase) {
|
||||||
super.onCreate(db)
|
super.onCreate(db)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.mobileapp.navigation
|
package com.example.mobileapp.navigation
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@ -15,8 +16,10 @@ import androidx.compose.material3.Scaffold
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@ -42,6 +45,7 @@ import com.example.mobileapp.screens.RegistrationScreen
|
|||||||
import com.example.mobileapp.screens.UsersScreen
|
import com.example.mobileapp.screens.UsersScreen
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.collect
|
import kotlinx.coroutines.flow.collect
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@ -82,34 +86,41 @@ fun AppNavigation(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CoroutineCreationDuringComposition")
|
||||||
@Composable
|
@Composable
|
||||||
fun CustomNavigationBar(navController: NavController) {
|
fun CustomNavigationBar(navController: NavController) {
|
||||||
|
val user = remember { mutableStateOf(User(-1, "", "", -1)) }
|
||||||
|
val context = LocalContext.current
|
||||||
|
val listOfNavItems = remember { mutableStateListOf<NavItem>() }
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
user.value = (AppDatabase.getInstance(context).userDao().getById(1))
|
||||||
|
|
||||||
|
(AppDatabase.getInstance(context).roleDao().getById(user.value.roleId)).collect{data ->
|
||||||
|
when (data.name) {
|
||||||
|
"admin" -> {
|
||||||
|
listOfNavItems.clear()
|
||||||
|
listOfNavItems.addAll(listOfAdminNavItems)
|
||||||
|
}
|
||||||
|
"worker" -> {
|
||||||
|
listOfNavItems.clear()
|
||||||
|
listOfNavItems.addAll(listOfWorkerNavItems)
|
||||||
|
}
|
||||||
|
"user" -> {
|
||||||
|
listOfNavItems.clear()
|
||||||
|
listOfNavItems.addAll(listOfUserNavItems)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.fillMaxHeight(0.1f)
|
.fillMaxHeight(0.1f)
|
||||||
.background(Color(212, 206, 203))
|
.background(Color(212, 206, 203))
|
||||||
) {
|
) {
|
||||||
var listOfNavItems : List<NavItem>? = null
|
listOfNavItems.forEachIndexed { index, navItem ->
|
||||||
val user = remember { mutableStateOf(User(-1, "", "", -1)) }
|
|
||||||
val context = LocalContext.current
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
user.value = AppDatabase.getInstance(context).userDao().getById(1)
|
|
||||||
(AppDatabase.getInstance(context).roleDao().getByName("admin")).collect{
|
|
||||||
if (it.id == user.value.roleId) { listOfNavItems = listOfAdminNavItems }
|
|
||||||
}
|
|
||||||
(AppDatabase.getInstance(context).roleDao().getByName("worker")).collect{
|
|
||||||
if (it.id == user.value.roleId) { listOfNavItems = listOfWorkerNavItems }
|
|
||||||
}
|
|
||||||
(AppDatabase.getInstance(context).roleDao().getByName("user")).collect{
|
|
||||||
if (it.id == user.value.roleId) { listOfNavItems = listOfUserNavItems }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
listOfNavItems?.forEachIndexed { index, navItem ->
|
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
@ -123,11 +134,11 @@ fun CustomNavigationBar(navController: NavController) {
|
|||||||
border = BorderStroke(4.dp, Color(222,161,69)),
|
border = BorderStroke(4.dp, Color(222,161,69)),
|
||||||
shape = RoundedCornerShape(
|
shape = RoundedCornerShape(
|
||||||
topStart = if (index == 0) 30.dp else 0.dp,
|
topStart = if (index == 0) 30.dp else 0.dp,
|
||||||
topEnd = if (index == listOfNavItems!!.size - 1) 30.dp else 0.dp
|
topEnd = if (index == listOfNavItems.size - 1) 30.dp else 0.dp
|
||||||
),
|
),
|
||||||
colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)),
|
colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)),
|
||||||
|
|
||||||
){
|
){
|
||||||
Icon(
|
Icon(
|
||||||
painterResource(id = navItem.icon),
|
painterResource(id = navItem.icon),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
|
@ -122,7 +122,7 @@ fun CartCard(){
|
|||||||
category.value = data.name
|
category.value = data.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (category.value == "Бургер"){
|
if (category.value == "Бургеры"){
|
||||||
Image(
|
Image(
|
||||||
painterResource(
|
painterResource(
|
||||||
id = R.drawable.burger
|
id = R.drawable.burger
|
||||||
|
@ -84,20 +84,8 @@ fun CreateProductCard(){
|
|||||||
.padding(top = 10.dp),
|
.padding(top = 10.dp),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
val categoryList = remember { mutableStateListOf<String>() }
|
|
||||||
var expanded by remember { mutableStateOf(false) }
|
|
||||||
val title = remember { mutableStateOf(TextFieldValue("")) }
|
val title = remember { mutableStateOf(TextFieldValue("")) }
|
||||||
val price = remember { mutableStateOf(TextFieldValue("")) }
|
val price = remember { mutableStateOf(TextFieldValue("")) }
|
||||||
val context = LocalContext.current
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
AppDatabase.getInstance(context).categoryDao().getAll().collect { data ->
|
|
||||||
categoryList.clear()
|
|
||||||
categoryList.addAll(data.map { it.name })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var selectedCategory by remember { mutableStateOf(categoryList[0]) }
|
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
shape = RoundedCornerShape(20.dp),
|
shape = RoundedCornerShape(20.dp),
|
||||||
@ -139,6 +127,19 @@ fun CreateProductCard(){
|
|||||||
onSurface = Color.Gray
|
onSurface = Color.Gray
|
||||||
)
|
)
|
||||||
){
|
){
|
||||||
|
val categoryList = remember { mutableStateListOf<String>() }
|
||||||
|
var selectedCategory by remember { mutableStateOf("") }
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
val context = LocalContext.current
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
AppDatabase.getInstance(context).categoryDao().getAll().collect { data ->
|
||||||
|
categoryList.clear()
|
||||||
|
categoryList.addAll(data.map { category -> category.name })
|
||||||
|
selectedCategory = data.first().name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onExpandedChange = {
|
onExpandedChange = {
|
||||||
|
@ -21,6 +21,7 @@ import androidx.compose.material3.OutlinedButton
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@ -70,13 +71,13 @@ fun EditMenuCard(navController: NavController){
|
|||||||
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
val categoryWithProducts = remember { mutableListOf<CategoryWithProducts>()}
|
val categoryWithProducts = remember { mutableStateListOf<CategoryWithProducts>() }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
AppDatabase.getInstance(context).categoryDao().getCatgoryWithProducts().collect { data ->
|
AppDatabase.getInstance(context).categoryDao().getCategoryWithProducts().collect { data ->
|
||||||
categoryWithProducts.addAll(data)
|
categoryWithProducts.addAll(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.mobileapp.screens
|
package com.example.mobileapp.screens
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@ -27,6 +28,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@ -43,6 +45,7 @@ import com.example.mobileapp.R
|
|||||||
import com.example.mobileapp.db.AppDatabase
|
import com.example.mobileapp.db.AppDatabase
|
||||||
import com.example.mobileapp.widgets.Header
|
import com.example.mobileapp.widgets.Header
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -56,6 +59,7 @@ fun EditProductScreen(id: Int){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("CoroutineCreationDuringComposition")
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun EditProductCard(id: Int){
|
fun EditProductCard(id: Int){
|
||||||
@ -85,11 +89,12 @@ fun EditProductCard(id: Int){
|
|||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val categoryList = remember { mutableStateListOf<String>() }
|
|
||||||
var selectedCategory by remember { mutableStateOf("") }
|
var selectedCategory by remember { mutableStateOf("") }
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
val title = remember { mutableStateOf(TextFieldValue("")) }
|
val title = remember { mutableStateOf(TextFieldValue("")) }
|
||||||
val price = remember { mutableStateOf(TextFieldValue("")) }
|
val price = remember { mutableStateOf(TextFieldValue("")) }
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
AppDatabase.getInstance(context).productDao().getById(id).collect {data ->
|
AppDatabase.getInstance(context).productDao().getById(id).collect {data ->
|
||||||
@ -100,10 +105,6 @@ fun EditProductCard(id: Int){
|
|||||||
selectedCategory = it.name
|
selectedCategory = it.name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AppDatabase.getInstance(context).categoryDao().getAll().collect { data ->
|
|
||||||
categoryList.clear()
|
|
||||||
categoryList.addAll(data.map { it.name })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Card(
|
Card(
|
||||||
@ -139,6 +140,7 @@ fun EditProductCard(id: Int){
|
|||||||
border = BorderStroke(1.dp, Color(222,161,69)),
|
border = BorderStroke(1.dp, Color(222,161,69)),
|
||||||
modifier = Modifier.fillMaxWidth().padding(top = 20.dp, start = 20.dp, end = 20.dp),
|
modifier = Modifier.fillMaxWidth().padding(top = 20.dp, start = 20.dp, end = 20.dp),
|
||||||
){
|
){
|
||||||
|
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = lightColorScheme(
|
colorScheme = lightColorScheme(
|
||||||
surfaceVariant= Color.White,
|
surfaceVariant= Color.White,
|
||||||
@ -146,6 +148,13 @@ fun EditProductCard(id: Int){
|
|||||||
onSurface = Color.Gray
|
onSurface = Color.Gray
|
||||||
)
|
)
|
||||||
){
|
){
|
||||||
|
val categoryList = remember { mutableStateListOf<String>() }
|
||||||
|
scope.launch {
|
||||||
|
AppDatabase.getInstance(context).categoryDao().getAll().collect { data ->
|
||||||
|
categoryList.clear()
|
||||||
|
categoryList.addAll(data.map { category -> category.name })
|
||||||
|
}
|
||||||
|
}
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onExpandedChange = {
|
onExpandedChange = {
|
||||||
|
@ -20,6 +20,7 @@ import androidx.compose.material3.OutlinedButton
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
@ -69,20 +70,17 @@ fun MenuCard(){
|
|||||||
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
val categoryWithProducts = remember { mutableListOf<CategoryWithProducts>()}
|
val categoryWithProducts = remember { mutableStateListOf<CategoryWithProducts>()}
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
AppDatabase.getInstance(context).categoryDao().getCatgoryWithProducts().collect { data ->
|
(AppDatabase.getInstance(context).categoryDao().getCategoryWithProducts()).collect { data ->
|
||||||
categoryWithProducts.addAll(data)
|
categoryWithProducts.addAll(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
|
@ -19,6 +19,7 @@ import androidx.compose.material3.OutlinedButton
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
@ -80,7 +81,7 @@ fun OrderCard(){
|
|||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
|
|
||||||
val ordersWithProducts = remember { mutableListOf<OrderWithProducts> () }
|
val ordersWithProducts = remember { mutableStateListOf<OrderWithProducts> () }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ fun OrderCard(){
|
|||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "Статус: " + status,
|
text = "Статус: " + status.value,
|
||||||
color = Color.Black,
|
color = Color.Black,
|
||||||
fontFamily = FontFamily(Font(R.font.nunito_extrabold_italic)),
|
fontFamily = FontFamily(Font(R.font.nunito_extrabold_italic)),
|
||||||
fontSize = 20.sp,
|
fontSize = 20.sp,
|
||||||
@ -166,6 +167,7 @@ fun OrderCard(){
|
|||||||
border = BorderStroke(4.dp, Color(222,161,69)),
|
border = BorderStroke(4.dp, Color(222,161,69)),
|
||||||
shape = RoundedCornerShape(20.dp),
|
shape = RoundedCornerShape(20.dp),
|
||||||
colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)),
|
colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)),
|
||||||
|
modifier = Modifier.padding(bottom = 10.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "Готов",
|
text = "Готов",
|
||||||
@ -183,6 +185,7 @@ fun OrderCard(){
|
|||||||
border = BorderStroke(4.dp, Color(222,161,69)),
|
border = BorderStroke(4.dp, Color(222,161,69)),
|
||||||
shape = RoundedCornerShape(20.dp),
|
shape = RoundedCornerShape(20.dp),
|
||||||
colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)),
|
colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)),
|
||||||
|
modifier = Modifier.padding(bottom = 10.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "Выдать",
|
text = "Выдать",
|
||||||
|
@ -19,6 +19,7 @@ import androidx.compose.material3.OutlinedButton
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
@ -103,13 +104,14 @@ fun ProfileCard(navController: NavController){
|
|||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
|
|
||||||
val ordersWithProducts = remember { mutableListOf<OrderWithProducts> () }
|
val ordersWithProducts = remember { mutableStateListOf<OrderWithProducts> () }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
AppDatabase.getInstance(context).orderDao().getByUserId(1).collect { data ->
|
AppDatabase.getInstance(context).orderDao().getByUserId(1).collect { data ->
|
||||||
|
ordersWithProducts.clear()
|
||||||
ordersWithProducts.addAll(data)
|
ordersWithProducts.addAll(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ fun UsersCard(){
|
|||||||
.padding(top = 10.dp),
|
.padding(top = 10.dp),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
val users = remember { mutableListOf<User> () }
|
val users = remember { mutableStateListOf<User> () }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
@ -152,8 +152,11 @@ fun UsersCard(){
|
|||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
AppDatabase.getInstance(context).roleDao().getAll().collect { data ->
|
AppDatabase.getInstance(context).roleDao().getAll().collect { data ->
|
||||||
roleList.addAll(data.map {it.name})
|
roleList.clear()
|
||||||
|
roleList.addAll(data.map {role -> role.name})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
scope.launch {
|
||||||
AppDatabase.getInstance(context).roleDao().getById(user.roleId).collect { data ->
|
AppDatabase.getInstance(context).roleDao().getById(user.roleId).collect { data ->
|
||||||
selectedRole = data.name
|
selectedRole = data.name
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user