diff --git a/.gradle/8.0/checksums/checksums.lock b/.gradle/8.0/checksums/checksums.lock
index 27d9b8e..fb0feb4 100644
Binary files a/.gradle/8.0/checksums/checksums.lock and b/.gradle/8.0/checksums/checksums.lock differ
diff --git a/.gradle/8.0/checksums/md5-checksums.bin b/.gradle/8.0/checksums/md5-checksums.bin
index 2dd2fed..854ce88 100644
Binary files a/.gradle/8.0/checksums/md5-checksums.bin 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
index 41955ce..7117ade 100644
Binary files a/.gradle/8.0/checksums/sha1-checksums.bin and b/.gradle/8.0/checksums/sha1-checksums.bin differ
diff --git a/.gradle/8.0/fileHashes/fileHashes.lock b/.gradle/8.0/fileHashes/fileHashes.lock
index 3b78ce0..6b6ca6b 100644
Binary files a/.gradle/8.0/fileHashes/fileHashes.lock and b/.gradle/8.0/fileHashes/fileHashes.lock differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
index 9d1bfd3..ffe221f 100644
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
index 007ac5b..459d3ed 100644
Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7d57701..111fe90 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -9,36 +9,26 @@
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
@@ -94,8 +84,8 @@
-
+
@@ -121,22 +111,22 @@
- {
+ "keyToString": {
+ "ASKED_ADD_EXTERNAL_FILES": "true",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.cidr.known.project.marker": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "cidr.known.project.marker": "true",
+ "com.android.tools.idea.devicemanager.tab": "Physical",
+ "last_opened_file_path": "C:/Users/Kate/AndroidStudioProjects/Ihonkina_PIbd-31_PMU",
+ "project.structure.last.edited": "Modules",
+ "project.structure.proportion": "0.17",
+ "project.structure.side.proportion": "0.2",
+ "settings.editor.selected.configurable": "project.kotlinCompiler"
}
-}]]>
+}
@@ -152,6 +142,7 @@
+
@@ -306,7 +297,14 @@
1698258953508
-
+
+ 1699816471908
+
+
+
+ 1699816471908
+
+
@@ -342,6 +340,7 @@
-
+
+
\ No newline at end of file
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 8277fc1..43568d4 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -65,7 +65,10 @@ dependencies {
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
+ implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")
+ implementation ("io.coil-kt:coil-compose:1.4.0")
+
// Room
diff --git a/app/src/main/java/com/example/pmuapp/composeui/EditPet.kt b/app/src/main/java/com/example/pmuapp/composeui/EditPet.kt
index 41ae443..5f16aa8 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/EditPet.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/EditPet.kt
@@ -1,6 +1,5 @@
package com.example.pmuapp.composeui
-import android.os.Build
import android.os.Build.*
import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
@@ -25,19 +24,18 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
-import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.example.pmuapp.composeui.navigation.Screen
-import com.example.pmuapp.models.user.model.AuthViewModel
+import com.example.pmuapp.models.user.model.viewmodel.AuthViewModel
import com.example.pmuapp.models.user.model.PetViewModel
import com.example.pmuapp.models.user.model.UserViewModel
@RequiresApi(VERSION_CODES.O)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
-fun EditPet(navController: NavController ,authViewModel: AuthViewModel, petViewModel: PetViewModel, userViewModel: UserViewModel, petId: Int) {
+fun EditPet(navController: NavController, authViewModel: AuthViewModel, petViewModel: PetViewModel, userViewModel: UserViewModel, petId: Int) {
val pet = (authViewModel.currentUser?.petId ?: emptyList()).find { it.id == petId }
var petName by remember { mutableStateOf(pet?.name ?: "") }
diff --git a/app/src/main/java/com/example/pmuapp/composeui/Home.kt b/app/src/main/java/com/example/pmuapp/composeui/Home.kt
index 5873b06..6c798cd 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/Home.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/Home.kt
@@ -14,7 +14,7 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.example.pmuapp.composeui.navigation.Screen
import com.example.pmuapp.models.user.composeui.PetList
-import com.example.pmuapp.models.user.model.AuthViewModel
+import com.example.pmuapp.models.user.model.viewmodel.AuthViewModel
import com.example.pmuapp.models.user.model.PetViewModel
import com.example.pmuapp.models.user.model.UserViewModel
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 1a7a4fc..7b4922f 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/Login.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/Login.kt
@@ -1,11 +1,5 @@
package com.example.pmuapp.composeui
-import android.content.Intent
-import android.content.res.Configuration
-import android.net.Uri
-import android.widget.TextView
-import androidx.activity.compose.BackHandler
-import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
@@ -15,42 +9,32 @@ import androidx.compose.foundation.layout.height
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.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
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
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.AuthViewModel
-import com.example.pmuapp.models.user.model.User
-import com.example.pmuapp.ui.theme.PMUappTheme
+import com.example.pmuapp.models.user.model.viewmodel.AuthViewModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Login(
- navController: NavHostController,
- authViewModel: AuthViewModel,
- users: List
+ navController: NavController,
+ authViewModel: AuthViewModel
) {
var username by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
+ val users by authViewModel.currentUser.collectAsState()
Column(
modifier = Modifier
@@ -82,11 +66,12 @@ fun Login(
Button(
onClick = {
- val authenticatedUser = users.find { it.login == username && it.password == password }
+ val authenticatedUser = authViewModel.loginUser(username, password)
if (authenticatedUser != null) {
- authViewModel.currentUser = authenticatedUser
+ // Аутентификация успешна
navController.navigate(Screen.Profile.route)
} else {
+ // Аутентификация не удалась
println("Authentication failed")
}
},
@@ -95,10 +80,10 @@ fun Login(
Text("Login")
}
+
+ // Вы можете также использовать users для дополнительных проверок или вывода информации
+ users?.let {
+ Text("Current User: ${it.name}")
+ }
}
}
-
-
-
-
-
diff --git a/app/src/main/java/com/example/pmuapp/composeui/PlayPet.kt b/app/src/main/java/com/example/pmuapp/composeui/PlayPet.kt
index 2b268bf..f29a8f9 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/PlayPet.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/PlayPet.kt
@@ -5,7 +5,6 @@ import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
-import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@@ -25,14 +24,14 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.example.pmuapp.composeui.navigation.Screen
-import com.example.pmuapp.models.user.model.AuthViewModel
+import com.example.pmuapp.models.user.model.viewmodel.AuthViewModel
import com.example.pmuapp.models.user.model.PetViewModel
import com.example.pmuapp.models.user.model.UserViewModel
@RequiresApi(Build.VERSION_CODES.O)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
-fun PlayPet(navController: NavController,authViewModel: AuthViewModel, petViewModel: PetViewModel, userViewModel: UserViewModel, petId: Int) {
+fun PlayPet(navController: NavController, authViewModel: AuthViewModel, petViewModel: PetViewModel, userViewModel: UserViewModel, petId: Int) {
val pet = (authViewModel.currentUser?.petId ?: emptyList()).find { it.id == petId }
Column(
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 45df3d5..ccc67d6 100644
--- a/app/src/main/java/com/example/pmuapp/composeui/Profile.kt
+++ b/app/src/main/java/com/example/pmuapp/composeui/Profile.kt
@@ -49,7 +49,7 @@ fun Profile(navController: NavController,currentUser: User?, onSaveClick: (User)
) {
currentUser?.let { user ->
Image(
- painter = rememberImagePainter(data = user.imageResId),
+ painter = rememberImagePainter(data = user.imageUri),
contentDescription = null,
modifier = Modifier
.fillMaxWidth()
@@ -108,8 +108,8 @@ fun Profile(navController: NavController,currentUser: User?, onSaveClick: (User)
nameState.value,
loginState.value,
passwordState.value,
- currentUser?.petId ?: emptyList(),
- selectedImageUri.value?.toString() ?: "",
+ currentUser?.pets ?: emptyList(),
+ selectedImageUri.value?.toString() ?: ""
)
onSaveClick(updatedUser)
},
@@ -117,6 +117,8 @@ fun Profile(navController: NavController,currentUser: User?, onSaveClick: (User)
) {
Text("Сохранить")
}
+
+
Button(
onClick = {
navController.navigate(Screen.Login.route)
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 6721c08..6cc181e 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
@@ -1,7 +1,6 @@
package com.example.pmuapp.composeui.navigation
import CreatePet
-import android.content.res.Configuration
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.layout.Box
@@ -17,7 +16,6 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
-import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
@@ -27,7 +25,6 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
-import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavDestination
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavGraph.Companion.findStartDestination
@@ -46,10 +43,9 @@ import com.example.pmuapp.composeui.PlayPet
import com.example.pmuapp.composeui.Profile
import com.example.pmuapp.models.user.composeui.PetList
import com.example.pmuapp.models.user.composeui.UserList
-import com.example.pmuapp.models.user.model.AuthViewModel
+import com.example.pmuapp.models.user.model.viewmodel.AuthViewModel
import com.example.pmuapp.models.user.model.PetViewModel
import com.example.pmuapp.models.user.model.UserViewModel
-import com.example.pmuapp.ui.theme.PMUappTheme
@OptIn(ExperimentalMaterial3Api::class)
@Composable
@@ -123,11 +119,11 @@ fun Navbar(
@RequiresApi(Build.VERSION_CODES.O)
@Composable
fun NavHost(
-navController: NavHostController,
-innerPadding: PaddingValues,
-authViewModel: AuthViewModel,
-userViewModel: UserViewModel,
-petViewModel: PetViewModel
+ navController: NavHostController,
+ innerPadding: PaddingValues,
+ authViewModel: AuthViewModel,
+ userViewModel: UserViewModel,
+ petViewModel: PetViewModel
) {
NavHost(
navController = navController,
diff --git a/app/src/main/java/com/example/pmuapp/models/user/composeui/PetList.kt b/app/src/main/java/com/example/pmuapp/models/user/composeui/PetList.kt
index 46bc764..1e12479 100644
--- a/app/src/main/java/com/example/pmuapp/models/user/composeui/PetList.kt
+++ b/app/src/main/java/com/example/pmuapp/models/user/composeui/PetList.kt
@@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
-import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
@@ -17,8 +16,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
@@ -28,9 +25,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.example.pmuapp.composeui.navigation.Screen
-import com.example.pmuapp.models.user.model.AuthViewModel
+import com.example.pmuapp.models.user.model.viewmodel.AuthViewModel
import com.example.pmuapp.models.user.model.PetViewModel
-import com.example.pmuapp.models.user.model.User
import com.example.pmuapp.models.user.model.UserViewModel
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
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
deleted file mode 100644
index 2a73530..0000000
--- a/app/src/main/java/com/example/pmuapp/models/user/model/AuthViewModel.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-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/User.kt b/app/src/main/java/com/example/pmuapp/models/user/model/User.kt
index 9e33af1..bbc9ffd 100644
--- a/app/src/main/java/com/example/pmuapp/models/user/model/User.kt
+++ b/app/src/main/java/com/example/pmuapp/models/user/model/User.kt
@@ -10,22 +10,23 @@ import androidx.room.Relation
@Entity(tableName = "users")
data class User(
@PrimaryKey(autoGenerate = true)
- val id: Int,
+ val id: Int = 0,
val name: String,
val login: String,
val password: String,
- @Relation(
- entity = Pet::class,
- parentColumn = "id",
- entityColumn = "user_id"
- )
- val pets: List,
- @ColumnInfo(name = "image_res_id")
- val imageResId: String
-) {
+ @Relation(parentColumn = "id", entityColumn = "user_id")
+ var pets: List = emptyList(),
+ val imageUri: String = ""
+) {
@Ignore
- constructor(id: Int, name: String, login: String, password: String, imageResId: Int) :
- this(id, name, login, password, emptyList(), imageResId)
+ constructor(
+ name: String,
+ login: String,
+ password: String,
+ pets: List,
+ imageUri: String
+ ) : this(0, name, login, password, pets, imageUri)
+
fun addPet(pet: Pet): User {
val updatedPets = pets.toMutableList()
updatedPets.add(pet)
diff --git a/app/src/main/java/com/example/pmuapp/models/user/model/viewmodel/AuthViewModel.kt b/app/src/main/java/com/example/pmuapp/models/user/model/viewmodel/AuthViewModel.kt
new file mode 100644
index 0000000..a48c066
--- /dev/null
+++ b/app/src/main/java/com/example/pmuapp/models/user/model/viewmodel/AuthViewModel.kt
@@ -0,0 +1,45 @@
+package com.example.pmuapp.models.user.model.viewmodel
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.pmuapp.models.user.Dao.UserDao
+import com.example.pmuapp.models.user.model.User
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+
+class AuthViewModel(private val userDao: UserDao) : ViewModel() {
+
+ private val _currentUser = MutableStateFlow(null)
+ val currentUser: StateFlow get() = _currentUser.asStateFlow()
+
+ init {
+ // Подписываемся на изменения в базе данных и обновляем _currentUser
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ val users = userDao.getAll()
+ // Ваш код обработки данных, если необходимо
+ // Например, если вам нужно обновить _currentUser
+ _currentUser.value = users.firstOrNull()
+ }
+ }
+
+
+
+ }
+ // Метод для входа пользователя
+ fun loginUser(login: String, password: String) {
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ val user = userDao.getUserByLoginAndPassword(login, password)
+ // Обновляем _currentUser после успешной аутентификации
+ _currentUser.value = user
+ }
+ }
+ }
+
+ // Добавьте методы для выхода пользователя, регистрации и других операций, если нужно
+}
diff --git a/app/src/main/java/com/example/pmuapp/models/user/model/viewmodel/UserViewModel.kt b/app/src/main/java/com/example/pmuapp/models/user/model/viewmodel/UserViewModel.kt
new file mode 100644
index 0000000..883042c
--- /dev/null
+++ b/app/src/main/java/com/example/pmuapp/models/user/model/viewmodel/UserViewModel.kt
@@ -0,0 +1,36 @@
+package com.example.pmuapp.models.user.model.viewmodel
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.pmuapp.models.user.Dao.UserDao
+import com.example.pmuapp.models.user.model.User
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+class UserViewModel(private val userDao: UserDao) : ViewModel() {
+
+ private val _users = MutableStateFlow>(emptyList())
+ val users: StateFlow> get() = _users
+
+ // Метод для обновления списка пользователей
+ fun updateUsers(newUsers: List) {
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ _users.value = newUsers
+ }
+ }
+ }
+
+ // Метод для входа пользователя
+ fun loginUser(login: String, password: String) {
+ viewModelScope.launch {
+ withContext(Dispatchers.IO) {
+ val user = userDao.getUserByLoginAndPassword(login, password)
+ // Здесь должно быть обновление списка пользователей, но не _currentUser
+ // Также, вам, возможно, нужно вызвать метод updateUsers с обновленным списком пользователей
+ }
+ }
+ }
+}