From 442d1202b2bfe8925521cfeb39475724541d3b9c Mon Sep 17 00:00:00 2001 From: Safgerd Date: Tue, 19 Dec 2023 21:34:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=203:=20=D0=B3=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=20=D0=B8=20=D1=81=D0=B4=D0=B0=D0=BD=D0=B0,?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B1=D1=8B=D0=BB=20=D0=B7=D0=B0=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B8=D1=82=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 6 +- .../com/example/mobileapp/MainActivity.kt | 14 ++++ .../com/example/mobileapp/dao/CategoryDao.kt | 2 +- .../com/example/mobileapp/dao/OrderDao.kt | 10 +-- .../com/example/mobileapp/db/AppDatabase.kt | 75 ++++++------------- .../mobileapp/navigation/AppNavigation.kt | 55 ++++++++------ .../example/mobileapp/screens/CartScreen.kt | 2 +- .../mobileapp/screens/CreateProductScreen.kt | 25 ++++--- .../mobileapp/screens/EditMenuScreen.kt | 5 +- .../mobileapp/screens/EditProductScreen.kt | 19 +++-- .../example/mobileapp/screens/MenuScreen.kt | 8 +- .../example/mobileapp/screens/OrderScreen.kt | 7 +- .../mobileapp/screens/ProfileScreen.kt | 4 +- .../example/mobileapp/screens/UsersScreen.kt | 7 +- 14 files changed, 124 insertions(+), 115 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d183c2f..8c72749 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -34,11 +34,11 @@ android { } } compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 } kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" } buildFeatures { compose = true diff --git a/app/src/main/java/com/example/mobileapp/MainActivity.kt b/app/src/main/java/com/example/mobileapp/MainActivity.kt index 3643abc..fd1d77c 100644 --- a/app/src/main/java/com/example/mobileapp/MainActivity.kt +++ b/app/src/main/java/com/example/mobileapp/MainActivity.kt @@ -3,7 +3,21 @@ package com.example.mobileapp import android.os.Bundle import androidx.activity.ComponentActivity 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.listOfAdminNavItems +import com.example.mobileapp.navigation.listOfUserNavItems +import com.example.mobileapp.navigation.listOfWorkerNavItems +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/com/example/mobileapp/dao/CategoryDao.kt b/app/src/main/java/com/example/mobileapp/dao/CategoryDao.kt index 151034d..aea20b2 100644 --- a/app/src/main/java/com/example/mobileapp/dao/CategoryDao.kt +++ b/app/src/main/java/com/example/mobileapp/dao/CategoryDao.kt @@ -20,5 +20,5 @@ interface CategoryDao { fun getByName(name: String) : Flow @Query("select * from category") - fun getCatgoryWithProducts() : Flow> + fun getCategoryWithProducts() : Flow> } diff --git a/app/src/main/java/com/example/mobileapp/dao/OrderDao.kt b/app/src/main/java/com/example/mobileapp/dao/OrderDao.kt index ee4b7b0..e395188 100644 --- a/app/src/main/java/com/example/mobileapp/dao/OrderDao.kt +++ b/app/src/main/java/com/example/mobileapp/dao/OrderDao.kt @@ -12,16 +12,16 @@ interface OrderDao { @Delete suspend fun delete(order: Order) - @Query("select * from 'order'") + @Query("select * from `order`") fun getAll() : Flow> - @Query("select * from 'order' where 'order.id' =:id") + @Query("select * from `order` where `order`.`user_id` =:id") fun getById(id: Int): Flow> - @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> - @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 - @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> } \ No newline at end of file diff --git a/app/src/main/java/com/example/mobileapp/db/AppDatabase.kt b/app/src/main/java/com/example/mobileapp/db/AppDatabase.kt index 7d18fcc..f82d1b0 100644 --- a/app/src/main/java/com/example/mobileapp/db/AppDatabase.kt +++ b/app/src/main/java/com/example/mobileapp/db/AppDatabase.kt @@ -4,7 +4,9 @@ import androidx.room.* import androidx.sqlite.db.SupportSQLiteDatabase import com.example.mobileapp.dao.* import com.example.mobileapp.models.* -import kotlinx.coroutines.* +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch @Database( entities = @@ -38,36 +40,32 @@ abstract class AppDatabase : RoomDatabase() { private suspend fun populateDatabase() { INSTANCE?.let { database -> - //region Roles + //Roles val roleDao = database.roleDao() roleDao.insert(Role(1, "admin")) roleDao.insert(Role(2, "worker")) roleDao.insert(Role(3, "user")) - //endregion - //region Statuses + //Statuses val statusDao = database.statusDao() statusDao.insert(Status(1, "Корзина")) statusDao.insert(Status(2, "Принят")) statusDao.insert(Status(3, "Готов")) statusDao.insert(Status(4, "Выдан")) - //endregion - //region Categories + //Categories val categoryDao = database.categoryDao() categoryDao.insert(Category(1, "Бургеры")) categoryDao.insert(Category(2, "Картошка")) categoryDao.insert(Category(3, "Напитки")) - //endregion - //region Users + //Users val userDao = database.userDao() userDao.insert(User(1, "admin", "admin", 1)) userDao.insert(User(2, "worker", "worker", 2)) userDao.insert(User(3, "user", "user", 3)) - //endregion - //region Products + //Products val productDao = database.productDao() //Бургеры 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(8, "Напиток2", 3, 200)) productDao.insert(Product(9, "Напиток3", 3, 300)) - //endregion - //region Orders + //Orders val orderDao = database.orderDao() //Корзины 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(5,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 + orderDao.insert(Order(2,1,250,3)) + orderDao.insert(Order(3,1,400,2)) //region OrderProducts val orderProductDao = database.orderProductDao() //Корзины - //1 orderProductDao.insert(OrderProduct(1,1,2)) 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(4,1,1)) - orderProductDao.insert(OrderProduct(4,7,1)) - //2 - 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 + orderProductDao.insert(OrderProduct(2,1,1)) + orderProductDao.insert(OrderProduct(2,7,1)) + orderProductDao.insert(OrderProduct(3,2,1)) + orderProductDao.insert(OrderProduct(3,5,1)) } } fun getInstance(appContext: Context): AppDatabase { return INSTANCE ?: synchronized(this) { - Room.databaseBuilder( - appContext, - AppDatabase::class.java, - DB_NAME - ) + Room + .databaseBuilder( + appContext, + AppDatabase::class.java, + DB_NAME + ) .addCallback(object : Callback() { override fun onCreate(db: SupportSQLiteDatabase) { super.onCreate(db) diff --git a/app/src/main/java/com/example/mobileapp/navigation/AppNavigation.kt b/app/src/main/java/com/example/mobileapp/navigation/AppNavigation.kt index fdcb171..24fa5d2 100644 --- a/app/src/main/java/com/example/mobileapp/navigation/AppNavigation.kt +++ b/app/src/main/java/com/example/mobileapp/navigation/AppNavigation.kt @@ -1,5 +1,6 @@ package com.example.mobileapp.navigation +import android.annotation.SuppressLint import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.layout.Row @@ -15,8 +16,10 @@ import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext @@ -42,6 +45,7 @@ import com.example.mobileapp.screens.RegistrationScreen import com.example.mobileapp.screens.UsersScreen import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @OptIn(ExperimentalMaterial3Api::class) @@ -82,34 +86,41 @@ fun AppNavigation(){ } } +@SuppressLint("CoroutineCreationDuringComposition") @Composable fun CustomNavigationBar(navController: NavController) { + val user = remember { mutableStateOf(User(-1, "", "", -1)) } + val context = LocalContext.current + val listOfNavItems = remember { mutableStateListOf() } + 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( modifier = Modifier .fillMaxWidth() .fillMaxHeight(0.1f) .background(Color(212, 206, 203)) ) { - var listOfNavItems : List? = null - 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 -> + listOfNavItems.forEachIndexed { index, navItem -> OutlinedButton( modifier = Modifier .fillMaxHeight() @@ -123,11 +134,11 @@ fun CustomNavigationBar(navController: NavController) { border = BorderStroke(4.dp, Color(222,161,69)), shape = RoundedCornerShape( 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)), - ){ + ){ Icon( painterResource(id = navItem.icon), contentDescription = null, diff --git a/app/src/main/java/com/example/mobileapp/screens/CartScreen.kt b/app/src/main/java/com/example/mobileapp/screens/CartScreen.kt index 107c7cc..627f971 100644 --- a/app/src/main/java/com/example/mobileapp/screens/CartScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/CartScreen.kt @@ -122,7 +122,7 @@ fun CartCard(){ category.value = data.name } } - if (category.value == "Бургер"){ + if (category.value == "Бургеры"){ Image( painterResource( id = R.drawable.burger diff --git a/app/src/main/java/com/example/mobileapp/screens/CreateProductScreen.kt b/app/src/main/java/com/example/mobileapp/screens/CreateProductScreen.kt index 24af1e0..d01a366 100644 --- a/app/src/main/java/com/example/mobileapp/screens/CreateProductScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/CreateProductScreen.kt @@ -84,20 +84,8 @@ fun CreateProductCard(){ .padding(top = 10.dp), textAlign = TextAlign.Center, ) - val categoryList = remember { mutableStateListOf() } - var expanded by remember { mutableStateOf(false) } val title = 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( shape = RoundedCornerShape(20.dp), @@ -139,6 +127,19 @@ fun CreateProductCard(){ onSurface = Color.Gray ) ){ + val categoryList = remember { mutableStateListOf() } + 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( expanded = expanded, onExpandedChange = { diff --git a/app/src/main/java/com/example/mobileapp/screens/EditMenuScreen.kt b/app/src/main/java/com/example/mobileapp/screens/EditMenuScreen.kt index cfb8d84..a1a443a 100644 --- a/app/src/main/java/com/example/mobileapp/screens/EditMenuScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/EditMenuScreen.kt @@ -21,6 +21,7 @@ import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Alignment @@ -70,13 +71,13 @@ fun EditMenuCard(navController: NavController){ horizontalAlignment = Alignment.CenterHorizontally, ) { - val categoryWithProducts = remember { mutableListOf()} + val categoryWithProducts = remember { mutableStateListOf() } val context = LocalContext.current val scope = rememberCoroutineScope() LaunchedEffect(Unit) { withContext(Dispatchers.IO) { - AppDatabase.getInstance(context).categoryDao().getCatgoryWithProducts().collect { data -> + AppDatabase.getInstance(context).categoryDao().getCategoryWithProducts().collect { data -> categoryWithProducts.addAll(data) } } diff --git a/app/src/main/java/com/example/mobileapp/screens/EditProductScreen.kt b/app/src/main/java/com/example/mobileapp/screens/EditProductScreen.kt index 9ce7d3a..3423783 100644 --- a/app/src/main/java/com/example/mobileapp/screens/EditProductScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/EditProductScreen.kt @@ -1,5 +1,6 @@ package com.example.mobileapp.screens +import android.annotation.SuppressLint import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.background import androidx.compose.foundation.layout.Column @@ -27,6 +28,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateListOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -43,6 +45,7 @@ import com.example.mobileapp.R import com.example.mobileapp.db.AppDatabase import com.example.mobileapp.widgets.Header import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @Composable @@ -56,6 +59,7 @@ fun EditProductScreen(id: Int){ } } +@SuppressLint("CoroutineCreationDuringComposition") @OptIn(ExperimentalMaterial3Api::class) @Composable fun EditProductCard(id: Int){ @@ -85,11 +89,12 @@ fun EditProductCard(id: Int){ textAlign = TextAlign.Center, ) val context = LocalContext.current - val categoryList = remember { mutableStateListOf() } + var selectedCategory by remember { mutableStateOf("") } var expanded by remember { mutableStateOf(false) } val title = remember { mutableStateOf(TextFieldValue("")) } val price = remember { mutableStateOf(TextFieldValue("")) } + val scope = rememberCoroutineScope() LaunchedEffect(Unit) { withContext(Dispatchers.IO) { AppDatabase.getInstance(context).productDao().getById(id).collect {data -> @@ -100,10 +105,6 @@ fun EditProductCard(id: Int){ selectedCategory = it.name } } - AppDatabase.getInstance(context).categoryDao().getAll().collect { data -> - categoryList.clear() - categoryList.addAll(data.map { it.name }) - } } } Card( @@ -139,6 +140,7 @@ fun EditProductCard(id: Int){ border = BorderStroke(1.dp, Color(222,161,69)), modifier = Modifier.fillMaxWidth().padding(top = 20.dp, start = 20.dp, end = 20.dp), ){ + MaterialTheme( colorScheme = lightColorScheme( surfaceVariant= Color.White, @@ -146,6 +148,13 @@ fun EditProductCard(id: Int){ onSurface = Color.Gray ) ){ + val categoryList = remember { mutableStateListOf() } + scope.launch { + AppDatabase.getInstance(context).categoryDao().getAll().collect { data -> + categoryList.clear() + categoryList.addAll(data.map { category -> category.name }) + } + } ExposedDropdownMenuBox( expanded = expanded, onExpandedChange = { diff --git a/app/src/main/java/com/example/mobileapp/screens/MenuScreen.kt b/app/src/main/java/com/example/mobileapp/screens/MenuScreen.kt index fd73237..a1d273e 100644 --- a/app/src/main/java/com/example/mobileapp/screens/MenuScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/MenuScreen.kt @@ -20,6 +20,7 @@ import androidx.compose.material3.OutlinedButton import androidx.compose.material3.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.runtime.rememberCoroutineScope @@ -69,20 +70,17 @@ fun MenuCard(){ horizontalAlignment = Alignment.CenterHorizontally, ) { - val categoryWithProducts = remember { mutableListOf()} + val categoryWithProducts = remember { mutableStateListOf()} val context = LocalContext.current - val scope = rememberCoroutineScope() LaunchedEffect(Unit) { withContext(Dispatchers.IO) { - AppDatabase.getInstance(context).categoryDao().getCatgoryWithProducts().collect { data -> + (AppDatabase.getInstance(context).categoryDao().getCategoryWithProducts()).collect { data -> categoryWithProducts.addAll(data) } } } - - LazyColumn( modifier = Modifier .fillMaxSize() diff --git a/app/src/main/java/com/example/mobileapp/screens/OrderScreen.kt b/app/src/main/java/com/example/mobileapp/screens/OrderScreen.kt index 5dbdf82..8c9b47f 100644 --- a/app/src/main/java/com/example/mobileapp/screens/OrderScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/OrderScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.material3.OutlinedButton import androidx.compose.material3.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.runtime.rememberCoroutineScope @@ -80,7 +81,7 @@ fun OrderCard(){ textAlign = TextAlign.Center, ) - val ordersWithProducts = remember { mutableListOf () } + val ordersWithProducts = remember { mutableStateListOf () } val context = LocalContext.current val scope = rememberCoroutineScope() @@ -125,7 +126,7 @@ fun OrderCard(){ ) Text( - text = "Статус: " + status, + text = "Статус: " + status.value, color = Color.Black, fontFamily = FontFamily(Font(R.font.nunito_extrabold_italic)), fontSize = 20.sp, @@ -166,6 +167,7 @@ fun OrderCard(){ border = BorderStroke(4.dp, Color(222,161,69)), shape = RoundedCornerShape(20.dp), colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)), + modifier = Modifier.padding(bottom = 10.dp) ) { Text( text = "Готов", @@ -183,6 +185,7 @@ fun OrderCard(){ border = BorderStroke(4.dp, Color(222,161,69)), shape = RoundedCornerShape(20.dp), colors = ButtonDefaults.outlinedButtonColors(Color(255,186,83)), + modifier = Modifier.padding(bottom = 10.dp) ) { Text( text = "Выдать", diff --git a/app/src/main/java/com/example/mobileapp/screens/ProfileScreen.kt b/app/src/main/java/com/example/mobileapp/screens/ProfileScreen.kt index c6eb0ab..e15975b 100644 --- a/app/src/main/java/com/example/mobileapp/screens/ProfileScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/ProfileScreen.kt @@ -19,6 +19,7 @@ import androidx.compose.material3.OutlinedButton import androidx.compose.material3.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.runtime.rememberCoroutineScope @@ -103,13 +104,14 @@ fun ProfileCard(navController: NavController){ textAlign = TextAlign.Center, ) - val ordersWithProducts = remember { mutableListOf () } + val ordersWithProducts = remember { mutableStateListOf () } val context = LocalContext.current val scope = rememberCoroutineScope() LaunchedEffect(Unit) { withContext(Dispatchers.IO) { AppDatabase.getInstance(context).orderDao().getByUserId(1).collect { data -> + ordersWithProducts.clear() ordersWithProducts.addAll(data) } } diff --git a/app/src/main/java/com/example/mobileapp/screens/UsersScreen.kt b/app/src/main/java/com/example/mobileapp/screens/UsersScreen.kt index 4a52ed2..8954388 100644 --- a/app/src/main/java/com/example/mobileapp/screens/UsersScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/UsersScreen.kt @@ -97,7 +97,7 @@ fun UsersCard(){ .padding(top = 10.dp), textAlign = TextAlign.Center, ) - val users = remember { mutableListOf () } + val users = remember { mutableStateListOf () } val context = LocalContext.current val scope = rememberCoroutineScope() LaunchedEffect(Unit) { @@ -152,8 +152,11 @@ fun UsersCard(){ scope.launch { 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 -> selectedRole = data.name }