This commit is contained in:
Екатерина Рогашова 2023-12-27 00:00:59 +04:00
parent ea3b827b55
commit 1921585f6f
9 changed files with 111 additions and 25 deletions

View File

@ -63,6 +63,7 @@ dependencies {
implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview") implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3:1.1.2") implementation("androidx.compose.material3:material3:1.1.2")
implementation("androidx.compose.material:material:1.4.3")
// Room // Room
val room_version = "2.5.2" val room_version = "2.5.2"

View File

@ -22,6 +22,7 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Lock import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -33,6 +34,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -73,6 +75,23 @@ fun Enter(navController: NavController, modifier: Modifier = Modifier, lessonLis
val users = mutableStateOf<List<User>>(entryScreenViewModel.userList) val users = mutableStateOf<List<User>>(entryScreenViewModel.userList)
val argument = currentUserViewModel.argument.value val argument = currentUserViewModel.argument.value
var passwordVisibility by rememberSaveable { mutableStateOf(false) } 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( Box(
modifier = modifier modifier = modifier
@ -196,14 +215,19 @@ fun Enter(navController: NavController, modifier: Modifier = Modifier, lessonLis
Button( Button(
onClick = { onClick = {
if (passwordValue.isNotEmpty()) { if (passwordValue.isNotEmpty()) {
var userExists = false
users.value.forEach { user -> users.value.forEach { user ->
if (user.password == passwordValue && user.userName == emailValue) { if (user.password == passwordValue && user.userName == emailValue) {
currentUserViewModel.setArgument(user.uid.toString()) currentUserViewModel.setArgument(user.uid.toString())
Log.d("CurrentUserViewModel1", "Текущий пользователь: $user") Log.d("CurrentUserViewModel1", "Текущий пользователь: $user")
navController.navigate(route = Graph.passUserId(user.uid.toString())) { navController.navigate(route = Graph.passUserId(user.uid.toString())) {
} }
userExists = true
} }
} }
if (!userExists) {
showInvalidPasswordDialog.value = true
}
} }
}, },
modifier = Modifier modifier = Modifier

View File

@ -478,18 +478,24 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
} }
else{ else{
Text( Text(
text = "Получить отчет", text = "К записи",
color = Color.Black, color = Color.White,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
style = TextStyle( style = TextStyle(
fontSize = 16.sp, fontSize = 17.sp,
fontWeight = FontWeight.Bold fontWeight = FontWeight.Bold
), ),
modifier = Modifier modifier = Modifier
.fillMaxWidth() .requiredWidth(width = 343.dp)
.padding(16.dp) .requiredHeight(height = 44.dp)
.background(Color.LightGray) .wrapContentHeight(align = Alignment.CenterVertically)
.requiredWidth(300.dp) .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 = "К записи", text = "Получить отчет",
color = Color.White, color = Color.White,
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
style = TextStyle( style = TextStyle(
@ -529,12 +535,6 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
.clickable( .clickable(
enabled = getUser?.lessonId != null, enabled = getUser?.lessonId != null,
onClick = { onClick = {
// getUser?.lessonId = null
// coroutineScope.launch {
// getUser?.let {
// currentUserViewModel.updateUser(it)
// }
// }
val route = BottomBarScreen.LessonRecord.route.replace("{id}", lessonId.toString()) val route = BottomBarScreen.LessonRecord.route.replace("{id}", lessonId.toString())
navController.navigate(route) navController.navigate(route)
}) })

View File

@ -22,6 +22,7 @@ import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Done import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.Lock import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
@ -34,6 +35,7 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
@ -79,6 +81,21 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re
registerScreenViewModel.users.observeForever { userList -> registerScreenViewModel.users.observeForever { userList ->
users.value = 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) } var passwordVisibility by rememberSaveable { mutableStateOf(false) }
@ -214,9 +231,10 @@ fun Registration(navController: NavController, modifier: Modifier = Modifier, re
var isExist = false; var isExist = false;
if (passwordValue.isNotEmpty() && loginValue.isNotEmpty() && fioValue.isNotEmpty()) { if (passwordValue.isNotEmpty() && loginValue.isNotEmpty() && fioValue.isNotEmpty()) {
users.value.forEach { user -> 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()) Log.d("User already exist. User id: ", user.uid.toString())
isExist = true isExist = true
showInvalidPasswordDialog.value = true
} }
} }
if (!isExist) { if (!isExist) {

View File

@ -29,7 +29,7 @@ abstract class AppDatabase : RoomDatabase() {
abstract fun remoteKeysDao(): RemoteKeysDao abstract fun remoteKeysDao(): RemoteKeysDao
companion object { companion object {
private const val DB_NAME: String = "bd4" private const val DB_NAME: String = "bd8"
@Volatile @Volatile
private var INSTANCE: AppDatabase? = null private var INSTANCE: AppDatabase? = null

View File

@ -37,10 +37,12 @@ fun LessonRecord(
val getUser by remember { mutableStateOf(currentUserViewModel.user) } val getUser by remember { mutableStateOf(currentUserViewModel.user) }
Log.d("getUserLesson", "gU: $getUser") Log.d("getUserLesson", "gU: $getUser")
val lessonCurId = viewModel.getUidLesson() val lessonCurId = viewModel.getUidLesson()
val lessonDetails = viewModel.lessonUiState.lessonDetails
LessonRecord( LessonRecord(
lessonUiState = viewModel.lessonUiState, lessonUiState = viewModel.lessonUiState,
directionUiState = directionViewModel.directionUiState, directionUiState = directionViewModel.directionUiState,
enabled = getUser?.lessonId != lessonCurId, enabled = (getUser?.lessonId != lessonCurId) && (lessonDetails.countRecord > 0),
enabled1 = getUser?.lessonId == lessonCurId,
onClick = { onClick = {
coroutineScope.launch { coroutineScope.launch {
Log.d("LessonBefore", "LB: ${getUser?.lessonId}") Log.d("LessonBefore", "LB: ${getUser?.lessonId}")
@ -55,9 +57,16 @@ fun LessonRecord(
} }
navController.popBackStack() navController.popBackStack()
} }
}, },
onClick1 = {
getUser?.lessonId = null
coroutineScope.launch {
getUser?.let {
currentUserViewModel.updateUser(it)
}
viewModel.updateRecordsForCancel()
}
}
) {} ) {}
} }
@ -67,7 +76,9 @@ private fun LessonRecord(
lessonUiState: LessonUiState, lessonUiState: LessonUiState,
directionUiState: DirectionUiState, directionUiState: DirectionUiState,
enabled: Boolean, enabled: Boolean,
enabled1: Boolean,
onClick: () -> Unit, onClick: () -> Unit,
onClick1: () -> Unit,
onUpdate: (LessonDetails) -> Unit onUpdate: (LessonDetails) -> Unit
) { ) {
Column( Column(
@ -123,5 +134,13 @@ private fun LessonRecord(
) { ) {
Text(text = stringResource(R.string.lesson_record_button)) 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))
}
} }
} }

View File

@ -182,7 +182,6 @@ private fun SwipeToDelete(
}, },
dismissContent = { dismissContent = {
LessonListItem(lesson = lesson, LessonListItem(lesson = lesson,
modifier = Modifier modifier = Modifier
.padding(vertical = 7.dp) .padding(vertical = 7.dp)
.clickable { onClick(lesson.uid) }) .clickable { onClick(lesson.uid) })

View File

@ -12,7 +12,7 @@
<string name="lesson_empty_description">Занятий нет</string> <string name="lesson_empty_description">Занятий нет</string>
<string name="lesson_save_button">Занятие сохранено</string> <string name="lesson_save_button">Занятие сохранено</string>
<string name="lesson_record_button">Записаться</string> <string name="lesson_record_button">Записаться</string>
<string name="lesson_cancel_button">Отменить запись</string>
<string name="student_phone">Телефон</string> <string name="student_phone">Телефон</string>
<string name="lesson_TimeDate">Время начала и конца</string> <string name="lesson_TimeDate">Время начала и конца</string>
<string name="lesson_DayOfWeek">День недели</string> <string name="lesson_DayOfWeek">День недели</string>

View File

@ -91,6 +91,23 @@
"dayOfWeekId": 5, "dayOfWeekId": 5,
"directionId": 1, "directionId": 1,
"countRecord": 5 "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": [ "users": [
@ -108,7 +125,7 @@
"password": "5678", "password": "5678",
"fio": "Илья Петрович Мунин", "fio": "Илья Петрович Мунин",
"role": "User", "role": "User",
"lessonId": 1 "lessonId": 7
}, },
{ {
"id": 3, "id": 3,
@ -116,7 +133,7 @@
"password": "13579", "password": "13579",
"fio": "Мария Денисовна Амова", "fio": "Мария Денисовна Амова",
"role": "User", "role": "User",
"lessonId": 1 "lessonId": 3
}, },
{ {
"id": 7, "id": 7,
@ -124,7 +141,7 @@
"password": "user7", "password": "user7",
"fio": "user7", "fio": "user7",
"role": "User", "role": "User",
"lessonId": 3 "lessonId": 7
}, },
{ {
"id": 8, "id": 8,
@ -132,7 +149,15 @@
"password": "user8", "password": "user8",
"fio": "user8", "fio": "user8",
"role": "User", "role": "User",
"lessonId": 5 "lessonId": null
},
{
"id": 9,
"userName": "user7",
"password": "parol",
"fio": "user7",
"role": "User",
"lessonId": 7
} }
] ]
} }