From 1921585f6f48876bc5f74b7086370e7f8e52501a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BA=D0=B0=D1=82=D0=B5=D1=80=D0=B8=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=A0=D0=BE=D0=B3=D0=B0=D1=88=D0=BE=D0=B2=D0=B0?= Date: Wed, 27 Dec 2023 00:00:59 +0400 Subject: [PATCH] . --- app/build.gradle.kts | 1 + .../java/com/example/myapplication/Enter.kt | 24 ++++++++++++++ .../java/com/example/myapplication/Profile.kt | 28 ++++++++-------- .../com/example/myapplication/Registration.kt | 20 ++++++++++- .../myapplication/dataBase/AppDatabase.kt | 2 +- .../myapplication/ui/edit/LessonRecord.kt | 25 ++++++++++++-- .../myapplication/ui/lesson/LessonList.kt | 1 - app/src/main/res/values/strings.xml | 2 +- server/data.json | 33 ++++++++++++++++--- 9 files changed, 111 insertions(+), 25 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6b66446..f157ae6 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -63,6 +63,7 @@ dependencies { implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.material3:material3:1.1.2") + implementation("androidx.compose.material:material:1.4.3") // Room val room_version = "2.5.2" diff --git a/app/src/main/java/com/example/myapplication/Enter.kt b/app/src/main/java/com/example/myapplication/Enter.kt index 4efe270..718c0a7 100644 --- a/app/src/main/java/com/example/myapplication/Enter.kt +++ b/app/src/main/java/com/example/myapplication/Enter.kt @@ -22,6 +22,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Done import androidx.compose.material.icons.filled.Lock +import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -33,6 +34,7 @@ import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment @@ -73,6 +75,23 @@ fun Enter(navController: NavController, modifier: Modifier = Modifier, lessonLis val users = mutableStateOf>(entryScreenViewModel.userList) val argument = currentUserViewModel.argument.value var passwordVisibility by rememberSaveable { mutableStateOf(false) } + val showInvalidPasswordDialog = remember { mutableStateOf(false) } + + + if (showInvalidPasswordDialog.value) { + AlertDialog( + onDismissRequest = { showInvalidPasswordDialog.value = false }, + title = { Text(text = "Ошибка") }, + text = { Text(text = "Неверный логин и/или пароль. Если вы у нас впервые - зарегистрируйтесь!") }, + confirmButton = { + Button( + onClick = { showInvalidPasswordDialog.value = false }, + ) { + Text(text = "Ок") + } + } + ) + } Box( modifier = modifier @@ -196,14 +215,19 @@ fun Enter(navController: NavController, modifier: Modifier = Modifier, lessonLis Button( onClick = { if (passwordValue.isNotEmpty()) { + var userExists = false users.value.forEach { user -> if (user.password == passwordValue && user.userName == emailValue) { currentUserViewModel.setArgument(user.uid.toString()) Log.d("CurrentUserViewModel1", "Текущий пользователь: $user") navController.navigate(route = Graph.passUserId(user.uid.toString())) { } + userExists = true } } + if (!userExists) { + showInvalidPasswordDialog.value = true + } } }, modifier = Modifier diff --git a/app/src/main/java/com/example/myapplication/Profile.kt b/app/src/main/java/com/example/myapplication/Profile.kt index 39640c9..77c0751 100644 --- a/app/src/main/java/com/example/myapplication/Profile.kt +++ b/app/src/main/java/com/example/myapplication/Profile.kt @@ -478,18 +478,24 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL } else{ Text( - text = "Получить отчет", - color = Color.Black, + text = "К записи", + color = Color.White, textAlign = TextAlign.Center, style = TextStyle( - fontSize = 16.sp, + fontSize = 17.sp, fontWeight = FontWeight.Bold ), modifier = Modifier - .fillMaxWidth() - .padding(16.dp) - .background(Color.LightGray) - .requiredWidth(300.dp) + .requiredWidth(width = 343.dp) + .requiredHeight(height = 44.dp) + .wrapContentHeight(align = Alignment.CenterVertically) + .align(Alignment.Center) + .clickable( + enabled = getUser?.lessonId != null, + onClick = { + val route = BottomBarScreen.LessonRecord.route.replace("{id}", lessonId.toString()) + navController.navigate(route) + }) ) } } @@ -514,7 +520,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL ) ) Text( - text = "К записи", + text = "Получить отчет", color = Color.White, textAlign = TextAlign.Center, style = TextStyle( @@ -529,12 +535,6 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL .clickable( enabled = getUser?.lessonId != null, onClick = { -// getUser?.lessonId = null -// coroutineScope.launch { -// getUser?.let { -// currentUserViewModel.updateUser(it) -// } -// } val route = BottomBarScreen.LessonRecord.route.replace("{id}", lessonId.toString()) navController.navigate(route) }) diff --git a/app/src/main/java/com/example/myapplication/Registration.kt b/app/src/main/java/com/example/myapplication/Registration.kt index b7d8b58..4f2130b 100644 --- a/app/src/main/java/com/example/myapplication/Registration.kt +++ b/app/src/main/java/com/example/myapplication/Registration.kt @@ -22,6 +22,7 @@ import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Done import androidx.compose.material.icons.filled.Lock +import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -34,6 +35,7 @@ import androidx.compose.material3.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue @@ -79,6 +81,21 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re registerScreenViewModel.users.observeForever { userList -> users.value = userList } + val showInvalidPasswordDialog = remember { mutableStateOf(false) } + if (showInvalidPasswordDialog.value) { + AlertDialog( + onDismissRequest = { showInvalidPasswordDialog.value = false }, + title = { Text(text = "Ошибка") }, + text = { Text(text = "Пользователь с таким логином уже есть") }, + confirmButton = { + Button( + onClick = { showInvalidPasswordDialog.value = false }, + ) { + Text(text = "Ок") + } + } + ) + } var passwordVisibility by rememberSaveable { mutableStateOf(false) } @@ -214,9 +231,10 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re var isExist = false; if (passwordValue.isNotEmpty() && loginValue.isNotEmpty() && fioValue.isNotEmpty()) { users.value.forEach { user -> - if (user.userName == loginValue || user.fio == fioValue) { + if (user.userName == loginValue) { Log.d("User already exist. User id: ", user.uid.toString()) isExist = true + showInvalidPasswordDialog.value = true } } if (!isExist) { diff --git a/app/src/main/java/com/example/myapplication/dataBase/AppDatabase.kt b/app/src/main/java/com/example/myapplication/dataBase/AppDatabase.kt index d7c38e0..7f62951 100644 --- a/app/src/main/java/com/example/myapplication/dataBase/AppDatabase.kt +++ b/app/src/main/java/com/example/myapplication/dataBase/AppDatabase.kt @@ -29,7 +29,7 @@ abstract class AppDatabase : RoomDatabase() { abstract fun remoteKeysDao(): RemoteKeysDao companion object { - private const val DB_NAME: String = "bd4" + private const val DB_NAME: String = "bd8" @Volatile private var INSTANCE: AppDatabase? = null diff --git a/app/src/main/java/com/example/myapplication/ui/edit/LessonRecord.kt b/app/src/main/java/com/example/myapplication/ui/edit/LessonRecord.kt index ffcbf07..39c6a3c 100644 --- a/app/src/main/java/com/example/myapplication/ui/edit/LessonRecord.kt +++ b/app/src/main/java/com/example/myapplication/ui/edit/LessonRecord.kt @@ -37,10 +37,12 @@ fun LessonRecord( val getUser by remember { mutableStateOf(currentUserViewModel.user) } Log.d("getUserLesson", "gU: $getUser") val lessonCurId = viewModel.getUidLesson() + val lessonDetails = viewModel.lessonUiState.lessonDetails LessonRecord( lessonUiState = viewModel.lessonUiState, directionUiState = directionViewModel.directionUiState, - enabled = getUser?.lessonId != lessonCurId, + enabled = (getUser?.lessonId != lessonCurId) && (lessonDetails.countRecord > 0), + enabled1 = getUser?.lessonId == lessonCurId, onClick = { coroutineScope.launch { Log.d("LessonBefore", "LB: ${getUser?.lessonId}") @@ -55,9 +57,16 @@ fun LessonRecord( } navController.popBackStack() } - }, - + onClick1 = { + getUser?.lessonId = null + coroutineScope.launch { + getUser?.let { + currentUserViewModel.updateUser(it) + } + viewModel.updateRecordsForCancel() + } + } ) {} } @@ -67,7 +76,9 @@ private fun LessonRecord( lessonUiState: LessonUiState, directionUiState: DirectionUiState, enabled: Boolean, + enabled1: Boolean, onClick: () -> Unit, + onClick1: () -> Unit, onUpdate: (LessonDetails) -> Unit ) { Column( @@ -123,5 +134,13 @@ private fun LessonRecord( ) { Text(text = stringResource(R.string.lesson_record_button)) } + Button( + onClick = onClick1, + enabled = enabled1, + shape = MaterialTheme.shapes.small, + modifier = Modifier.fillMaxWidth() + ) { + Text(text = stringResource(R.string.lesson_cancel_button)) + } } } diff --git a/app/src/main/java/com/example/myapplication/ui/lesson/LessonList.kt b/app/src/main/java/com/example/myapplication/ui/lesson/LessonList.kt index 93f0f52..d4667d5 100644 --- a/app/src/main/java/com/example/myapplication/ui/lesson/LessonList.kt +++ b/app/src/main/java/com/example/myapplication/ui/lesson/LessonList.kt @@ -182,7 +182,6 @@ private fun SwipeToDelete( }, dismissContent = { LessonListItem(lesson = lesson, - modifier = Modifier .padding(vertical = 7.dp) .clickable { onClick(lesson.uid) }) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e930f21..3b5d41c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,7 +12,7 @@ Занятий нет Занятие сохранено Записаться - + Отменить запись Телефон Время начала и конца День недели diff --git a/server/data.json b/server/data.json index 1f5cddc..b2f2f0f 100644 --- a/server/data.json +++ b/server/data.json @@ -91,6 +91,23 @@ "dayOfWeekId": 5, "directionId": 1, "countRecord": 5 + }, + { + "id": 6, + "teacher": "Софья Олеговна", + "time": "10.00", + "classNumber": 6, + "dayOfWeekId": 3, + "directionId": 6, + "countRecord": 5 + }, + { + "id": 7, + "teacher": "Илона", + "time": "10.00", + "classNumber": 5, + "dayOfWeekId": 5, + "directionId": 3 } ], "users": [ @@ -108,7 +125,7 @@ "password": "5678", "fio": "Илья Петрович Мунин", "role": "User", - "lessonId": 1 + "lessonId": 7 }, { "id": 3, @@ -116,7 +133,7 @@ "password": "13579", "fio": "Мария Денисовна Амова", "role": "User", - "lessonId": 1 + "lessonId": 3 }, { "id": 7, @@ -124,7 +141,7 @@ "password": "user7", "fio": "user7", "role": "User", - "lessonId": 3 + "lessonId": 7 }, { "id": 8, @@ -132,7 +149,15 @@ "password": "user8", "fio": "user8", "role": "User", - "lessonId": 5 + "lessonId": null + }, + { + "id": 9, + "userName": "user7", + "password": "parol", + "fio": "user7", + "role": "User", + "lessonId": 7 } ] } \ No newline at end of file