Загрузка данных
package com.monika.orangesky
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
@Composable
fun RegisterScreen(onRegisterSuccess: () -> Unit) {
var email by remember { mutableStateOf("") }
var password by remember { mutableStateOf("") }
var name by remember { mutableStateOf("") }
var house by remember { mutableStateOf("") }
var error by remember { mutableStateOf(false) }
val winterIceBlue = Color(0xFF1E3F66)
val snowBackground = Color(0xFFF0F4F8)
Column(
modifier = Modifier
.fillMaxSize()
.background(snowBackground)
) {
Box(
modifier = Modifier
.fillMaxWidth()
.background(winterIceBlue)
.padding(16.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = "❄️ the facebook (Winter '04)",
color = Color.White,
fontWeight = FontWeight.Bold,
fontSize = 20.sp
)
Text(
text = "New Account",
color = Color(0xFFBCE3C5),
fontSize = 12.sp,
fontWeight = FontWeight.Medium
)
}
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(24.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Card(
colors = CardDefaults.cardColors(containerColor = Color.White),
elevation = CardDefaults.cardElevation(3.dp),
modifier = Modifier.fillMaxWidth()
) {
Column(modifier = Modifier.padding(16.dp)) {
Text("Student Registration", fontWeight = FontWeight.Bold, color = winterIceBlue, fontSize = 18.sp)
Text("❄️ Join the campus network", fontSize = 11.sp, color = Color.Gray)
Spacer(modifier = Modifier.height(16.dp))
OutlinedTextField(
value = name,
onValueChange = { name = it },
label = { Text("Full Name") },
modifier = Modifier.fillMaxWidth(),
singleLine = true
)
Spacer(modifier = Modifier.height(8.dp))
OutlinedTextField(
value = house,
onValueChange = { house = it },
label = { Text("House / Dorm") },
modifier = Modifier.fillMaxWidth(),
singleLine = true
)
Spacer(modifier = Modifier.height(8.dp))
OutlinedTextField(
value = email,
onValueChange = { email = it },
label = { Text("Email / NetID") },
modifier = Modifier.fillMaxWidth(),
singleLine = true
)
Spacer(modifier = Modifier.height(8.dp))
OutlinedTextField(
value = password,
onValueChange = { password = it },
label = { Text("Password") },
visualTransformation = PasswordVisualTransformation(),
modifier = Modifier.fillMaxWidth(),
singleLine = true
)
if (error) {
Spacer(modifier = Modifier.height(4.dp))
Text("Please fill in all fields", color = Color.Red, fontSize = 12.sp)
}
Spacer(modifier = Modifier.height(16.dp))
Button(
onClick = {
if (email.isNotBlank() && password.isNotBlank() && name.isNotBlank()) {
DataSource.users.add(
UserProfile(
id = System.currentTimeMillis().toString(),
name = name,
house = if (house.isBlank()) "Harvard" else house,
status = "Joined for the Winter term ❄️",
email = email,
info = "Registered via app."
)
)
onRegisterSuccess()
} else {
error = true
}
},
colors = ButtonDefaults.buttonColors(containerColor = winterIceBlue),
modifier = Modifier.fillMaxWidth()
) {
Text("Register")
}
}
}
}
}
}