хвала небесам запись заработала

This commit is contained in:
Екатерина Рогашова 2023-12-26 00:52:27 +04:00
parent 84dbb70f6e
commit 235636627b
7 changed files with 222 additions and 222 deletions

View File

@ -23,7 +23,7 @@ import com.example.myapplication.ui.AppViewModelProvider
import com.example.myapplication.ui.edit.DayDropDownViewModel
import com.example.myapplication.ui.edit.DirectionDropDownViewModel
import com.example.myapplication.ui.edit.LessonEdit
//import com.example.myapplication.ui.edit.LessonRecord
import com.example.myapplication.ui.edit.LessonRecord
import com.example.myapplication.ui.edit.LessonEditViewModel
import com.example.myapplication.ui.lesson.LessonList
import com.example.myapplication.ui.lesson.LessonListViewModel
@ -52,12 +52,12 @@ fun HomeNavGraph(navController: NavHostController, currentUserViewModel: Current
) {
LessonEdit(navController)
}
// composable(
// BottomBarScreen.LessonRecord.route,
// arguments = listOf(navArgument("id") { type = NavType.IntType })
// ) {
// LessonRecord(navController)
// }
composable(
BottomBarScreen.LessonRecord.route,
arguments = listOf(navArgument("id") { type = NavType.IntType })
) {
LessonRecord(navController, currentUserViewModel)
}
composable(route = BottomBarScreen.DirectionView.route) { DirectionView(navController) }
composable(route = BottomBarScreen.Profile.route) {
Profile(

View File

@ -44,6 +44,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.paging.compose.collectAsLazyPagingItems
import com.example.myapplication.Graph.AuthScreen
import com.example.myapplication.dataBase.model.RoleEnum
import com.example.myapplication.ui.AppViewModelProvider
import com.example.myapplication.ui.lesson.LessonListViewModel
import com.example.myapplication.ui.user.CurrentUserViewModel
@ -391,18 +392,34 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
.background(color = Color.White)
)
Text(
text = "Ближайшая запись:",
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
if (getUser?.role == RoleEnum.User) {
Text(
text = "Ближайшая запись:",
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
}
else{
Text(
text = "Отчет",
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
}
}
}
}
@ -434,61 +451,84 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
.background(color = Color.White)
)
Text(
text = userLessonText,
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.background(Color.LightGray)
.requiredWidth(300.dp)
)
}
Box(
modifier = Modifier
.align(alignment = Alignment.TopStart)
.offset(
x = 0.dp,
y = 75.dp
if (getUser?.role == RoleEnum.User) {
Text(
text = userLessonText,
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.background(Color.LightGray)
.requiredWidth(300.dp)
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 44.dp)
) {
}
else{
Text(
text = "Получить отчет",
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.background(Color.LightGray)
.requiredWidth(300.dp)
)
}
}
if (getUser?.role == RoleEnum.User) {
Box(
modifier = Modifier
.fillMaxWidth()
.requiredWidth(width = 300.dp)
.height(50.dp)
.background(Color.Black),
)
Text(
text = "Отменить запись",
color = Color.White,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 17.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.requiredWidth(width = 343.dp)
.align(alignment = Alignment.TopStart)
.offset(
x = 0.dp,
y = 75.dp
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 44.dp)
.wrapContentHeight(align = Alignment.CenterVertically)
.align(Alignment.Center)
.clickable(onClick = {
getUser?.lessonId = null
coroutineScope.launch {
getUser?.let {
currentUserViewModel.updateUser(it)
}
}
})
)
) {
Box(
modifier = Modifier
.fillMaxWidth()
.requiredWidth(width = 300.dp)
.height(50.dp)
.background(
if (getUser?.lessonId != null) Color.Black else Color.Gray
)
)
Text(
text = "Отменить запись",
color = Color.White,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 17.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.requiredWidth(width = 343.dp)
.requiredHeight(height = 44.dp)
.wrapContentHeight(align = Alignment.CenterVertically)
.align(Alignment.Center)
.clickable(
enabled = getUser?.lessonId != null,
onClick = {
getUser?.lessonId = null
coroutineScope.launch {
getUser?.let {
currentUserViewModel.updateUser(it)
}
}
})
)
}
}
}
@ -496,3 +536,4 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
}
}

View File

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

View File

