Лаб 2 нало работы с пользователем
This commit is contained in:
parent
555dca89be
commit
4d537f08f0
BIN
.gradle/8.0/checksums/md5-checksums.bin
Normal file
BIN
.gradle/8.0/checksums/md5-checksums.bin
Normal file
Binary file not shown.
BIN
.gradle/8.0/checksums/sha1-checksums.bin
Normal file
BIN
.gradle/8.0/checksums/sha1-checksums.bin
Normal file
Binary file not shown.
BIN
.gradle/8.0/executionHistory/executionHistory.bin
Normal file
BIN
.gradle/8.0/executionHistory/executionHistory.bin
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
.gradle/8.0/fileHashes/resourceHashesCache.bin
Normal file
BIN
.gradle/8.0/fileHashes/resourceHashesCache.bin
Normal file
Binary file not shown.
Binary file not shown.
BIN
.gradle/file-system.probe
Normal file
BIN
.gradle/file-system.probe
Normal file
Binary file not shown.
@ -9,29 +9,19 @@
|
|||||||
<option name="autoReloadType" value="NONE" />
|
<option name="autoReloadType" value="NONE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="dc3793c7-c725-42e8-8eda-044c95f334c1" name="Changes" comment="добавление отчета лаб 1">
|
<list default="true" id="dc3793c7-c725-42e8-8eda-044c95f334c1" name="Changes" comment="Лаб 2 начало">
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Home.kt" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/model/AuthViewModel.kt" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Login.kt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Profile.kt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/navigation/Screen.kt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.gradle/8.0/checksums/checksums.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/checksums/checksums.lock" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.gradle/8.0/executionHistory/executionHistory.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/executionHistory/executionHistory.lock" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.gradle/8.0/executionHistory/executionHistory.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/executionHistory/executionHistory.lock" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.bin" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.bin" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.bin" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.bin" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.lock" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/8.0/fileHashes/fileHashes.lock" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/buildOutputCleanup.lock" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.gradle/buildOutputCleanup/outputFiles.bin" beforeDir="false" afterPath="$PROJECT_DIR$/.gradle/buildOutputCleanup/outputFiles.bin" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/gradle.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/gradle.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/app/build.gradle.kts" beforeDir="false" afterPath="$PROJECT_DIR$/app/build.gradle.kts" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Login.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Login.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/app/src/main/AndroidManifest.xml" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/AndroidManifest.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Profile.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/Profile.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/MainActivity.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/MainComposeActivity.kt" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/app/src/main/res/values/strings.xml" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/res/values/strings.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/gradle.properties" beforeDir="false" afterPath="$PROJECT_DIR$/gradle.properties" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt" beforeDir="false" afterPath="$PROJECT_DIR$/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -101,6 +91,9 @@
|
|||||||
<component name="MarkdownSettingsMigration">
|
<component name="MarkdownSettingsMigration">
|
||||||
<option name="stateVersion" value="1" />
|
<option name="stateVersion" value="1" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="ProblemsViewState">
|
||||||
|
<option name="selectedTabId" value="CurrentFile" />
|
||||||
|
</component>
|
||||||
<component name="ProjectId" id="2WToW0mvjPzND9QiCAmC6MXKLwF" />
|
<component name="ProjectId" id="2WToW0mvjPzND9QiCAmC6MXKLwF" />
|
||||||
<component name="ProjectLevelVcsManager">
|
<component name="ProjectLevelVcsManager">
|
||||||
<ConfirmationsSetting value="2" id="Add" />
|
<ConfirmationsSetting value="2" id="Add" />
|
||||||
@ -226,7 +219,14 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1696766847352</updated>
|
<updated>1696766847352</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="3" />
|
<task id="LOCAL-00003" summary="Лаб 2 начало">
|
||||||
|
<created>1697038354150</created>
|
||||||
|
<option name="number" value="00003" />
|
||||||
|
<option name="presentableId" value="LOCAL-00003" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1697038354150</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="4" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
@ -256,6 +256,7 @@
|
|||||||
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
|
||||||
<MESSAGE value="коммит1" />
|
<MESSAGE value="коммит1" />
|
||||||
<MESSAGE value="добавление отчета лаб 1" />
|
<MESSAGE value="добавление отчета лаб 1" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="добавление отчета лаб 1" />
|
<MESSAGE value="Лаб 2 начало" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Лаб 2 начало" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@ -31,17 +32,22 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
|
import androidx.navigation.NavHostController
|
||||||
import com.example.pmuapp.R
|
import com.example.pmuapp.R
|
||||||
import com.example.pmuapp.composeui.navigation.Screen
|
import com.example.pmuapp.composeui.navigation.Screen
|
||||||
import com.example.pmuapp.models.user.model.getStudents
|
import com.example.pmuapp.models.user.model.AuthViewModel
|
||||||
|
import com.example.pmuapp.models.user.model.User
|
||||||
import com.example.pmuapp.ui.theme.PMUappTheme
|
import com.example.pmuapp.ui.theme.PMUappTheme
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun Login(navController: NavController) {
|
fun Login(
|
||||||
|
navController: NavHostController,
|
||||||
|
authViewModel: AuthViewModel,
|
||||||
|
users: List<User> // Используйте ViewModel как параметр
|
||||||
|
) {
|
||||||
var username by remember { mutableStateOf("") }
|
var username by remember { mutableStateOf("") }
|
||||||
var password by remember { mutableStateOf("") }
|
var password by remember { mutableStateOf("") }
|
||||||
val users = getStudents()
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@ -69,17 +75,15 @@ fun Login(navController: NavController) {
|
|||||||
.padding(bottom = 16.dp)
|
.padding(bottom = 16.dp)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp)) // Промежуток
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
// Check if the entered username and password match a user
|
|
||||||
val authenticatedUser = users.find { it.login == username && it.password == password }
|
val authenticatedUser = users.find { it.login == username && it.password == password }
|
||||||
if (authenticatedUser != null) {
|
if (authenticatedUser != null) {
|
||||||
// Navigate to the Home screen if authentication is successful
|
authViewModel.currentUser = authenticatedUser
|
||||||
navController.navigate(Screen.Home.route)
|
navController.navigate(Screen.Profile.route)
|
||||||
} else {
|
} else {
|
||||||
// Show an error message or handle authentication failure
|
|
||||||
// For example, display a Toast or Text message
|
|
||||||
// For simplicity, we'll just print a message
|
|
||||||
println("Authentication failed")
|
println("Authentication failed")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -91,7 +95,6 @@ fun Login(navController: NavController) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
//@Composable
|
//@Composable
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.example.pmuapp.composeui
|
package com.example.pmuapp.composeui
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
@ -8,16 +9,22 @@ import android.widget.TextView
|
|||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
@ -25,28 +32,61 @@ import com.example.pmuapp.R
|
|||||||
import com.example.pmuapp.models.user.model.User
|
import com.example.pmuapp.models.user.model.User
|
||||||
import com.example.pmuapp.ui.theme.PMUappTheme
|
import com.example.pmuapp.ui.theme.PMUappTheme
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@SuppressLint("RememberReturnType")
|
||||||
@Composable
|
@Composable
|
||||||
fun Profile(user: User) {
|
fun Profile(currentUser: User?, onSaveClick: (User) -> Unit) {
|
||||||
val localContext = LocalContext.current
|
val nameState = remember { mutableStateOf(currentUser?.name.orEmpty()) }
|
||||||
|
val loginState = remember { mutableStateOf(currentUser?.login.orEmpty()) }
|
||||||
|
val passwordState = remember { mutableStateOf(currentUser?.password.orEmpty()) }
|
||||||
|
|
||||||
val urlOnClick = {
|
Column(
|
||||||
val openURL = Intent(Intent.ACTION_VIEW)
|
modifier = Modifier
|
||||||
openURL.data = Uri.parse("https://ulstu.ru/")
|
.fillMaxSize()
|
||||||
localContext.startActivity(openURL)
|
.padding(16.dp)
|
||||||
}
|
) {
|
||||||
|
TextField(
|
||||||
Column(Modifier.padding(all = 10.dp)) {
|
value = nameState.value,
|
||||||
Text("Name: ${user.name}")
|
onValueChange = { nameState.value = it },
|
||||||
Text("Login: ${user.login}")
|
label = { Text("Name") },
|
||||||
Text("Password: ${user.password}")
|
|
||||||
|
|
||||||
Spacer(Modifier.padding(bottom = 10.dp))
|
|
||||||
AndroidView(
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable(onClick = urlOnClick),
|
.padding(bottom = 16.dp)
|
||||||
factory = { context -> TextView(context) },
|
|
||||||
update = { it.text = R.string.app_name.toString() }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
TextField(
|
||||||
|
value = loginState.value,
|
||||||
|
onValueChange = { loginState.value = it },
|
||||||
|
label = { Text("Login") },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(bottom = 16.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
TextField(
|
||||||
|
value = passwordState.value,
|
||||||
|
onValueChange = { passwordState.value = it },
|
||||||
|
label = { Text("Password") },
|
||||||
|
visualTransformation = PasswordVisualTransformation(),
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(bottom = 16.dp)
|
||||||
|
)
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
val updatedUser = User(
|
||||||
|
nameState.value,
|
||||||
|
loginState.value,
|
||||||
|
passwordState.value
|
||||||
|
)
|
||||||
|
onSaveClick(updatedUser) // Вызывает функцию updateUser в UserViewModel
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text("Save")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import androidx.compose.material3.TopAppBar
|
|||||||
import androidx.compose.material3.TopAppBarDefaults
|
import androidx.compose.material3.TopAppBarDefaults
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
@ -35,9 +36,11 @@ import com.example.pmuapp.R
|
|||||||
import com.example.pmuapp.composeui.Home
|
import com.example.pmuapp.composeui.Home
|
||||||
import com.example.pmuapp.composeui.Login
|
import com.example.pmuapp.composeui.Login
|
||||||
import com.example.pmuapp.composeui.Profile
|
import com.example.pmuapp.composeui.Profile
|
||||||
import com.example.pmuapp.models.user.composeui.UserList
|
|
||||||
import com.example.pmuapp.models.user.composeui.StudentView
|
import com.example.pmuapp.models.user.composeui.StudentView
|
||||||
|
import com.example.pmuapp.models.user.composeui.UserList
|
||||||
|
import com.example.pmuapp.models.user.model.AuthViewModel
|
||||||
import com.example.pmuapp.models.user.model.User
|
import com.example.pmuapp.models.user.model.User
|
||||||
|
import com.example.pmuapp.models.user.model.UserViewModel
|
||||||
import com.example.pmuapp.ui.theme.PMUappTheme
|
import com.example.pmuapp.ui.theme.PMUappTheme
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@ -98,33 +101,37 @@ fun Navbar(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun Navhost(
|
fun NavHost(
|
||||||
navController: NavHostController,
|
navController: NavHostController,
|
||||||
innerPadding: PaddingValues, modifier:
|
innerPadding: PaddingValues,
|
||||||
Modifier = Modifier
|
authViewModel: AuthViewModel, // Передайте AuthViewModel как параметр
|
||||||
|
userViewModel: UserViewModel // Передайте UserViewModel как параметр
|
||||||
) {
|
) {
|
||||||
NavHost(
|
NavHost(
|
||||||
navController,
|
navController = navController,
|
||||||
startDestination = Screen.Login.route,
|
startDestination = Screen.Login.route,
|
||||||
modifier.padding(innerPadding)
|
modifier = Modifier.padding(innerPadding)
|
||||||
) {
|
) {
|
||||||
composable(Screen.UserList.route) { UserList(navController) }
|
composable(Screen.Login.route) {
|
||||||
composable(Screen.Home.route) { Home() }
|
Login(navController, authViewModel,userViewModel.getUsers())
|
||||||
composable(Screen.Profile.route + "/{name}/{username}/{password}") { backStackEntry ->
|
|
||||||
val name = backStackEntry.arguments?.getString("name")
|
|
||||||
val username = backStackEntry.arguments?.getString("username")
|
|
||||||
val password = backStackEntry.arguments?.getString("password")
|
|
||||||
if (name != null && username != null && password != null) {
|
|
||||||
val user = User(name, username, password)
|
|
||||||
Profile(user)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
composable(Screen.Login.route) { Login(navController) }
|
composable(Screen.Profile.route) {
|
||||||
|
Profile(
|
||||||
|
currentUser = authViewModel.currentUser,
|
||||||
|
onSaveClick = { updatedUser ->
|
||||||
|
userViewModel.updateUser(updatedUser)
|
||||||
|
authViewModel.currentUser=updatedUser// Обновление пользователя в ViewModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
composable(Screen.UserList.route) { UserList(navController, userViewModel.getUsers()) }
|
||||||
|
composable(Screen.Home.route) { Home() }
|
||||||
composable(
|
composable(
|
||||||
Screen.UserView.route,
|
Screen.UserView.route,
|
||||||
arguments = listOf(navArgument("id") { type = NavType.IntType })
|
arguments = listOf(navArgument("id") { type = NavType.IntType })
|
||||||
) { backStackEntry ->
|
) { backStackEntry ->
|
||||||
backStackEntry.arguments?.let { StudentView(it.getInt("id")) }
|
backStackEntry.arguments?.let { StudentView(userViewModel.getUsers()[it.getInt("id")]) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,6 +140,8 @@ fun Navhost(
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainNavbar() {
|
fun MainNavbar() {
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
|
val authViewModel = remember { AuthViewModel() }
|
||||||
|
val userViewModel =UserViewModel() // Создайте экземпляр AuthViewModel
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
val currentDestination = navBackStackEntry?.destination
|
val currentDestination = navBackStackEntry?.destination
|
||||||
val currentScreen = currentDestination?.route?.let { Screen.getItem(it) }
|
val currentScreen = currentDestination?.route?.let { Screen.getItem(it) }
|
||||||
@ -147,8 +156,8 @@ fun MainNavbar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
Navhost(navController, innerPadding)
|
NavHost(navController, innerPadding, authViewModel, userViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
|
@ -15,32 +15,32 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.example.pmuapp.R
|
import com.example.pmuapp.R
|
||||||
import com.example.pmuapp.models.user.model.getStudents
|
import com.example.pmuapp.models.user.model.User
|
||||||
import com.example.pmuapp.ui.theme.PMUappTheme
|
import com.example.pmuapp.ui.theme.PMUappTheme
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun StudentView(id: Int) {
|
fun StudentView(user: User) {
|
||||||
val student = getStudents()[id]
|
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 10.dp)
|
.padding(all = 10.dp)
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||||
value = student.name, onValueChange = {}, readOnly = true,
|
value = user.name, onValueChange = {}, readOnly = true,
|
||||||
label = {
|
label = {
|
||||||
Text(stringResource(id = R.string.user_name))
|
Text(stringResource(id = R.string.user_name))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||||
value = student.login, onValueChange = {}, readOnly = true,
|
value = user.login, onValueChange = {}, readOnly = true,
|
||||||
label = {
|
label = {
|
||||||
Text(stringResource(id = R.string.user_login))
|
Text(stringResource(id = R.string.user_login))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
|
||||||
value = student.password, onValueChange = {}, readOnly = true,
|
value = user.password, onValueChange = {}, readOnly = true,
|
||||||
label = {
|
label = {
|
||||||
Text(stringResource(id = R.string.user_login))
|
Text(stringResource(id = R.string.user_login))
|
||||||
}
|
}
|
||||||
@ -48,15 +48,15 @@ fun StudentView(id: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
@Composable
|
//@Composable
|
||||||
fun StudentViewPreview() {
|
//fun StudentViewPreview() {
|
||||||
PMUappTheme {
|
// PMUappTheme {
|
||||||
Surface(
|
// Surface(
|
||||||
color = MaterialTheme.colorScheme.background
|
// color = MaterialTheme.colorScheme.background
|
||||||
) {
|
// ) {
|
||||||
StudentView(id = 0)
|
// StudentView(id = 0)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -14,34 +14,35 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.example.pmuapp.composeui.navigation.Screen
|
import com.example.pmuapp.composeui.navigation.Screen
|
||||||
import com.example.pmuapp.models.user.model.getStudents
|
import com.example.pmuapp.models.user.model.User
|
||||||
import com.example.pmuapp.ui.theme.PMUappTheme
|
import com.example.pmuapp.ui.theme.PMUappTheme
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UserList(navController: NavController?) {
|
fun UserList(navController: NavController?,
|
||||||
|
users: List<User> ) {
|
||||||
Column(Modifier.padding(all = 10.dp)) {
|
Column(Modifier.padding(all = 10.dp)) {
|
||||||
getStudents().forEachIndexed() { index, student ->
|
users.forEachIndexed() { index, user ->
|
||||||
val studentId = Screen.UserView.route.replace("{id}", index.toString())
|
val userId = Screen.UserView.route.replace("{id}", index.toString())
|
||||||
Button(
|
Button(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 10.dp),
|
.padding(all = 10.dp),
|
||||||
onClick = { navController?.navigate(studentId) }) {
|
onClick = { navController?.navigate(userId) }) {
|
||||||
Text("${student.login}")
|
Text("${user.login}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
//@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
|
||||||
@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
//@Preview(name = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||||
@Composable
|
//@Composable
|
||||||
fun StudentListPreview() {
|
//fun StudentListPreview() {
|
||||||
PMUappTheme {
|
// PMUappTheme {
|
||||||
Surface(
|
// Surface(
|
||||||
color = MaterialTheme.colorScheme.background
|
// color = MaterialTheme.colorScheme.background
|
||||||
) {
|
// ) {
|
||||||
UserList(navController = null)
|
// UserList(navController = null)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.example.pmuapp.models.user.model
|
||||||
|
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
|
|
||||||
|
class AuthViewModel : ViewModel() {
|
||||||
|
var currentUser: User? by mutableStateOf(null)
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package com.example.pmuapp.models.user.model
|
package com.example.pmuapp.models.user.model
|
||||||
|
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.lifecycle.ViewModel
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
data class User(
|
data class User(
|
||||||
@ -8,10 +11,29 @@ data class User(
|
|||||||
val password: String,
|
val password: String,
|
||||||
) : Serializable
|
) : Serializable
|
||||||
|
|
||||||
fun getStudents(): List<User> {
|
class UserViewModel : ViewModel() {
|
||||||
return listOf(
|
var users: MutableState<List<User>> = mutableStateOf(
|
||||||
User("Иван", "ivan", "111111"),
|
listOf(
|
||||||
User("Анна", "ann", "111111"),
|
User("Иван", "ivan", "111111"),
|
||||||
User("Лиза", "liza", "111111")
|
User("Анна", "ann", "111111"),
|
||||||
|
User("Лиза", "liza", "111111")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun getUsers(): List<User> {
|
||||||
|
return users.value
|
||||||
|
}
|
||||||
|
|
||||||
|
fun updateUser(updatedUser: User) {
|
||||||
|
val updatedUsers = users.value.toMutableList()
|
||||||
|
val index = updatedUsers.indexOfFirst { it.login == updatedUser.login }
|
||||||
|
if (index != -1) {
|
||||||
|
updatedUsers[index] = updatedUser
|
||||||
|
users.value = updatedUsers
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user