From e4b66ae0366c7fd9351ed4b7a1246dd52a5c69ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 24 Dec 2023 00:11:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9A=D1=80=D0=B8=D0=BD=D0=B6=D0=BE=D0=B2?= =?UTF-8?q?=D1=8B=D0=B9=20=D0=BA=D1=80=D0=B8=D0=BD=D0=B6=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../composeui/CurrentUserViewModel.kt | 4 ++ .../entities/composeui/UserProfile.kt | 54 +++++++++++++++++-- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/CurrentUserViewModel.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/CurrentUserViewModel.kt index 2c098cc..a851ba1 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/CurrentUserViewModel.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/CurrentUserViewModel.kt @@ -21,4 +21,8 @@ class CurrentUserViewModel(private val userRepository: UserRepository) : ViewMod user = userRepository.getUserById(userid.value) } } + + fun setNullUser() { + user = null + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt index 1115de6..b98f006 100644 --- a/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt +++ b/app/src/main/java/com/example/myapplication/database/entities/composeui/UserProfile.kt @@ -2,6 +2,7 @@ package com.example.myapplication.database.entities.composeui import android.annotation.SuppressLint import android.util.Log +import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -14,6 +15,7 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.BasicTextField import androidx.compose.material3.Button @@ -30,6 +32,8 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.PasswordVisualTransformation @@ -37,6 +41,7 @@ import androidx.compose.ui.text.style.TextAlign 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.composeui.navigation.Screen import com.example.myapplication.database.entities.model.User import com.example.myapplication.datastore.DataStoreManager @@ -73,10 +78,51 @@ fun UserProfile( // Проверяем, авторизован пользователь или нет if (getUser?.uid != null) { - // Пользователь авторизован, отображаем страницу профиля - // Замените на ваш код для страницы профиля - // Например, использовать другой @Composable или навигировать на другой экран - Text("Это страница профиля") + + Column( + modifier = Modifier + .fillMaxSize() + .padding(16.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + // Display the user's photo (replace the Image composable with your logic) + Image( + painter = painterResource(id = R.drawable.ic_launcher_foreground), // Replace with your photo + contentDescription = null, + modifier = Modifier + .size(120.dp) + .clip(CircleShape) + .background(MaterialTheme.colorScheme.primary) + ) + + Spacer(modifier = Modifier.height(16.dp)) + + // Display the logged-in message + Text( + text = "Вы авторизованы под аккаунтом: ${getUser?.login}", + //style = MaterialTheme.typography.h6, + textAlign = TextAlign.Center + ) + + Spacer(modifier = Modifier.height(16.dp)) + + // "Logout" button + Button( + onClick = { + // Perform logout action + currentUserViewModel.setNullUser() + navController?.navigate(Screen.LoginScreen.route) + // Navigate back to the login screen + //navController?.popBackStack() + }, + modifier = Modifier + .fillMaxWidth() + .padding(8.dp) + ) { + Text("Выйти") + } + } } else { LazyColumn {