@ -10,8 +10,8 @@ import androidx.room.PrimaryKey
entity = Lesson::class,
parentColumns = ["uid"],
childColumns = ["lesson_id"],
onDelete = ForeignKey.NO_ACTION,
onUpdate = ForeignKey.NO_ACTION
onDelete = ForeignKey.CASCADE,
onUpdate = ForeignKey.CASCADE
)])
data class User(
@PrimaryKey(autoGenerate = true)

View File

@ -25,99 +25,98 @@ import com.example.myapplication.ui.AppViewModelProvider
import com.example.myapplication.ui.user.CurrentUserViewModel
import kotlinx.coroutines.launch
//@Composable
//fun LessonRecord(
// navController: NavController,
// viewModel: LessonEditViewModel = viewModel(factory = AppViewModelProvider.Factory),
// directionViewModel: DirectionDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory),
// currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)
//) {
// val coroutineScope = rememberCoroutineScope()
// directionViewModel.setCurrentDirection(viewModel.lessonUiState.lessonDetails.directionId)
// val getUser by remember { mutableStateOf(currentUserViewModel.user) }
// Log.d("getUserLesson", "gU: $getUser")
//
// LessonRecord(
// lessonUiState = viewModel.lessonUiState,
// directionUiState = directionViewModel.directionUiState,
// onClick = {
// coroutineScope.launch {
// val lessonCurId = viewModel.getUidLesson()
// Log.d("LessonBefore", "LB: ${getUser?.lessonId}")
//
// getUser?.let {
// it.lessonId = lessonCurId
// Log.d("LessonAfter", "LA: ${getUser?.lessonId}")
// currentUserViewModel.updateUser(it)
// Log.d("UserAfter", "UA: $getUser")
// }
//
// navController.popBackStack()
// }
//
// }
// ) {}
//}
//
//@OptIn(ExperimentalMaterial3Api::class)
//@Composable
//private fun LessonRecord(
// lessonUiState: LessonUiState,
// directionUiState: DirectionUiState,
// onClick: () -> Unit,
// onUpdate: (LessonDetails) -> Unit
//) {
// Column(
// Modifier
// .fillMaxWidth()
// .padding(all = 10.dp)
// ) {
// OutlinedTextField(
// modifier = Modifier.fillMaxWidth(),
// value = lessonUiState.lessonDetails.time,
// onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(time = it)) },
// label = { Text(stringResource(id = R.string.lesson_TimeDate)) },
// singleLine = true,
// readOnly = true
// )
// OutlinedTextField(
// modifier = Modifier.fillMaxWidth(),
// value = lessonUiState.lessonDetails.teacher,
// onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(teacher = it)) },
// label = { Text(stringResource(id = R.string.lesson_teacher)) },
// singleLine = true,
// readOnly = true
// )
// OutlinedTextField(
// modifier = Modifier.fillMaxWidth(),
// value = directionUiState.direction?.directionName
// ?: stringResource(id = R.string.lesson_direction),
// label = { Text(stringResource(id = R.string.lesson_direction)) },
// onValueChange = {},
// readOnly = true,
// )
// OutlinedTextField(
// modifier = Modifier.fillMaxWidth(),
// value = lessonUiState.lessonDetails.classNumber.toString(),
// onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(classNumber = it.toIntOrNull() ?: 0)) },
// label = { Text(stringResource(id = R.string.lesson_classNumber)) },
// singleLine = true,
// readOnly = true
// )
// OutlinedTextField(
// modifier = Modifier.fillMaxWidth(),
// value = lessonUiState.lessonDetails.countRecord.toString(),
// onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(countRecord = it.toIntOrNull() ?: 0)) },
// label = { Text(stringResource(id = R.string.lesson_countRecord)) },
// singleLine = true,
// readOnly = true
// )
// Button(
// onClick = onClick,
// shape = MaterialTheme.shapes.small,
// modifier = Modifier.fillMaxWidth()
// ) {
// Text(text = stringResource(R.string.lesson_record_button))
// }
// }
//}
@Composable
fun LessonRecord(
navController: NavController,
currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory),
viewModel: LessonEditViewModel = viewModel(factory = AppViewModelProvider.Factory),
directionViewModel: DirectionDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory)
) {
val coroutineScope = rememberCoroutineScope()
directionViewModel.setCurrentDirection(viewModel.lessonUiState.lessonDetails.directionId)
val getUser by remember { mutableStateOf(currentUserViewModel.user) }
Log.d("getUserLesson", "gU: $getUser")
LessonRecord(
lessonUiState = viewModel.lessonUiState,
directionUiState = directionViewModel.directionUiState,
onClick = {
coroutineScope.launch {
val lessonCurId = viewModel.getUidLesson()
Log.d("LessonBefore", "LB: ${getUser?.lessonId}")
getUser?.let {
it.lessonId = lessonCurId
Log.d("LessonAfter", "LA: ${getUser?.lessonId}")
currentUserViewModel.updateUser(it)
Log.d("UserAfter", "UA: $getUser")
}
navController.popBackStack()
}
}
) {}
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun LessonRecord(
lessonUiState: LessonUiState,
directionUiState: DirectionUiState,
onClick: () -> Unit,
onUpdate: (LessonDetails) -> Unit
) {
Column(
Modifier
.fillMaxWidth()
.padding(all = 10.dp)
) {
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = lessonUiState.lessonDetails.time,
onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(time = it)) },
label = { Text(stringResource(id = R.string.lesson_TimeDate)) },
singleLine = true,
readOnly = true
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = lessonUiState.lessonDetails.teacher,
onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(teacher = it)) },
label = { Text(stringResource(id = R.string.lesson_teacher)) },
singleLine = true,
readOnly = true
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = directionUiState.direction?.directionName
?: stringResource(id = R.string.lesson_direction),
label = { Text(stringResource(id = R.string.lesson_direction)) },
onValueChange = {},
readOnly = true,
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = lessonUiState.lessonDetails.classNumber.toString(),
onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(classNumber = it.toIntOrNull() ?: 0)) },
label = { Text(stringResource(id = R.string.lesson_classNumber)) },
singleLine = true,
readOnly = true
)
OutlinedTextField(
modifier = Modifier.fillMaxWidth(),
value = lessonUiState.lessonDetails.countRecord.toString(),
onValueChange = { onUpdate(lessonUiState.lessonDetails.copy(countRecord = it.toIntOrNull() ?: 0)) },
label = { Text(stringResource(id = R.string.lesson_countRecord)) },
singleLine = true,
readOnly = true
)
Button(
onClick = onClick,
shape = MaterialTheme.shapes.small,
modifier = Modifier.fillMaxWidth()
) {
Text(text = stringResource(R.string.lesson_record_button))
}
}
}

