Skip to content

Commit

Permalink
Merge pull request #3 from NOW-SOPT-ANDROID/feat/#1-week1-compose-ess…
Browse files Browse the repository at this point in the history
…ential

[feat/#2] week1 - compose / essential(필수)
  • Loading branch information
nagaeng authored Apr 7, 2024
2 parents a6d26cd + f97ef80 commit 145a623
Show file tree
Hide file tree
Showing 5 changed files with 517 additions and 20 deletions.
12 changes: 11 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:theme="@style/Theme.NOWSOPTAndroid"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".LoginActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid">
Expand All @@ -23,6 +23,16 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid" />
<activity
android:name=".SignupActivity"
android:exported="false"
android:label="@string/app_name"
android:theme="@style/Theme.NOWSOPTAndroid" />
</application>

</manifest>
196 changes: 196 additions & 0 deletions app/src/main/java/com/sopt/now/compose/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package com.sopt.now.compose

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
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.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat.startActivity
import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme

class LoginActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

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

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

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

if (!isLogged) {
SoptComposable(
getId = getId,
getPassword = getPassword,
getNickname = getNickname,
getMbti = getMbti
)
} else {
val context = LocalContext.current
context.startActivity(Intent(context, MainActivity::class.java))
}
}

fun isValid(userId: String?, userPassword: String?, getId: String, getPassword: String): Boolean {
return userId != "" && userPassword != "" && userId == getId && userPassword == getPassword
}

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("nickname", userNickname)
putExtra("mbti", userMbti)
}
context.startActivity(intent)
Toast.makeText(context, "로그인 성공!", Toast.LENGTH_SHORT).show()
}

@Composable
fun SoptComposable(
getId: String,
getPassword: String,
getNickname: String,
getMbti: String

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

Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.height(30.dp))

Text(
text = "Welcome To SOPT",
color = Color.Gray,
fontWeight = FontWeight.Bold,
fontSize = 30.sp,
modifier = Modifier.align(Alignment.CenterHorizontally),
)

// Welcome 문구와 ID 텍스트 사이의 간격
Spacer(modifier = Modifier.height(100.dp)) // 중간 간격을 위한 투명 view

// ID 입력하는 부분 (ID 텍스트는 좌측 정렬, 텍스트 필드는 중앙 정렬)
Column(verticalArrangement = Arrangement.Center) {
Text(text = "ID")

TextField(
value = userId,
onValueChange = { userId = it },
label = { Text("ID를 입력하세요") },
placeholder = { Text("EX) helen0816") },
singleLine = true,
)
}

// ID 텍스트 필드와 PASSWORD 텍스트 사이의 간격
Spacer(modifier = Modifier.height(50.dp)) // 중간 간격을 위한 투명 view

// PW 입력하는 부분 (PW 텍스트는 좌측 정렬, 텍스트 필드는 중앙 정렬)
Column(verticalArrangement = Arrangement.Center) {
Text(text = "PASSWORD")

TextField(
value = userPassword,
onValueChange = { userPassword = it },
label = { Text("PASSWORD를 입력하세요") },
placeholder = { Text("EX) qwaszx@!") },
singleLine = true,
)
}

// PW 텍스트 필드와 버튼 사이의 간격
Spacer(modifier = Modifier.height(250.dp)) // 중간 간격을 위한 투명 view

val context = LocalContext.current

Button(
onClick = { if (isValid(userId, userPassword, getId ?: "", getPassword ?: "")) {
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(
containerColor = Color.LightGray,
contentColor = Color.Black
)
) {
Text(text = "로그인",
fontWeight = FontWeight.Bold,
)
}

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

Button(
onClick = {
val intent = Intent(context, SignupActivity::class.java)
context.startActivity(intent)
},
contentPadding = PaddingValues(start = 90.dp, end = 90.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.LightGray,
contentColor = Color.Black
)
)
{
Text(text = "회원가입",
fontWeight = FontWeight.Bold,
)
}

}
}
@Preview(showBackground = true)

@Composable
fun LoginPreview() {
NOWSOPTAndroidTheme {
SoptComposable(getId ="", getPassword ="", getNickname = "", getMbti = "")
}
}
98 changes: 79 additions & 19 deletions app/src/main/java/com/sopt/now/compose/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,104 @@ package com.sopt.now.compose
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sopt.now.compose.ui.theme.NOWSOPTAndroidTheme
import com.sopt.now.compose.ui.theme.PurpleGrey40

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val id = intent.getStringExtra("id")
val password = intent.getStringExtra("password")
val nickname = intent.getStringExtra("nickname")

setContent {
NOWSOPTAndroidTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
}
MainActivityContent(id = id ?: "", password = password ?: "", nickname = nickname?: "")
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
fun MainActivityContent(id: String, password: String, nickname: String) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image (
painter = painterResource(id = R.drawable.apple), // 이미지 리소스 추가
contentDescription = null,
modifier = Modifier
.aspectRatio(1.5f) // aspectRatio 설정
.padding(top = 30.dp)
.padding(bottom = 10.dp)
)
UserInfoComposable(id, password, nickname)
}
}

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

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

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


Button(
onClick = { },

contentPadding = PaddingValues(start = 90.dp, end = 90.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color.LightGray,
contentColor = Color.Black
)
) {
Text(text = "수정하기",
fontWeight = FontWeight.Bold,
)
}
}

}


@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
fun MainPreview() {
NOWSOPTAndroidTheme {
Greeting("Android")
UserInfoComposable(
id = "exampleId",
password = "examplePassword",
nickname = "exampleNickname"
)
}
}
Loading

0 comments on commit 145a623

Please sign in to comment.