Skip to content

Commit

Permalink
[FEAT/#1] 1주차 compose 수정 4
Browse files Browse the repository at this point in the history
  • Loading branch information
nagaeng committed Apr 5, 2024
1 parent 09e4147 commit f97ef80
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 38 deletions.
31 changes: 14 additions & 17 deletions app/src/main/java/com/sopt/now/compose/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ class LoginActivity : ComponentActivity() {

val getId = intent.getStringExtra("id") ?: ""
val getPassword = intent.getStringExtra("password") ?: ""
val getName = intent.getStringExtra("name") ?: ""
val getNickname = intent.getStringExtra("nickname") ?: ""
val getMbti = intent.getStringExtra("mbti") ?: ""

setContent {
LoginContent(getId, getPassword, getName, getMbti)
LoginContent(getId, getPassword, getNickname, getMbti)
}
}
}

@Composable
fun LoginContent(getId: String, getPassword: String, getName: String, getMbti: String) {
fun LoginContent(getId: String, getPassword: String, getNickname: String, getMbti: String) {
var isLogged by remember { mutableStateOf(false) }

if (!isLogged) {
SoptComposable(
getId = getId,
getPassword = getPassword,
getName = getName,
getNickname = getNickname,
getMbti = getMbti
)
} else {
Expand All @@ -71,12 +71,12 @@ fun isValid(userId: String?, userPassword: String?, getId: String, getPassword:
return userId != "" && userPassword != "" && userId == getId && userPassword == getPassword
}

fun Success(context: Context, userId: String, userPassword: String, userName: String?, userMbti: String?) {
fun Success(context: Context, userId: String, userPassword: String, userNickname: String, userMbti: String?) {

val intent = Intent(context, MainActivity::class.java).apply {
putExtra("id", userId)
putExtra("password", userPassword)
putExtra("name", userName)
putExtra("nickname", userNickname)
putExtra("mbti", userMbti)
}
context.startActivity(intent)
Expand All @@ -87,13 +87,13 @@ fun Success(context: Context, userId: String, userPassword: String, userName: St
fun SoptComposable(
getId: String,
getPassword: String,
getName: String,
getNickname: String,
getMbti: String

) {
var userId by remember { mutableStateOf("") }
var userPassword by remember { mutableStateOf("") }
var userName by remember { mutableStateOf("") }
var userNickname by remember { mutableStateOf("") }
var userMbti by remember { mutableStateOf("") }

Column(
Expand All @@ -117,14 +117,12 @@ fun SoptComposable(
// ID 입력하는 부분 (ID 텍스트는 좌측 정렬, 텍스트 필드는 중앙 정렬)
Column(verticalArrangement = Arrangement.Center) {
Text(text = "ID")
var text = remember {
mutableStateOf("")
}

TextField(
value = userId,
onValueChange = { userId = it },
label = { Text("ID를 입력하세요") },
placeholder = { Text("EX) nakyung") },
placeholder = { Text("EX) helen0816") },
singleLine = true,
)
}
Expand All @@ -135,9 +133,7 @@ fun SoptComposable(
// PW 입력하는 부분 (PW 텍스트는 좌측 정렬, 텍스트 필드는 중앙 정렬)
Column(verticalArrangement = Arrangement.Center) {
Text(text = "PASSWORD")
var passwordText = remember {
mutableStateOf("")
}

TextField(
value = userPassword,
onValueChange = { userPassword = it },
Expand All @@ -154,8 +150,9 @@ fun SoptComposable(

Button(
onClick = { if (isValid(userId, userPassword, getId ?: "", getPassword ?: "")) {
Success(context, userId, userPassword, userName, userMbti)
Success(context, userId, userPassword, userNickname, userMbti)
}
else Toast.makeText(context, "아이디 또는 비밀번호가 일치하지 않습니다", Toast.LENGTH_SHORT).show()
},
contentPadding = PaddingValues(start = 90.dp, end = 90.dp),
colors = ButtonDefaults.buttonColors(
Expand Down Expand Up @@ -194,6 +191,6 @@ fun SoptComposable(
@Composable
fun LoginPreview() {
NOWSOPTAndroidTheme {
SoptComposable(getId ="", getPassword ="", getName = "", getMbti = "")
SoptComposable(getId ="", getPassword ="", getNickname = "", getMbti = "")
}
}
25 changes: 13 additions & 12 deletions app/src/main/java/com/sopt/now/compose/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -27,16 +25,16 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
val id = intent.getStringExtra("id")
val password = intent.getStringExtra("password")
val name = intent.getStringExtra("name")
val nickname = intent.getStringExtra("nickname")

setContent {
MainActivityContent(id ?: "", password ?: "", name ?: "")
MainActivityContent(id = id ?: "", password = password ?: "", nickname = nickname?: "")
}
}
}

@Composable
fun MainActivityContent(id: String, password: String, name: String) {
fun MainActivityContent(id: String, password: String, nickname: String) {
Column(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -49,31 +47,34 @@ fun MainActivityContent(id: String, password: String, name: String) {
contentDescription = null,
modifier = Modifier
.aspectRatio(1.5f) // aspectRatio 설정
.padding(top = 16.dp)
.padding(top = 30.dp)
.padding(bottom = 10.dp)
)
UserInfoComposable(id = id, password = password, name = name)
UserInfoComposable(id, password, nickname)
}
}

@Composable
fun UserInfoComposable(id: String, password: String, name: String) {
fun UserInfoComposable(id: String, password: String, nickname: String) {
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = "안녕하세요 $name 님! \n",
Text(text = "안녕하세요, $id 님!\n",
fontSize = 24.sp,
fontWeight = FontWeight.ExtraBold)
Text(text = "아이디: \n$id\n",

Text(text = "아이디: $id \n",
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
color = PurpleGrey40)
Text(text = "비밀번호: \n$password\n",

Text(text = "비밀번호: $password \n",
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
color = PurpleGrey40)


Button(
onClick = { },

Expand All @@ -99,7 +100,7 @@ fun MainPreview() {
UserInfoComposable(
id = "exampleId",
password = "examplePassword",
name = "exampleName",
nickname = "exampleNickname"
)
}
}
17 changes: 8 additions & 9 deletions app/src/main/java/com/sopt/now/compose/SignupActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme
class UserInfo(
val userId: String,
val userPassword: String,
val userName: String,
val userNickname: String,
val userMbti: String
)

Expand All @@ -50,7 +50,7 @@ fun Signup () {
{
var userId by remember { mutableStateOf("") }
var userPassword by remember { mutableStateOf("") }
var userName by remember { mutableStateOf("") }
var userNickname by remember { mutableStateOf("") }
var userMbti by remember { mutableStateOf("") }

Text(
Expand Down Expand Up @@ -107,8 +107,8 @@ fun Signup () {
)

TextField(
value = userName,
onValueChange = { newValue -> userName = newValue },
value = userNickname,
onValueChange = { newValue -> userNickname = newValue },
modifier = Modifier
.fillMaxWidth(),
label = { Text("닉네임을 입력하세요(공백 안됨)") },
Expand Down Expand Up @@ -138,14 +138,13 @@ fun Signup () {
val context = LocalContext.current

Button(onClick = {
if (CheckId(context, userId) && CheckPassword(context, userPassword) && CheckName(context, userName) && CheckMbti(context, userMbti)) {
if (CheckId(context, userId) && CheckPassword(context, userPassword) && CheckNickname(context, userNickname) && CheckMbti(context, userMbti)) {
val intent = Intent(context, LoginActivity::class.java).apply {
putExtra("id", userId)
putExtra("password", userPassword)
putExtra("name", userName)
putExtra("nickname", userNickname)
putExtra("mbti", userMbti)
}

context.startActivity(intent) // 회원가입 성공 시 MainActivity로 이동
Toast.makeText(context, "회원가입 성공!", Toast.LENGTH_SHORT).show()

Expand Down Expand Up @@ -178,8 +177,8 @@ fun CheckPassword(context: Context, password: String): Boolean {
}
}

fun CheckName(context: Context, name: String): Boolean {
if (name.isNotBlank() && name.length > 1) {
fun CheckNickname(context: Context, nickname: String): Boolean {
if (nickname.isNotBlank() && nickname.length > 1) {
return true
} else {
Toast.makeText(context, "닉네임은 2자 이상의 유효한 문자로 입력해주세요", Toast.LENGTH_SHORT).show()
Expand Down

0 comments on commit f97ef80

Please sign in to comment.