View File

@ -77,6 +77,7 @@ import com.example.myapplication.dataBase.model.Lesson
import com.example.myapplication.dataBase.model.RoleEnum
import com.example.myapplication.dataBase.model.User
import com.example.myapplication.ui.AppViewModelProvider
import com.example.myapplication.ui.edit.DirectionDropDownViewModel
import com.example.myapplication.ui.navigation.Screen
import com.example.myapplication.ui.theme.PmudemoTheme
import com.example.myapplication.ui.user.CurrentUserViewModel
@ -122,10 +123,10 @@ fun LessonList(
val route = BottomBarScreen.LessonEdit.route.replace("{id}", uid.toString())
navController.navigate(route)
}
// else{
// val route = BottomBarScreen.LessonRecord.route.replace("{id}", uid.toString())
// navController.navigate(route)
// }
else{
val route = BottomBarScreen.LessonRecord.route.replace("{id}", uid.toString())
navController.navigate(route)
}
}
){ lesson: Lesson ->
if (getUser?.role == RoleEnum.Admin) {
@ -529,36 +530,3 @@ private fun LessonListItem(
}
}
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
//@Composable
//fun LessonListPreview() {
// PmudemoTheme {
// Surface(
// color = MaterialTheme.colorScheme.background
// ) {
// LessonList(
// lessonList = (1..20).map { i -> Lesson.getLesson(i) },
// onClick = {}
// ) {}
// }
// }
//}
//
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
//@Composable
//fun LessonEmptyListPreview() {
// PmudemoTheme {
// Surface(
// color = MaterialTheme.colorScheme.background
// ) {
// LessonList(
// lessonList = listOf(),
// onClick = {}
// ) {}
// }
// }
//}

View File

@ -124,23 +124,15 @@
"password": "user7",
"fio": "user7",
"role": "User",
"lessonId": 4
},
{
"id": 8,
"userName": "user8",
"password": "user8",
"fio": "user8",
"role": "User",
"lessonId": null
},
{
"userName": "user8",
"password": "user8",
"fio": "user8",
"role": "User",
"lessonId": null,
"id": 8
},
{
"userName": "user8",
"password": "user8",
"fio": "user8",
"role": "User",
"lessonId": null,
"id": 9
}
]
}