auth;reg_but_without_name
This commit is contained in:
parent
0225f44877
commit
07855028a4
@ -1,29 +1,15 @@
|
||||
package com.example.matuletest
|
||||
|
||||
import android.os.Bundle
|
||||
import android.window.SplashScreen
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.matuletest.ui.auth.AuthScreen
|
||||
import com.example.matuletest.ui.auth.screens.AuthScreen
|
||||
import com.example.matuletest.ui.auth.FirstScreen
|
||||
//import com.example.matuletest.ui.auth.FirstScreen
|
||||
import com.example.matuletest.ui.auth.screens.RegistrationScreen
|
||||
import com.example.matuletest.ui.auth.SliderScreen
|
||||
import com.example.matuletest.ui.theme.MatuleTestTheme
|
||||
|
||||
@ -33,17 +19,6 @@ class MainActivity : ComponentActivity() {
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
MatuleTestTheme {
|
||||
// var isSplashScreenVisible by remember { mutableStateOf(true) }
|
||||
//
|
||||
// if (isSplashScreenVisible) {
|
||||
// FirstScreen (onNavigateToSliderScreen = {
|
||||
// isSplashScreenVisible = false
|
||||
// })
|
||||
// } else {
|
||||
// AuthScreen()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
val navController = rememberNavController()
|
||||
|
||||
NavHost(navController = navController, startDestination = "first_screen") {
|
||||
@ -58,7 +33,10 @@ class MainActivity : ComponentActivity() {
|
||||
})
|
||||
}
|
||||
composable("auth_screen") {
|
||||
AuthScreen()
|
||||
AuthScreen(navController)
|
||||
}
|
||||
composable("registration_screen") {
|
||||
RegistrationScreen(navController)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.matuletest.domain
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import com.example.matuletest.data.remotesource.SupaBaseClient
|
||||
import io.github.jan.supabase.auth.SessionManager
|
||||
@ -24,4 +25,20 @@ class AuthUseCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//без добавления имени
|
||||
suspend fun registration(email: String, password: String)= flow<Boolean>{
|
||||
SupaBaseClient.instance.auth.signUpWith(Email){
|
||||
this.email = email
|
||||
this.password = password
|
||||
}
|
||||
SupaBaseClient.instance.auth.sessionStatus.collect{ status ->
|
||||
when(status){
|
||||
is SessionStatus.Authenticated -> emit(true)
|
||||
is SessionStatus.Initializing -> {}
|
||||
else -> emit(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
package com.example.matuletest.ui.auth
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
//import androidx.compose.foundation.text2.input.TextFieldCharSequence
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
|
||||
@Composable
|
||||
fun AuthScreen(){
|
||||
val viewModel: AuthScreenViewModel = viewModel()
|
||||
AuthContent(viewModel)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AuthContent(viewModel: AuthScreenViewModel){
|
||||
val authState = viewModel.authScreenState.collectAsState()
|
||||
|
||||
if(authState.value.isSignIn){
|
||||
Text("Success Authorize")
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(text = "Email")
|
||||
TextField(
|
||||
value = authState.value.email,
|
||||
onValueChange = {
|
||||
viewModel.setEmail(it)
|
||||
})
|
||||
Text(text = "Password")
|
||||
TextField(
|
||||
value = authState.value.password,
|
||||
onValueChange = {
|
||||
viewModel.setPassword(it)
|
||||
},
|
||||
visualTransformation = PasswordVisualTransformation()
|
||||
)
|
||||
Button(onClick = {
|
||||
viewModel.auth()
|
||||
}) {
|
||||
Text("Authorize")
|
||||
}
|
||||
}
|
||||
}
|
@ -5,3 +5,10 @@ data class AuthScreenState(
|
||||
var password: String = "",
|
||||
var isSignIn: Boolean = false
|
||||
)
|
||||
|
||||
data class RegistrationScreenState(
|
||||
// var name: String = "",
|
||||
var email: String = "",
|
||||
var password: String = "",
|
||||
var isSignUp: Boolean = false
|
||||
)
|
@ -9,18 +9,32 @@ import kotlinx.coroutines.launch
|
||||
|
||||
class AuthScreenViewModel: ViewModel() {
|
||||
val authScreenState = MutableStateFlow(AuthScreenState())
|
||||
val registrationScreenState = MutableStateFlow(RegistrationScreenState())
|
||||
val useCase = AuthUseCase()
|
||||
fun setPassword(password: String){
|
||||
fun setPassword(password: String, isRegistration: Boolean = false){
|
||||
viewModelScope.launch {
|
||||
authScreenState.update {
|
||||
it.copy(password = password)
|
||||
if (isRegistration) {
|
||||
registrationScreenState.update {
|
||||
it.copy(password = password)
|
||||
}
|
||||
} else {
|
||||
authScreenState.update {
|
||||
it.copy(password = password)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fun setEmail(email: String){
|
||||
|
||||
fun setEmail(email: String, isRegistration: Boolean = false){
|
||||
viewModelScope.launch {
|
||||
authScreenState.update {
|
||||
it.copy(email = email)
|
||||
if (isRegistration) {
|
||||
registrationScreenState.update {
|
||||
it.copy(email = email)
|
||||
}
|
||||
} else {
|
||||
authScreenState.update {
|
||||
it.copy(email = email)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -35,4 +49,15 @@ class AuthScreenViewModel: ViewModel() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun reg(){
|
||||
viewModelScope.launch {
|
||||
useCase.registration(
|
||||
registrationScreenState.value.email,
|
||||
registrationScreenState.value.password
|
||||
).collect{ result ->
|
||||
if(result) registrationScreenState.update { it.copy(isSignUp = true) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ import java.lang.reflect.Modifier
|
||||
@Composable
|
||||
fun FirstScreen(onNavigateToSliderScreen: () -> Unit) {
|
||||
LaunchedEffect(Unit) {
|
||||
kotlinx.coroutines.delay(6000)
|
||||
kotlinx.coroutines.delay(3000)
|
||||
onNavigateToSliderScreen()
|
||||
}
|
||||
Box(
|
||||
@ -116,23 +116,22 @@ fun SliderScreen(onNavigateToAuthScreen: () -> Unit) {
|
||||
valueRange = 0f..maxIndex.toFloat(),
|
||||
steps = maxIndex - 1,
|
||||
colors = androidx.compose.material3.SliderDefaults.colors(
|
||||
thumbColor = Color.White, // Цвет ползунка
|
||||
activeTrackColor = Color(0xFF0076B1), // Цвет активной части слайдера
|
||||
inactiveTrackColor = Color(0xFFB0B0B0) // Цвет неактивной части слайдера
|
||||
thumbColor = Color.White,
|
||||
activeTrackColor = Color(0xFF0076B1),
|
||||
inactiveTrackColor = Color(0xFFB0B0B0)
|
||||
),
|
||||
modifier = androidx.compose.ui.Modifier.fillMaxWidth()
|
||||
)
|
||||
|
||||
Spacer(modifier = androidx.compose.ui.Modifier.height(20.dp))
|
||||
// Spacer(modifier = androidx.compose.ui.Modifier.height(20.dp))
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
if (sliderValue < maxIndex) {
|
||||
sliderValue++
|
||||
} else {
|
||||
onNavigateToAuthScreen() // Переход на экран авторизации
|
||||
onNavigateToAuthScreen()
|
||||
}},
|
||||
// enabled = sliderValue < maxIndex,
|
||||
colors = androidx.compose.material3.ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
contentColor = Color.Black
|
||||
|
@ -0,0 +1,120 @@
|
||||
package com.example.matuletest.ui.auth.screens
|
||||
|
||||
import androidx.compose.foundation.hoverable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.text.ClickableText
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.example.matuletest.ui.auth.AuthScreenViewModel
|
||||
|
||||
@Composable
|
||||
fun AuthScreen(navController: NavController) {
|
||||
val viewModel: AuthScreenViewModel = viewModel()
|
||||
// AuthContent(viewModel, navController)
|
||||
AuthContent(viewModel, navController)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AuthContent(viewModel: AuthScreenViewModel, navController: NavController) {
|
||||
val authState = viewModel.authScreenState.collectAsState()
|
||||
|
||||
if (authState.value.isSignIn) {
|
||||
Text("Success Authorize")
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Привет!",
|
||||
style = TextStyle(fontSize = 32.sp, fontWeight = FontWeight.Bold),
|
||||
modifier = Modifier.height(60.dp).padding(bottom = 20.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "Заполните Свои данные или продолжите через социальные медиа",
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 20.dp),
|
||||
style = TextStyle(fontSize = 16.sp),
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 2
|
||||
)
|
||||
|
||||
Text(text = "Email", modifier = Modifier.padding(end = 255.dp))
|
||||
TextField(
|
||||
modifier = Modifier.width(300.dp).height(70.dp).padding(bottom = 16.dp),
|
||||
value = authState.value.email,
|
||||
onValueChange = {
|
||||
viewModel.setEmail(it)
|
||||
})
|
||||
|
||||
Text(text = "Password", modifier = Modifier.padding(end = 225.dp))
|
||||
TextField(
|
||||
modifier = Modifier.width(300.dp).height(70.dp).padding(bottom = 16.dp),
|
||||
value = authState.value.password,
|
||||
onValueChange = {
|
||||
viewModel.setPassword(it)
|
||||
},
|
||||
visualTransformation = PasswordVisualTransformation()
|
||||
)
|
||||
|
||||
Button(
|
||||
modifier = Modifier.width(350.dp).height(50.dp),
|
||||
colors = androidx.compose.material3.ButtonDefaults.buttonColors(
|
||||
containerColor = Color(0xFF48B2E7),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
viewModel.auth()
|
||||
}) {
|
||||
Text("Войти")
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(top = 16.dp)
|
||||
.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Вы впервые? ",
|
||||
style = TextStyle(fontSize = 16.sp, color = Color.Black)
|
||||
)
|
||||
|
||||
ClickableText(
|
||||
text = buildAnnotatedString { append("Создать пользователя") },
|
||||
onClick = {
|
||||
navController.navigate("registration_screen")
|
||||
},
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = Color.Black
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package com.example.matuletest.ui.auth.screens
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
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.foundation.layout.width
|
||||
import androidx.compose.foundation.text.ClickableText
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import com.example.matuletest.ui.auth.AuthScreenViewModel
|
||||
|
||||
@Composable
|
||||
fun RegistrationScreen(navController: NavController) {
|
||||
val viewModel: AuthScreenViewModel = viewModel()
|
||||
RegistrationContent(viewModel, navController)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RegistrationContent(viewModel: AuthScreenViewModel, navController: NavController){
|
||||
val regState = viewModel.registrationScreenState.collectAsState()
|
||||
|
||||
if (regState.value.isSignUp) {
|
||||
Text("Success Registration")
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Регистрация!",
|
||||
style = TextStyle(fontSize = 32.sp, fontWeight = FontWeight.Bold),
|
||||
modifier = Modifier.height(60.dp).padding(bottom = 20.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "Заполните Свои данные или продолжите через социальные медиа",
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 20.dp),
|
||||
style = TextStyle(fontSize = 16.sp),
|
||||
textAlign = TextAlign.Center,
|
||||
maxLines = 2
|
||||
)
|
||||
|
||||
// Text(text = "Ваше имя", modifier = Modifier.padding(end = 255.dp))
|
||||
// TextField(
|
||||
// modifier = Modifier.width(300.dp).height(70.dp).padding(bottom = 16.dp),
|
||||
// value = regState.value.email,
|
||||
// onValueChange = {
|
||||
// viewModel.setEmail(it)
|
||||
// })
|
||||
|
||||
Text(text = "Email", modifier = Modifier.padding(end = 255.dp))
|
||||
TextField(
|
||||
modifier = Modifier.width(300.dp).height(70.dp).padding(bottom = 16.dp),
|
||||
value = regState.value.email,
|
||||
onValueChange = {
|
||||
viewModel.setEmail(it, true)
|
||||
})
|
||||
|
||||
Text(text = "Password", modifier = Modifier.padding(end = 225.dp))
|
||||
TextField(
|
||||
modifier = Modifier.width(300.dp).height(70.dp).padding(bottom = 16.dp),
|
||||
value = regState.value.password,
|
||||
onValueChange = {
|
||||
viewModel.setPassword(it, true)
|
||||
},
|
||||
visualTransformation = PasswordVisualTransformation()
|
||||
)
|
||||
|
||||
Button(
|
||||
modifier = Modifier.width(350.dp).height(50.dp),
|
||||
colors = androidx.compose.material3.ButtonDefaults.buttonColors(
|
||||
containerColor = Color(0xFF48B2E7),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
viewModel.reg()
|
||||
}) {
|
||||
Text("Зарегестрироваться")
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.padding(top = 16.dp)
|
||||
.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = "Есть аккаунт? ",
|
||||
style = TextStyle(fontSize = 16.sp, color = Color.Black)
|
||||
)
|
||||
|
||||
ClickableText(
|
||||
text = buildAnnotatedString { append("Войти") },
|
||||
onClick = {
|
||||
navController.navigate("auth_screen")
|
||||
},
|
||||
style = TextStyle(
|
||||
fontSize = 16.sp,
|
||||
color = Color.Black
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user