не все так плохо)))надеюсь

This commit is contained in:
Екатерина Рогашова 2023-12-26 02:04:48 +04:00
parent 235636627b
commit d3ea61ad03
3 changed files with 36 additions and 32 deletions

View File

@ -46,6 +46,8 @@ 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.edit.DayDropDownViewModel
import com.example.myapplication.ui.edit.DirectionDropDownViewModel
import com.example.myapplication.ui.lesson.LessonListViewModel
import com.example.myapplication.ui.user.CurrentUserViewModel
import kotlinx.coroutines.launch
@ -53,9 +55,8 @@ import kotlinx.coroutines.launch
@SuppressLint("UnrememberedMutableState")
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonListViewModel: LessonListViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)) {
fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonListViewModel: LessonListViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory), directionViewModel: DirectionDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory), dayViewModel: DayDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory)) {
val context = LocalContext.current
var getUser by remember { mutableStateOf(currentUserViewModel.user) }
val coroutineScope = rememberCoroutineScope()
Log.d("Profile", "getUser: $getUser")
@ -64,9 +65,18 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
var password by remember { mutableStateOf(getUser?.password) }
var fio by remember { mutableStateOf(getUser?.fio) }
val lessonId = getUser?.lessonId
var userLessonText by remember { mutableStateOf("Записи нет") }
lessonListViewModel.getUserLesson(lessonId).observeForever { lesson ->
userLessonText = lesson?.time ?: "Записи нет"
if (lesson != null) {
lesson.directionId.let { directionViewModel.setCurrentDirection(it) }
val directionUiState = directionViewModel.directionUiState
lesson.dayOfWeekId.let { dayViewModel.setCurrentDayOfWeek(it) }
val dayOfWeekUiState = dayViewModel.dayOfWeekUiState
userLessonText = String.format("%s %s\n Направление: %s\n Тренер: %s\t Зал: %s", dayOfWeekUiState.dayOfWeek?.dayName,lesson.time, directionUiState.direction?.directionName, lesson.teacher, lesson.classNumber)
} else{
userLessonText = "Записи нет"
}
}
Log.d("Profile11", "getUserLesson: $userLessonText")
@ -183,7 +193,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
modifier = Modifier
.offset(
x = 9.dp,
y = 60.dp
y = 30.dp
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 70.dp)
@ -230,7 +240,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
modifier = Modifier
.offset(
x = 106.dp,
y = 60.dp
y = 30.dp
)
.requiredWidth(width = 200.dp)
.requiredHeight(height = 310.dp)
@ -250,7 +260,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
Box(
modifier = Modifier
.requiredWidth(width = 300.dp)
.requiredHeight(height = 80.dp)
.requiredHeight(height = 60.dp)
.background(Color.White)
.border(width = 1.dp, color = Color.Black) // Добавляем черную границу,
)
@ -281,7 +291,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
Box(
modifier = Modifier
.requiredWidth(width = 300.dp)
.requiredHeight(height = 80.dp)
.requiredHeight(height = 60.dp)
.background(Color.White)
.border(width = 1.dp, color = Color.Black) // Добавляем черную границу
)
@ -369,7 +379,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
modifier = Modifier
.offset(
x = 0.dp,
y = 20.dp
y = 5.dp
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 70.dp)
@ -379,7 +389,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
.align(alignment = Alignment.TopStart)
.offset(
x = 0.dp,
y = 27.dp
y = 10.dp
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 70.dp)
@ -390,7 +400,6 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
.requiredHeight(height = 70.dp)
.clip(shape = RoundedCornerShape(5.dp))
.background(color = Color.White)
)
if (getUser?.role == RoleEnum.User) {
Text(
@ -398,12 +407,11 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
color = Color.Black,
textAlign = TextAlign.Center,
style = TextStyle(
fontSize = 24.sp,
fontSize = 21.sp,
fontWeight = FontWeight.Bold
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
)
}
else{
@ -428,25 +436,25 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
modifier = Modifier
.offset(
x = 9.dp,
y = 10.dp
y = (-25).dp
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 100.dp)
.requiredHeight(height = 80.dp)
) {
Box(
modifier = Modifier
.align(alignment = Alignment.TopStart)
.offset(
x = 0.dp,
y = 27.dp
y = 10.dp
)
.requiredWidth(width = 393.dp)
.requiredHeight(height = 70.dp)
.requiredHeight(height = 80.dp)
) {
Box(
modifier = Modifier
.requiredWidth(width = 393.dp)
.requiredHeight(height = 70.dp)
.requiredHeight(height = 80.dp)
.clip(shape = RoundedCornerShape(5.dp))
.background(color = Color.White)
@ -462,9 +470,8 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, lessonL
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
.background(Color.LightGray)
.requiredWidth(300.dp)
.requiredHeight(80.dp)
)
}
else{

View File

@ -182,6 +182,7 @@ private fun SwipeToDelete(
},
dismissContent = {
LessonListItem(lesson = lesson,
modifier = Modifier
.padding(vertical = 7.dp)
.clickable { onClick(lesson.uid) })
@ -508,13 +509,9 @@ private fun LessonList(
private fun LessonListItem(
lesson: Lesson, modifier: Modifier = Modifier
) {
var dir = ""
if (lesson.directionId == 3) dir = "Contemporary"
if (lesson.directionId == 1) dir = "K-pop"
if (lesson.directionId == 2) dir = "House"
if (lesson.directionId == 4) dir = "BreakDance"
if (lesson.directionId == 6) dir = "Dancehall"
if (lesson.directionId == 5) dir = "Jazz-funk"
val directionViewModel: DirectionDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory)
lesson.directionId.let { directionViewModel.setCurrentDirection(it) }
val directionUiState = directionViewModel.directionUiState
Card(
modifier = modifier.fillMaxWidth(),
shape = RoundedCornerShape(0.dp),
@ -524,7 +521,7 @@ private fun LessonListItem(
modifier = modifier.align(CenterHorizontally)
) {
Text(
text = String.format("%s %s %s", lesson.time, lesson.teacher, dir)
text = String.format("%s %s %s", lesson.time, lesson.teacher, directionUiState.direction?.directionName)
)
}
}

View File

@ -105,18 +105,18 @@
{
"id": 2,
"userName": "user2",
"fio": "Илья Петрович Мунин",
"password": "5678",
"fio": "Илья Петрович Мунин",
"role": "User",
"lessonId": null
"lessonId": 1
},
{
"id": 3,
"userName": "user3",
"fio": "Мария Денисовна Амова",
"password": "13579",
"fio": "Мария Денисовна Амова",
"role": "User",
"lessonId": null
"lessonId": 1
},
{
"id": 7,
@ -124,7 +124,7 @@
"password": "user7",
"fio": "user7",
"role": "User",
"lessonId": 4
"lessonId": 3
},
{
"id": 8,