diff --git a/.gradle/8.0/checksums/md5-checksums.bin b/.gradle/8.0/checksums/md5-checksums.bin
new file mode 100644
index 0000000..1de9280
Binary files /dev/null and b/.gradle/8.0/checksums/md5-checksums.bin differ
diff --git a/.gradle/8.0/checksums/sha1-checksums.bin b/.gradle/8.0/checksums/sha1-checksums.bin
new file mode 100644
index 0000000..4e51bde
Binary files /dev/null and b/.gradle/8.0/checksums/sha1-checksums.bin differ
diff --git a/.gradle/8.0/executionHistory/executionHistory.bin b/.gradle/8.0/executionHistory/executionHistory.bin
new file mode 100644
index 0000000..b5551c7
Binary files /dev/null and b/.gradle/8.0/executionHistory/executionHistory.bin differ
diff --git a/.gradle/8.0/executionHistory/executionHistory.lock b/.gradle/8.0/executionHistory/executionHistory.lock
index 3afa6db..a27065b 100644
Binary files a/.gradle/8.0/executionHistory/executionHistory.lock and b/.gradle/8.0/executionHistory/executionHistory.lock differ
diff --git a/.gradle/8.0/fileHashes/fileHashes.bin b/.gradle/8.0/fileHashes/fileHashes.bin
index 3634d1d..7094f96 100644
Binary files a/.gradle/8.0/fileHashes/fileHashes.bin and b/.gradle/8.0/fileHashes/fileHashes.bin differ
diff --git a/.gradle/8.0/fileHashes/fileHashes.lock b/.gradle/8.0/fileHashes/fileHashes.lock
index b4ef03e..9a28ecc 100644
Binary files a/.gradle/8.0/fileHashes/fileHashes.lock and b/.gradle/8.0/fileHashes/fileHashes.lock differ
diff --git a/.gradle/8.0/fileHashes/resourceHashesCache.bin b/.gradle/8.0/fileHashes/resourceHashesCache.bin
new file mode 100644
index 0000000..dcdab49
Binary files /dev/null and b/.gradle/8.0/fileHashes/resourceHashesCache.bin differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index f581430..cc67cb9 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe
new file mode 100644
index 0000000..f36d629
Binary files /dev/null and b/.gradle/file-system.probe differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 45b4db2..2c3383a 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -9,29 +9,19 @@
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -101,6 +91,9 @@
+
+
+
@@ -226,7 +219,14 @@
1696766847352
-
+
+ 1697038354150
+
+
+
+ 1697038354150
+
+
@@ -256,6 +256,7 @@
-
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/pmuapp/composeui/Login.kt b/app/src/main/java/com/example/pmuapp/composeui/Login.kt
index bb8a244..97bb3c3 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/Login.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/Login.kt
@@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
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.viewinterop.AndroidView
import androidx.navigation.NavController
+import androidx.navigation.NavHostController
import com.example.pmuapp.R
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
@OptIn(ExperimentalMaterial3Api::class)
@Composable
-fun Login(navController: NavController) {
+fun Login(
+ navController: NavHostController,
+ authViewModel: AuthViewModel,
+ users: List // Используйте ViewModel как параметр
+) {
var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
- val users = getStudents()
Column(
modifier = Modifier
@@ -69,17 +75,15 @@ fun Login(navController: NavController) {
.padding(bottom = 16.dp)
)
+ Spacer(modifier = Modifier.height(16.dp)) // Промежуток
+
Button(
onClick = {
- // Check if the entered username and password match a user
val authenticatedUser = users.find { it.login == username && it.password == password }
if (authenticatedUser != null) {
- // Navigate to the Home screen if authentication is successful
- navController.navigate(Screen.Home.route)
+ authViewModel.currentUser = authenticatedUser
+ navController.navigate(Screen.Profile.route)
} 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")
}
},
@@ -91,7 +95,6 @@ fun Login(navController: NavController) {
}
-
//@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
diff --git a/app/src/main/java/com/example/pmuapp/composeui/Profile.kt b/app/src/main/java/com/example/pmuapp/composeui/Profile.kt
index a798509..1d4e847 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/Profile.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/Profile.kt
@@ -1,5 +1,6 @@
package com.example.pmuapp.composeui
+import android.annotation.SuppressLint
import android.content.Intent
import android.content.res.Configuration
import android.net.Uri
@@ -8,16 +9,22 @@ import android.widget.TextView
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
+import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
+import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
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.ui.theme.PMUappTheme
+@OptIn(ExperimentalMaterial3Api::class)
+@SuppressLint("RememberReturnType")
@Composable
-fun Profile(user: User) {
- val localContext = LocalContext.current
+fun Profile(currentUser: User?, onSaveClick: (User) -> Unit) {
+ val nameState = remember { mutableStateOf(currentUser?.name.orEmpty()) }
+ val loginState = remember { mutableStateOf(currentUser?.login.orEmpty()) }
+ val passwordState = remember { mutableStateOf(currentUser?.password.orEmpty()) }
- val urlOnClick = {
- val openURL = Intent(Intent.ACTION_VIEW)
- openURL.data = Uri.parse("https://ulstu.ru/")
- localContext.startActivity(openURL)
- }
-
- Column(Modifier.padding(all = 10.dp)) {
- Text("Name: ${user.name}")
- Text("Login: ${user.login}")
- Text("Password: ${user.password}")
-
- Spacer(Modifier.padding(bottom = 10.dp))
- AndroidView(
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(16.dp)
+ ) {
+ TextField(
+ value = nameState.value,
+ onValueChange = { nameState.value = it },
+ label = { Text("Name") },
modifier = Modifier
.fillMaxWidth()
- .clickable(onClick = urlOnClick),
- factory = { context -> TextView(context) },
- update = { it.text = R.string.app_name.toString() }
+ .padding(bottom = 16.dp)
)
+
+ 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")
+ }
+
}
-}
\ No newline at end of file
+}
+
diff --git a/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt b/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt
index 2c86053..c41bc12 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/navigation/MyPage.kt
@@ -18,6 +18,7 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
+import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
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.Login
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.UserList
+import com.example.pmuapp.models.user.model.AuthViewModel
import com.example.pmuapp.models.user.model.User
+import com.example.pmuapp.models.user.model.UserViewModel
import com.example.pmuapp.ui.theme.PMUappTheme
@OptIn(ExperimentalMaterial3Api::class)
@@ -98,33 +101,37 @@ fun Navbar(
}
@Composable
-fun Navhost(
- navController: NavHostController,
- innerPadding: PaddingValues, modifier:
- Modifier = Modifier
+fun NavHost(
+navController: NavHostController,
+innerPadding: PaddingValues,
+authViewModel: AuthViewModel, // Передайте AuthViewModel как параметр
+userViewModel: UserViewModel // Передайте UserViewModel как параметр
) {
NavHost(
- navController,
+ navController = navController,
startDestination = Screen.Login.route,
- modifier.padding(innerPadding)
+ modifier = Modifier.padding(innerPadding)
) {
- composable(Screen.UserList.route) { UserList(navController) }
- composable(Screen.Home.route) { Home() }
- 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, authViewModel,userViewModel.getUsers())
}
- 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(
Screen.UserView.route,
arguments = listOf(navArgument("id") { type = NavType.IntType })
) { backStackEntry ->
- backStackEntry.arguments?.let { StudentView(it.getInt("id")) }
+ backStackEntry.arguments?.let { StudentView(userViewModel.getUsers()[it.getInt("id")]) }
}
}
}
@@ -133,6 +140,8 @@ fun Navhost(
@Composable
fun MainNavbar() {
val navController = rememberNavController()
+ val authViewModel = remember { AuthViewModel() }
+ val userViewModel =UserViewModel() // Создайте экземпляр AuthViewModel
val navBackStackEntry by navController.currentBackStackEntryAsState()
val currentDestination = navBackStackEntry?.destination
val currentScreen = currentDestination?.route?.let { Screen.getItem(it) }
@@ -147,8 +156,8 @@ fun MainNavbar() {
}
}
) { innerPadding ->
- Navhost(navController, innerPadding)
- }
+ NavHost(navController, innerPadding, authViewModel, userViewModel)
+ }
}
@Preview(name = "Light Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_NO)
diff --git a/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt b/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt
index c3d66cd..0b70106 100644
--- a/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt
+++ b/app/src/main/java/com/example/pmuapp/models/user/composeui/StudentView.kt
@@ -15,32 +15,32 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
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
@OptIn(ExperimentalMaterial3Api::class)
@Composable
-fun StudentView(id: Int) {
- val student = getStudents()[id]
+fun StudentView(user: User) {
+
Column(
Modifier
.fillMaxWidth()
.padding(all = 10.dp)
) {
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
- value = student.name, onValueChange = {}, readOnly = true,
+ value = user.name, onValueChange = {}, readOnly = true,
label = {
Text(stringResource(id = R.string.user_name))
}
)
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
- value = student.login, onValueChange = {}, readOnly = true,
+ value = user.login, onValueChange = {}, readOnly = true,
label = {
Text(stringResource(id = R.string.user_login))
}
)
OutlinedTextField(modifier = Modifier.fillMaxWidth(),
- value = student.password, onValueChange = {}, readOnly = true,
+ value = user.password, onValueChange = {}, readOnly = true,
label = {
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 = "Dark Mode", showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
-@Composable
-fun StudentViewPreview() {
- PMUappTheme {
- Surface(
- color = MaterialTheme.colorScheme.background
- ) {
- StudentView(id = 0)
- }
- }
-}
\ No newline at end of file
+//@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 StudentViewPreview() {
+// PMUappTheme {
+// Surface(
+// color = MaterialTheme.colorScheme.background
+// ) {
+// StudentView(id = 0)
+// }
+// }
+//}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt b/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt
index ce33f77..9140eed 100644
--- a/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt
+++ b/app/src/main/java/com/example/pmuapp/models/user/composeui/UserList.kt
@@ -14,34 +14,35 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
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
@Composable
-fun UserList(navController: NavController?) {
+fun UserList(navController: NavController?,
+ users: List ) {
Column(Modifier.padding(all = 10.dp)) {
- getStudents().forEachIndexed() { index, student ->
- val studentId = Screen.UserView.route.replace("{id}", index.toString())
+ users.forEachIndexed() { index, user ->
+ val userId = Screen.UserView.route.replace("{id}", index.toString())
Button(
modifier = Modifier
.fillMaxWidth()
.padding(all = 10.dp),
- onClick = { navController?.navigate(studentId) }) {
- Text("${student.login}")
+ onClick = { navController?.navigate(userId) }) {
+ Text("${user.login}")
}
}
}
}
-@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 StudentListPreview() {
- PMUappTheme {
- Surface(
- color = MaterialTheme.colorScheme.background
- ) {
- UserList(navController = null)
- }
- }
-}
\ No newline at end of file
+//@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 StudentListPreview() {
+// PMUappTheme {
+// Surface(
+// color = MaterialTheme.colorScheme.background
+// ) {
+// UserList(navController = null)
+// }
+// }
+//}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/pmuapp/models/user/model/AuthViewModel.kt b/app/src/main/java/com/example/pmuapp/models/user/model/AuthViewModel.kt
new file mode 100644
index 0000000..2a73530
--- /dev/null
+++ b/app/src/main/java/com/example/pmuapp/models/user/model/AuthViewModel.kt
@@ -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)
+}
diff --git a/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt b/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt
index 46c623c..825319b 100644
--- a/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt
+++ b/app/src/main/java/com/example/pmuapp/models/user/model/Student.kt
@@ -1,5 +1,8 @@
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
data class User(
@@ -8,10 +11,29 @@ data class User(
val password: String,
) : Serializable
-fun getStudents(): List {
- return listOf(
- User("Иван", "ivan", "111111"),
- User("Анна", "ann", "111111"),
- User("Лиза", "liza", "111111")
+class UserViewModel : ViewModel() {
+ var users: MutableState> = mutableStateOf(
+ listOf(
+ User("Иван", "ivan", "111111"),
+ User("Анна", "ann", "111111"),
+ User("Лиза", "liza", "111111")
+ )
)
+
+ fun getUsers(): List {
+ 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
+ }
+ }
}
+
+
+
+