diff --git a/app/src/main/java/com/example/myapplication/Enter.kt b/app/src/main/java/com/example/myapplication/Enter.kt index 0ea1d6b..6f3dac2 100644 --- a/app/src/main/java/com/example/myapplication/Enter.kt +++ b/app/src/main/java/com/example/myapplication/Enter.kt @@ -56,6 +56,7 @@ import com.example.myapplication.Graph.AuthScreen import com.example.myapplication.Graph.Graph import com.example.myapplication.dataBase.model.User import com.example.myapplication.ui.AppViewModelProvider +import com.example.myapplication.ui.lesson.LessonListViewModel import com.example.myapplication.ui.navigation.Screen import com.example.myapplication.ui.theme.PmudemoTheme import com.example.myapplication.ui.user.CurrentUserViewModel @@ -64,7 +65,7 @@ import com.example.myapplication.ui.user.EntryViewModel @SuppressLint("UnrememberedMutableState") @OptIn(ExperimentalMaterial3Api::class) @Composable -fun Enter(navController: NavController, modifier: Modifier = Modifier, entryScreenViewModel: EntryViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)) { +fun Enter(navController: NavController, modifier: Modifier = Modifier, lessonListViewModel: LessonListViewModel, entryScreenViewModel: EntryViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)) { var emailValue by rememberSaveable { mutableStateOf("") } var passwordValue by rememberSaveable { mutableStateOf("") } diff --git a/app/src/main/java/com/example/myapplication/Graph/AuthNavGraph.kt b/app/src/main/java/com/example/myapplication/Graph/AuthNavGraph.kt index ef7e3d5..055c713 100644 --- a/app/src/main/java/com/example/myapplication/Graph/AuthNavGraph.kt +++ b/app/src/main/java/com/example/myapplication/Graph/AuthNavGraph.kt @@ -7,17 +7,19 @@ import androidx.navigation.compose.composable import androidx.navigation.navigation import com.example.myapplication.Enter import com.example.myapplication.Registration +import com.example.myapplication.ui.edit.LessonEditViewModel +import com.example.myapplication.ui.lesson.LessonListViewModel import com.example.myapplication.ui.user.CurrentUserViewModel import com.example.myapplication.ui.user.EntryViewModel import com.example.myapplication.ui.user.RegisterViewModel -fun NavGraphBuilder.authNavGraph(navController: NavHostController, registerScreenViewModel: RegisterViewModel, entryScreenViewModel: EntryViewModel, currentUserViewModel: CurrentUserViewModel){ +fun NavGraphBuilder.authNavGraph(navController: NavHostController, registerScreenViewModel: RegisterViewModel, entryScreenViewModel: EntryViewModel, currentUserViewModel: CurrentUserViewModel, lessonListViewModel: LessonListViewModel){ navigation( route=Graph.AUTHENTICATION, startDestination = AuthScreen.Enter.route ){ composable(route=AuthScreen.Enter.route){ - Enter(navController = navController, Modifier,entryScreenViewModel,currentUserViewModel) + Enter(navController = navController, Modifier,lessonListViewModel, entryScreenViewModel,currentUserViewModel) } composable(route=AuthScreen.Register.route){ Registration(navController = navController, Modifier,registerScreenViewModel,currentUserViewModel) diff --git a/app/src/main/java/com/example/myapplication/Graph/HomeNavGraph.kt b/app/src/main/java/com/example/myapplication/Graph/HomeNavGraph.kt index c39f6cb..9d617f1 100644 --- a/app/src/main/java/com/example/myapplication/Graph/HomeNavGraph.kt +++ b/app/src/main/java/com/example/myapplication/Graph/HomeNavGraph.kt @@ -63,6 +63,7 @@ fun HomeNavGraph(navController: NavHostController, currentUserViewModel: Current Profile( navController, Modifier, + lessonListViewModel, currentUserViewModel ) } diff --git a/app/src/main/java/com/example/myapplication/Graph/RootNavGraph.kt b/app/src/main/java/com/example/myapplication/Graph/RootNavGraph.kt index 7f53aef..a7c7782 100644 --- a/app/src/main/java/com/example/myapplication/Graph/RootNavGraph.kt +++ b/app/src/main/java/com/example/myapplication/Graph/RootNavGraph.kt @@ -10,6 +10,7 @@ import androidx.navigation.compose.composable import androidx.navigation.navArgument import com.example.myapplication.LoadScreen import com.example.myapplication.ui.AppViewModelProvider +import com.example.myapplication.ui.lesson.LessonListViewModel import com.example.myapplication.ui.user.CurrentUserViewModel import com.example.myapplication.ui.user.EntryViewModel import com.example.myapplication.ui.user.RegisterViewModel @@ -17,13 +18,13 @@ import com.example.myapplication.ui.user.RegisterViewModel const val USERID_ARGUMENT="uid" @Composable -fun RootNavigationGraph(navController: NavHostController, registerScreenViewModel: RegisterViewModel = viewModel(factory = AppViewModelProvider.Factory), entryScreenViewModel: EntryViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)){ +fun RootNavigationGraph(navController: NavHostController, registerScreenViewModel: RegisterViewModel = viewModel(factory = AppViewModelProvider.Factory), entryScreenViewModel: EntryViewModel = viewModel(factory = AppViewModelProvider.Factory), lessonListViewModel: LessonListViewModel = viewModel(factory = AppViewModelProvider.Factory), currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory)){ NavHost( navController=navController, route = Graph.ROOT, startDestination = Graph.AUTHENTICATION ){ - authNavGraph(navController=navController,registerScreenViewModel,entryScreenViewModel,currentUserViewModel) + authNavGraph(navController=navController, registerScreenViewModel,entryScreenViewModel,currentUserViewModel, lessonListViewModel) composable(route=Graph.MAIN, arguments = listOf(navArgument(USERID_ARGUMENT){ type= NavType.StringType diff --git a/app/src/main/java/com/example/myapplication/HomeView.kt b/app/src/main/java/com/example/myapplication/HomeView.kt index d68e61d..8e7e605 100644 --- a/app/src/main/java/com/example/myapplication/HomeView.kt +++ b/app/src/main/java/com/example/myapplication/HomeView.kt @@ -28,6 +28,7 @@ import androidx.navigation.NavHostController import androidx.navigation.compose.rememberNavController import com.example.myapplication.Graph.BottomBar import com.example.myapplication.Graph.HomeNavGraph +import com.example.myapplication.ui.lesson.LessonListViewModel import com.example.myapplication.ui.theme.PmudemoTheme import com.example.myapplication.ui.user.CurrentUserViewModel diff --git a/app/src/main/java/com/example/myapplication/MainComposeActivity.kt b/app/src/main/java/com/example/myapplication/MainComposeActivity.kt index f250e9f..7f57a37 100644 --- a/app/src/main/java/com/example/myapplication/MainComposeActivity.kt +++ b/app/src/main/java/com/example/myapplication/MainComposeActivity.kt @@ -11,7 +11,6 @@ import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.compose.rememberNavController import com.example.myapplication.Graph.RootNavigationGraph import com.example.myapplication.ui.AppViewModelProvider -import com.example.myapplication.ui.navigation.MainNavbar import com.example.myapplication.ui.theme.PmudemoTheme class MainComposeActivity : ComponentActivity() { diff --git a/app/src/main/java/com/example/myapplication/Profile.kt b/app/src/main/java/com/example/myapplication/Profile.kt index e46fc5d..d799d0d 100644 --- a/app/src/main/java/com/example/myapplication/Profile.kt +++ b/app/src/main/java/com/example/myapplication/Profile.kt @@ -42,15 +42,17 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp 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.ui.AppViewModelProvider +import com.example.myapplication.ui.lesson.LessonListViewModel import com.example.myapplication.ui.user.CurrentUserViewModel import kotlinx.coroutines.launch @SuppressLint("UnrememberedMutableState") @OptIn(ExperimentalMaterial3Api::class) @Composable -fun Profile(navController: NavController, modifier: Modifier = Modifier, 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)) { val context = LocalContext.current var getUser by remember { mutableStateOf(currentUserViewModel.user) } @@ -60,9 +62,12 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current var userName by remember { mutableStateOf(getUser?.userName) } var password by remember { mutableStateOf(getUser?.password) } var fio by remember { mutableStateOf(getUser?.fio) } - - // Вывод лога о параметрах пользователя - Log.d("Profile", "userName: $userName, password: $password, fio: $fio") + val lessonId = getUser?.lessonId + var userLessonText by remember { mutableStateOf("Записи нет") } + lessonListViewModel.getUserLesson(lessonId).observeForever { lesson -> + userLessonText = lesson?.time ?: "Записи нет" + } + Log.d("Profile11", "getUserLesson: $userLessonText") if (openDialogUser) { AlertDialog( @@ -169,7 +174,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current LazyColumn( modifier = modifier .requiredWidth(width = 412.dp) - .requiredHeight(height = 605.dp) + .requiredHeight(height = 640.dp) .background(color = Color.White) ) { item { @@ -177,7 +182,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current modifier = Modifier .offset( x = 9.dp, - y = 80.dp + y = 60.dp ) .requiredWidth(width = 393.dp) .requiredHeight(height = 70.dp) @@ -224,7 +229,7 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current modifier = Modifier .offset( x = 106.dp, - y = 95.dp + y = 60.dp ) .requiredWidth(width = 200.dp) .requiredHeight(height = 310.dp) @@ -324,16 +329,16 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current .wrapContentHeight(align = Alignment.CenterVertically) .clickable { openDialogUser = true }) } - Box( - modifier = Modifier - .align(alignment = Alignment.TopStart) - .offset( - x = 0.dp, - y = 300.dp - ) - .requiredWidth(width = 200.dp) - .requiredHeight(height = 44.dp) - ) +// Box( +// modifier = Modifier +// .align(alignment = Alignment.TopStart) +// .offset( +// x = 0.dp, +// y = 300.dp +// ) +// .requiredWidth(width = 200.dp) +// .requiredHeight(height = 44.dp) +// ) // { // Box( // modifier = Modifier @@ -362,8 +367,8 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current Box( modifier = Modifier .offset( - x = 9.dp, - y = 220.dp + x = 0.dp, + y = 20.dp ) .requiredWidth(width = 393.dp) .requiredHeight(height = 70.dp) @@ -406,10 +411,10 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current modifier = Modifier .offset( x = 9.dp, - y = 220.dp + y = 10.dp ) .requiredWidth(width = 393.dp) - .requiredHeight(height = 70.dp) + .requiredHeight(height = 100.dp) ) { Box( modifier = Modifier @@ -430,11 +435,11 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current ) Text( - text = "${getUser?.lessonId}", + text = userLessonText, color = Color.Black, textAlign = TextAlign.Center, style = TextStyle( - fontSize = 20.sp, + fontSize = 16.sp, fontWeight = FontWeight.Bold ), modifier = Modifier @@ -442,11 +447,51 @@ fun Profile(navController: NavController, modifier: Modifier = Modifier, current .padding(16.dp) .background(Color.LightGray) .requiredWidth(300.dp) - .requiredWidth(70.dp) ) } + Box( + modifier = Modifier + .align(alignment = Alignment.TopStart) + .offset( + x = 0.dp, + y = 75.dp + ) + .requiredWidth(width = 393.dp) + .requiredHeight(height = 44.dp) + ) { + 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) + .requiredHeight(height = 44.dp) + .wrapContentHeight(align = Alignment.CenterVertically) + .align(Alignment.Center) + .clickable(onClick = { + getUser?.lessonId = null + coroutineScope.launch { + getUser?.let { + currentUserViewModel.updateUser(it) + } + } + }) + ) + } } + } } } diff --git a/app/src/main/java/com/example/myapplication/api/model/LessonRemote.kt b/app/src/main/java/com/example/myapplication/api/model/LessonRemote.kt index e2e24f1..8cf2d1e 100644 --- a/app/src/main/java/com/example/myapplication/api/model/LessonRemote.kt +++ b/app/src/main/java/com/example/myapplication/api/model/LessonRemote.kt @@ -11,7 +11,8 @@ data class LessonRemote( val classNumber: Int = 0, val dayOfWeekId: Int = 0, - val directionId: Int = 0 + val directionId: Int = 0, + val countRecord: Int = 0 ) @@ -22,6 +23,7 @@ fun LessonRemote.toLesson(): Lesson = Lesson( classNumber, dayOfWeekId, directionId, + countRecord ) fun Lesson.toLessonRemote(): LessonRemote = LessonRemote( @@ -30,5 +32,6 @@ fun Lesson.toLessonRemote(): LessonRemote = LessonRemote( time, classNumber, dayOfWeekId, - directionId + directionId, + countRecord ) \ No newline at end of file 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 68bade8..65a9e6c 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 = "pmy-dbbbb4" + private const val DB_NAME: String = "pmy-dbbbb5" @Volatile private var INSTANCE: AppDatabase? = null @@ -68,11 +68,11 @@ abstract class AppDatabase : RoomDatabase() { directionDao.insert(direction6) // Lessons val lessonDao = database.lessonDao() - val lesson1 = Lesson(1, "Anna", "9.00", 1, 1, 1) - val lesson2 = Lesson(2, "Elena", "10.00", 2, 1, 2) - val lesson3 = Lesson(3, "Anastasia", "18.00", 3, 2, 3) - val lesson4 = Lesson(4, "Vika", "9.00", 4, 3, 4) - val lesson5 = Lesson(5, "Tatyana", "11.00", 3, 5, 6) + val lesson1 = Lesson(1, "Anna", "9.00", 1, 1, 1, 10) + val lesson2 = Lesson(2, "Elena", "10.00", 2, 1, 2, 3) + val lesson3 = Lesson(3, "Anastasia", "18.00", 3, 2, 3, 2) + val lesson4 = Lesson(4, "Vika", "9.00", 4, 3, 4, 15) + val lesson5 = Lesson(5, "Tatyana", "11.00", 3, 5, 6, 7) lessonDao.insert(lesson1) lessonDao.insert(lesson2) lessonDao.insert(lesson3) diff --git a/app/src/main/java/com/example/myapplication/dataBase/model/Lesson.kt b/app/src/main/java/com/example/myapplication/dataBase/model/Lesson.kt index 8ca56df..54bdb65 100644 --- a/app/src/main/java/com/example/myapplication/dataBase/model/Lesson.kt +++ b/app/src/main/java/com/example/myapplication/dataBase/model/Lesson.kt @@ -35,7 +35,9 @@ data class Lesson( @ColumnInfo(name = "day_id", index = true) val dayOfWeekId: Int, @ColumnInfo(name = "direction_id", index = true) - val directionId: Int + val directionId: Int, + @ColumnInfo(name = "count_record", index = true) + val countRecord: Int ) { override fun equals(other: Any?): Boolean { @@ -58,7 +60,8 @@ data class Lesson( "9.00", 1, 1, - 1 + 1, + 10 ) } } diff --git a/app/src/main/java/com/example/myapplication/dataBase/model/User.kt b/app/src/main/java/com/example/myapplication/dataBase/model/User.kt index 1cb1825..e713ca0 100644 --- a/app/src/main/java/com/example/myapplication/dataBase/model/User.kt +++ b/app/src/main/java/com/example/myapplication/dataBase/model/User.kt @@ -25,7 +25,7 @@ data class User( @ColumnInfo(name = "role") val role: RoleEnum, @ColumnInfo(name = "lesson_id", index = true) - val lessonId: Int? + var lessonId: Int? ) { override fun equals(other: Any?): Boolean { if (this === other) return true diff --git a/app/src/main/java/com/example/myapplication/ui/edit/LessonEdit.kt b/app/src/main/java/com/example/myapplication/ui/edit/LessonEdit.kt index 4a8c4a2..9a36067 100644 --- a/app/src/main/java/com/example/myapplication/ui/edit/LessonEdit.kt +++ b/app/src/main/java/com/example/myapplication/ui/edit/LessonEdit.kt @@ -44,13 +44,11 @@ fun LessonEdit( navController: NavController, viewModel: LessonEditViewModel = viewModel(factory = AppViewModelProvider.Factory), directionViewModel: DirectionDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory), - dayViewModel: DayDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory), - currentUserViewModel: CurrentUserViewModel = viewModel(factory = AppViewModelProvider.Factory) + dayViewModel: DayDropDownViewModel = viewModel(factory = AppViewModelProvider.Factory) ) { val coroutineScope = rememberCoroutineScope() directionViewModel.setCurrentDirection(viewModel.lessonUiState.lessonDetails.directionId) dayViewModel.setCurrentDayOfWeek(viewModel.lessonUiState.lessonDetails.dayOfWeekId) - var getUser by remember { mutableStateOf(currentUserViewModel.user) } LessonEdit( lessonUiState = viewModel.lessonUiState, directionUiState = directionViewModel.directionUiState, @@ -59,12 +57,10 @@ fun LessonEdit( daysUiState = dayViewModel.dayOfWeekUiState, daysListUiState = dayViewModel.daysListUiState, onClick = { - if (getUser?.role == RoleEnum.Admin) { coroutineScope.launch { viewModel.saveLesson() navController.popBackStack() } - } }, onUpdate = viewModel::updateUiState, onDirectionUpdate = directionViewModel::updateUiState, @@ -227,6 +223,13 @@ private fun LessonEdit( onDayUpdate(it) } ) + 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 + ) Button( onClick = onClick, enabled = lessonUiState.isEntryValid, diff --git a/app/src/main/java/com/example/myapplication/ui/edit/LessonEditViewModel.kt b/app/src/main/java/com/example/myapplication/ui/edit/LessonEditViewModel.kt index f830dcf..2a9fac7 100644 --- a/app/src/main/java/com/example/myapplication/ui/edit/LessonEditViewModel.kt +++ b/app/src/main/java/com/example/myapplication/ui/edit/LessonEditViewModel.kt @@ -38,6 +38,9 @@ class LessonEditViewModel( ) } + fun getUidLesson(): Int{ + return lessonUid + } suspend fun saveLesson() { if (validateInput()) { if (lessonUid > 0) { @@ -55,6 +58,7 @@ class LessonEditViewModel( && classNumber > 0 && directionId > 0 && dayOfWeekId > 0 + && countRecord > 0 } } } @@ -69,7 +73,8 @@ data class LessonDetails( val time: String = "", val classNumber: Int = 0, val directionId: Int = 0, - val dayOfWeekId: Int = 0 + val dayOfWeekId: Int = 0, + val countRecord: Int = 0 ) fun LessonDetails.toLesson(uid: Int = 0): Lesson = Lesson( @@ -78,7 +83,8 @@ fun LessonDetails.toLesson(uid: Int = 0): Lesson = Lesson( time = time, classNumber = classNumber, directionId = directionId, - dayOfWeekId = dayOfWeekId + dayOfWeekId = dayOfWeekId, + countRecord = countRecord ) fun Lesson.toDetails(): LessonDetails = LessonDetails( @@ -86,7 +92,8 @@ fun Lesson.toDetails(): LessonDetails = LessonDetails( time = time, classNumber = classNumber, directionId = directionId, - dayOfWeekId = dayOfWeekId + dayOfWeekId = dayOfWeekId, + countRecord = countRecord ) fun Lesson.toUiState(isEntryValid: Boolean = false): LessonUiState = LessonUiState( 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 c7b19ef..a6e9eef 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 @@ -1,21 +1,14 @@ package com.example.myapplication.ui.edit -import android.content.res.Configuration -import androidx.compose.foundation.background +import android.util.Log import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.material3.Button -import androidx.compose.material3.DropdownMenu -import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.ExposedDropdownMenuBox -import androidx.compose.material3.ExposedDropdownMenuDefaults import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField -import androidx.compose.material3.Surface import androidx.compose.material3.Text -import androidx.compose.material3.TextField import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf @@ -23,19 +16,12 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource -import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavController import com.example.myapplication.R -import com.example.myapplication.dataBase.model.DayOfWeek -import com.example.myapplication.dataBase.model.Direction -import com.example.myapplication.dataBase.model.Lesson -import com.example.myapplication.dataBase.model.RoleEnum import com.example.myapplication.ui.AppViewModelProvider -import com.example.myapplication.ui.theme.PmudemoTheme import com.example.myapplication.ui.user.CurrentUserViewModel import kotlinx.coroutines.launch @@ -48,25 +34,33 @@ fun LessonRecord( ) { val coroutineScope = rememberCoroutineScope() directionViewModel.setCurrentDirection(viewModel.lessonUiState.lessonDetails.directionId) - var getUser by remember { mutableStateOf(currentUserViewModel.user) } - LessonEdit( + val getUser by remember { mutableStateOf(currentUserViewModel.user) } + Log.d("getUserLesson", "gU: $getUser") + val lessonCurId = viewModel.getUidLesson() + LessonRecord( lessonUiState = viewModel.lessonUiState, directionUiState = directionViewModel.directionUiState, onClick = { - if (getUser?.role == RoleEnum.Admin) { - coroutineScope.launch { - viewModel.saveLesson() - navController.popBackStack() + coroutineScope.launch { + 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() } - }, - onUpdate = viewModel::updateUiState - ) + + } + ) {} } @OptIn(ExperimentalMaterial3Api::class) @Composable -private fun LessonEdit( +private fun LessonRecord( lessonUiState: LessonUiState, directionUiState: DirectionUiState, onClick: () -> Unit, @@ -109,9 +103,16 @@ private fun LessonEdit( 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, - enabled = lessonUiState.isEntryValid, shape = MaterialTheme.shapes.small, modifier = Modifier.fillMaxWidth() ) { diff --git a/app/src/main/java/com/example/myapplication/ui/lesson/LessonListViewModel.kt b/app/src/main/java/com/example/myapplication/ui/lesson/LessonListViewModel.kt index 3206afc..ffa3a5f 100644 --- a/app/src/main/java/com/example/myapplication/ui/lesson/LessonListViewModel.kt +++ b/app/src/main/java/com/example/myapplication/ui/lesson/LessonListViewModel.kt @@ -1,6 +1,8 @@ package com.example.myapplication.ui.lesson import androidx.compose.runtime.mutableStateOf +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import androidx.paging.PagingData @@ -24,6 +26,16 @@ class LessonListViewModel( suspend fun deleteLesson(lesson: Lesson) { lessonRepository.deleteLesson(lesson) } + fun getUserLesson(uid: Int?): LiveData { + val userLessonLiveData = MutableLiveData() + + viewModelScope.launch { + val lesson = uid?.let { lessonRepository.getLesson(it) } + userLessonLiveData.value = lesson + } + + return userLessonLiveData + } } //class LessonListViewModel(private val lessonRepository: LessonRepository): ViewModel() { diff --git a/app/src/main/java/com/example/myapplication/ui/navigation/MainNavbar.kt b/app/src/main/java/com/example/myapplication/ui/navigation/MainNavbar.kt index c9bf862..a60f661 100644 --- a/app/src/main/java/com/example/myapplication/ui/navigation/MainNavbar.kt +++ b/app/src/main/java/com/example/myapplication/ui/navigation/MainNavbar.kt @@ -46,125 +46,125 @@ import com.example.myapplication.ui.edit.LessonEdit import com.example.myapplication.ui.lesson.LessonList import com.example.myapplication.ui.theme.PmudemoTheme -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun Topbar( - navController: NavHostController, - currentScreen: Screen? -) { - TopAppBar( - colors = TopAppBarDefaults.smallTopAppBarColors( - containerColor = MaterialTheme.colorScheme.primary, - titleContentColor = MaterialTheme.colorScheme.onPrimary, - ), - title = { - Text(stringResource(currentScreen?.resourceId ?: R.string.app_name)) - }, - navigationIcon = { - if ( - navController.previousBackStackEntry != null - && (currentScreen == null || !currentScreen.showInBottomBar) - ) { - IconButton(onClick = { navController.navigateUp() }) { - Icon( - imageVector = Icons.Filled.ArrowBack, - contentDescription = null, - tint = MaterialTheme.colorScheme.onPrimary - ) - } - } - } - ) -} - -@Composable -fun Navbar( - navController: NavHostController, - currentDestination: NavDestination?, - modifier: Modifier = Modifier -) { - NavigationBar(modifier) { - Screen.bottomBarItems.forEach { screen -> - NavigationBarItem( - icon = { Icon(screen.icon, contentDescription = null) }, - label = { Text(stringResource(screen.resourceId)) }, - selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true, - onClick = { - navController.navigate(screen.route) { - popUpTo(navController.graph.findStartDestination().id) { - saveState = true - } - launchSingleTop = true - restoreState = true - } - } - ) - } - } -} - -@Composable -fun Navhost( - navController: NavHostController, - innerPadding: PaddingValues, modifier: - Modifier = Modifier -) { - NavHost( - navController, - startDestination = Screen.HomeView.route, - modifier.padding(innerPadding) - ) { - composable(Screen.LessonList.route) { LessonList(navController) } - composable(Screen.About.route) { About() } - composable(Screen.HomeView.route) { HomeView(navController) } - composable(Screen.Registration.route) { Registration(navController) } - composable(Screen.House.route) { House() } - composable(Screen.Contemp.route) { Contemp() } - composable(Screen.BrDance.route) { BrDance() } - composable(Screen.Kpop.route) { Kpop() } - composable(Screen.Enter.route) { Enter(navController) } - composable(Screen.DirectionView.route) { DirectionView(navController) } - composable(Screen.Profile.route) { Profile(navController) } - composable( - Screen.LessonEdit.route, - arguments = listOf(navArgument("id") { type = NavType.IntType }) - ) { - LessonEdit(navController) - } - } -} - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun MainNavbar() { - val navController = rememberNavController() - val navBackStackEntry by navController.currentBackStackEntryAsState() - val currentDestination = navBackStackEntry?.destination - val currentScreen = currentDestination?.route?.let { Screen.getItem(it) } - - Scaffold( - topBar = { - Topbar(navController, currentScreen) - }, - bottomBar = { - if (currentScreen == null || currentScreen.showInBottomBar) { - Navbar(navController, currentDestination) - } - } - ) { innerPadding -> - Navhost(navController, innerPadding) - } -} - -@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) -@Composable -fun MainNavbarPreview() { - PmudemoTheme { - Surface( - color = MaterialTheme.colorScheme.background - ) { - MainNavbar() - } - } -} \ No newline at end of file +//@OptIn(ExperimentalMaterial3Api::class) +//@Composable +//fun Topbar( +// navController: NavHostController, +// currentScreen: Screen? +//) { +// TopAppBar( +// colors = TopAppBarDefaults.smallTopAppBarColors( +// containerColor = MaterialTheme.colorScheme.primary, +// titleContentColor = MaterialTheme.colorScheme.onPrimary, +// ), +// title = { +// Text(stringResource(currentScreen?.resourceId ?: R.string.app_name)) +// }, +// navigationIcon = { +// if ( +// navController.previousBackStackEntry != null +// && (currentScreen == null || !currentScreen.showInBottomBar) +// ) { +// IconButton(onClick = { navController.navigateUp() }) { +// Icon( +// imageVector = Icons.Filled.ArrowBack, +// contentDescription = null, +// tint = MaterialTheme.colorScheme.onPrimary +// ) +// } +// } +// } +// ) +//} +// +//@Composable +//fun Navbar( +// navController: NavHostController, +// currentDestination: NavDestination?, +// modifier: Modifier = Modifier +//) { +// NavigationBar(modifier) { +// Screen.bottomBarItems.forEach { screen -> +// NavigationBarItem( +// icon = { Icon(screen.icon, contentDescription = null) }, +// label = { Text(stringResource(screen.resourceId)) }, +// selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true, +// onClick = { +// navController.navigate(screen.route) { +// popUpTo(navController.graph.findStartDestination().id) { +// saveState = true +// } +// launchSingleTop = true +// restoreState = true +// } +// } +// ) +// } +// } +//} +// +//@Composable +//fun Navhost( +// navController: NavHostController, +// innerPadding: PaddingValues, modifier: +// Modifier = Modifier +//) { +// NavHost( +// navController, +// startDestination = Screen.HomeView.route, +// modifier.padding(innerPadding) +// ) { +// composable(Screen.LessonList.route) { LessonList(navController) } +// composable(Screen.About.route) { About() } +// composable(Screen.HomeView.route) { HomeView(navController) } +// composable(Screen.Registration.route) { Registration(navController) } +// composable(Screen.House.route) { House() } +// composable(Screen.Contemp.route) { Contemp() } +// composable(Screen.BrDance.route) { BrDance() } +// composable(Screen.Kpop.route) { Kpop() } +// composable(Screen.Enter.route) { Enter(navController) } +// composable(Screen.DirectionView.route) { DirectionView(navController) } +// composable(Screen.Profile.route) { Profile(navController) } +// composable( +// Screen.LessonEdit.route, +// arguments = listOf(navArgument("id") { type = NavType.IntType }) +// ) { +// LessonEdit(navController) +// } +// } +//} +// +//@OptIn(ExperimentalMaterial3Api::class) +//@Composable +//fun MainNavbar() { +// val navController = rememberNavController() +// val navBackStackEntry by navController.currentBackStackEntryAsState() +// val currentDestination = navBackStackEntry?.destination +// val currentScreen = currentDestination?.route?.let { Screen.getItem(it) } +// +// Scaffold( +// topBar = { +// Topbar(navController, currentScreen) +// }, +// bottomBar = { +// if (currentScreen == null || currentScreen.showInBottomBar) { +// Navbar(navController, currentDestination) +// } +// } +// ) { innerPadding -> +// Navhost(navController, innerPadding) +// } +//} +// +//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES) +//@Composable +//fun MainNavbarPreview() { +// PmudemoTheme { +// Surface( +// color = MaterialTheme.colorScheme.background +// ) { +// MainNavbar() +// } +// } +//} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/ui/user/CurrentUserViewModel.kt b/app/src/main/java/com/example/myapplication/ui/user/CurrentUserViewModel.kt index 2c1d459..6ba24d3 100644 --- a/app/src/main/java/com/example/myapplication/ui/user/CurrentUserViewModel.kt +++ b/app/src/main/java/com/example/myapplication/ui/user/CurrentUserViewModel.kt @@ -25,4 +25,5 @@ class CurrentUserViewModel(private val userRepository: UserRepository) : ViewMod suspend fun updateUser(user: User) { userRepository.updateUser(user) } + } \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e18c6c1..e930f21 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,6 +6,7 @@ Тренер Группа Зал + Количество мест День недели Направление Занятий нет diff --git a/server/data.json b/server/data.json index e65ed90..300f549 100644 --- a/server/data.json +++ b/server/data.json @@ -62,7 +62,8 @@ "time": "9.00-10.00", "classNumber": 2, "directionId": 1, - "dayOfWeekId": 1 + "dayOfWeekId": 1, + "countRecord": 7 }, { "id": 3, @@ -70,7 +71,8 @@ "time": "17.00-18.00", "classNumber": 3, "directionId": 3, - "dayOfWeekId": 2 + "dayOfWeekId": 2, + "countRecord": 3 }, { "id": 4, @@ -78,7 +80,17 @@ "time": "9.00-12.30", "classNumber": 6, "directionId": 3, - "dayOfWeekId": 3 + "dayOfWeekId": 3, + "countRecord": 4 + }, + { + "id": 5, + "teacher": "Илона", + "time": "8.00-9.00", + "classNumber": 6, + "dayOfWeekId": 5, + "directionId": 1, + "countRecord": 7 } ], "users": [ @@ -88,7 +100,7 @@ "fio": "Анна Викторовна Сомова", "password": "1234", "role": "Admin", - "lessonId": null + "lessonId": 1 }, { "id": 2, @@ -96,7 +108,7 @@ "fio": "Илья Петрович Мунин", "password": "5678", "role": "User", - "lessonId": null + "lessonId": 3 }, { "id": 3, @@ -104,7 +116,7 @@ "fio": "Мария Денисовна Амова", "password": "13579", "role": "User", - "lessonId": null + "lessonId": 3 }, { "id": 7,