Package Not1

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

package com.example.

myapplication

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.myapplication.ui.theme.MyApplicationTheme

class MainActivity : ComponentActivity() {


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting()
}
}
}
}
}

@Composable
fun Greeting() {
var img: Painter = painterResource(id = R.drawable.th)
var MSV by remember { mutableStateOf("") }
var hoten by remember { mutableStateOf("") }
var emailText by remember { mutableStateOf("") } // State để lưu trữ nội dung
email
var emailList by remember { mutableStateOf<List<String>>(emptyList()) } // Danh
sách các email đã tạo

Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = "QUẢN LÝ SINH VIÊN",
modifier = Modifier.padding(8.dp)
)
Image(painter = img, contentDescription = null)
}
Text(
text = "Mã Sinh Viên",
modifier = Modifier.padding(top = 16.dp)
)
CustomTextField(
value = MSV,
onValueChanged = { MSV = it },
modifier = Modifier
.padding(bottom = 16.dp)
.fillMaxWidth()
)
Text(
text = "Họ và Tên",
modifier = Modifier.padding(top = 10.dp)
)
CustomTextField(
value = hoten,
onValueChanged = { hoten = it },
modifier = Modifier
.padding(bottom = 16.dp)
.fillMaxWidth()
)
Text(
text = "Email",
modifier = Modifier.padding(top = 10.dp)
)
// TextField cho email
CustomTextField(
value = emailText,
onValueChanged = { emailText = it },
modifier = Modifier
.padding(bottom = 16.dp)
.fillMaxWidth()
)

Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
Button(onClick = {
// Khi người dùng nhấn vào nút "Tạo email"
val email = email(hoten, MSV)
emailText = email // Cập nhật nội dung email
emailList = emailList + email // Thêm email mới vào danh sách
}, modifier = Modifier.weight(1f)) {
Text("Tạo email")
}
Button(onClick = {}, modifier = Modifier.weight(1f)) {
Text("Xem")
}
}

Spacer(modifier = Modifier.height(16.dp))

// Hiển thị danh sách email đã tạo trong một danh sách cuộn dọc
LazyColumn(
modifier = Modifier.weight(1f),
contentPadding = PaddingValues(horizontal = 16.dp)
) {
items(emailList) { email ->
Text(text = email)
}
}
}
}

// Define generateEmail function here or in a separate file

private fun email(hoten:String,MSV:String):String{


var email = ""
val x = hoten.split(" ")
var s = x[x.count()-1]
var msv1=("")
email=s
for(i in 0 until x.size -1){
email += x[i][0]
}
for(i in 0 until MSV.count()-3){
msv1+=MSV[i]
}
email +="."+ msv1 + "@vku.udn.vn"
return email

@Composable
fun CustomTextField(
value: String,
onValueChanged: (String) -> Unit,
modifier: Modifier = Modifier
) {
TextField(
value = value,
onValueChange = onValueChanged,
modifier = modifier,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(onDone = {})
)
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
MyApplicationTheme {
Greeting()
}
}

You might also like