Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#6 week2 compose 필수과제 구현 #8

Merged
merged 17 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.sopt.now.compose

import androidx.compose.ui.graphics.vector.ImageVector

data class BottomNavigationItem(
val icon: ImageVector,
val label: String
)
9 changes: 9 additions & 0 deletions app/src/main/java/com/sopt/now/compose/Friend.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sopt.now.compose

import androidx.compose.ui.graphics.vector.ImageVector

data class Friend(
val profileImage: ImageVector,
val name: String,
val selfDescription: String,
)
50 changes: 50 additions & 0 deletions app/src/main/java/com/sopt/now/compose/FriendProfileItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.sopt.now.compose

import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp


@Composable
fun FriendProfileItem(friend: Friend) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

friend를 넣어주는 것도 좋지만, 저는 각각 나눠서 넣어주는 것을 더 선호합니다.

만약 friend내부 객체가 바뀐다면?
friend가 아닌 객체도 해당 함수를 재사용하게 된다면?
ui테스트를 위해 Preview를 만들 때 객체도 생성해야 하는 불편함

이런 부분들을 생각해서 저는 image, name, description 등등.. 나눠서 넣어주는걸 선호합니다

Row(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 10.dp),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
modifier = Modifier.size(50.dp),
imageVector = friend.profileImage,
contentDescription = null
)
Spacer(modifier = Modifier.width(10.dp))
Text(
text = friend.name,
fontSize = 14.sp,
fontWeight = FontWeight.Bold,
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
Spacer(modifier = Modifier.width(30.dp))
Spacer(modifier = Modifier.weight(1f))
Text(
text = friend.selfDescription,
fontSize = 10.sp,
overflow = TextOverflow.Ellipsis,
maxLines = 1
)
}
}
116 changes: 116 additions & 0 deletions app/src/main/java/com/sopt/now/compose/HomeUi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.sopt.now.compose

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Person
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun HomeUi() {
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
LazyColumn {
items(userList) {
UserProfileItem(it)
}
items(friendList) {
FriendProfileItem(it)
}
}
}
}
val userList = listOf<User>(
User(
profileImage = R.drawable.cute,
name = "송혜음",
selfDescription = "여러분 보고 시퍼yo 훌쩍훌쩍"
)
)

val friendList = listOf<Friend>(
Friend(
profileImage = Icons.Filled.Person,
name = "박동민",
selfDescription = "곽의진...얼굴 재치 실력 모든걸 다 가진 남자... 하지만 밀양박씨 36대손인 나 박동민은 가지지 못했지"
),
Friend(
profileImage = Icons.Filled.Person,
name = "이석준",
selfDescription = "죄송합니다 저 도핑했습니다... 안드-로이더 \uD83D\uDC89"
),
Friend(
profileImage = Icons.Filled.Person,
name = "박유진",
selfDescription = "(ง˙∇˙)ว 에라 모르겠다"
),Friend(
profileImage = Icons.Filled.Person,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지?"
),
Friend(
profileImage = Icons.Filled.Person,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐"
),
Friend(
profileImage = Icons.Filled.Person,
name = "배지현",
selfDescription = "표정 풀자 ^^"
),
Friend(
profileImage = Icons.Filled.Person,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지?"
),
Friend(
profileImage = Icons.Filled.Person,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐"
),
Friend(
profileImage = Icons.Filled.Person,
name = "배지현",
selfDescription = "표정 풀자 ^^"
),
Friend(
profileImage = Icons.Filled.Person,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지?"
),
Friend(
profileImage = Icons.Filled.Person,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐"
),
Friend(
profileImage = Icons.Filled.Person,
name = "배지현",
selfDescription = "표정 풀자 ^^"
),
Friend(
profileImage = Icons.Filled.Person,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지?"
),
Friend(
profileImage = Icons.Filled.Person,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐"
),
Friend(
profileImage = Icons.Filled.Person,
name = "배지현",
selfDescription = "표정 풀자 ^^"
)
)
63 changes: 39 additions & 24 deletions app/src/main/java/com/sopt/now/compose/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sopt.now.compose

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
Expand Down Expand Up @@ -47,15 +48,15 @@ class LoginActivity : ComponentActivity() {
val userId = intent.getStringExtra("userId")
val userPw = intent.getStringExtra("userPw")
val userNick = intent.getStringExtra("userNick")
LoginUI(userId,userPw,userNick)
LoginUI(userId, userPw, userNick)
}
}
}
}
}
//로그인 화면

@Composable
fun LoginUI(userId: String?="", userPw:String?="", userNick:String?="") {
fun LoginUI(userId: String?, userPw: String?, userNick: String?) {
val context = LocalContext.current
var id by remember { mutableStateOf("") }
var pw by remember { mutableStateOf("") }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이름이 UI이기 때문에 id와 pw도 SatateHoisting을 활용해 값을 상단으로 빼는건 어떨까요??
LoginUI에는 UI와 관련된 부분만 존재하고, 값을 수정하거나 클릭했을때의 액션은 밖으로 빼는게 좋아 보입니다!

Expand All @@ -76,41 +77,32 @@ fun LoginUI(userId: String?="", userPw:String?="", userNick:String?="") {
)
TextField(
value = id,
onValueChange = {id = it},
onValueChange = { id = it },
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
placeholder = {Text(stringResource(R.string.tf_login_id))},
placeholder = { Text(stringResource(R.string.tf_login_id)) },
singleLine = true,
leadingIcon = { Icon(Icons.Filled.Person,contentDescription = "User Icon") }
)
leadingIcon = { Icon(Icons.Filled.Person, contentDescription = "User Icon") }
)
Spacer(modifier = Modifier.height(30.dp))
Text(text = stringResource(R.string.text_pw))
TextField(
value = pw,
onValueChange = {pw = it},
onValueChange = { pw = it },
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
placeholder = {Text(stringResource(R.string.tf_login_pw))},
placeholder = { Text(stringResource(R.string.tf_login_pw)) },
singleLine = true,
visualTransformation = PasswordVisualTransformation(),
leadingIcon = { Icon(Icons.Filled.Person,contentDescription = "User Icon") },
leadingIcon = { Icon(Icons.Filled.Person, contentDescription = "User Icon") },
)
Spacer(modifier = Modifier.weight(1f))
Button(
onClick = {
val message = when{
userId != id || userPw != pw -> context.getString(R.string.login_error)
else -> {
val intent = Intent(context, MainActivity::class.java)
intent.putExtra("userId",userId).putExtra("userPw", userPw).putExtra("userNick", userNick)
context.startActivity(intent)
context.getString(R.string.login_success)
}
}
Toast.makeText(context,message,Toast.LENGTH_SHORT).show()
},
isLoginAvailable(context, userId, userPw, userNick, id, pw)
},
modifier = Modifier
.fillMaxWidth()
) {
Expand All @@ -119,20 +111,43 @@ fun LoginUI(userId: String?="", userPw:String?="", userNick:String?="") {
Spacer(modifier = Modifier.height(20.dp))
Button(
onClick = {
val intent = Intent(context,SignUpActivity::class.java)
val intent = Intent(context, SignUpActivity::class.java)
context.startActivity(intent)
},
},
modifier = Modifier
.fillMaxWidth()
) {
Text(stringResource(R.string.btn_sign_up))
}
}
}

fun isLoginAvailable(
context: Context,
userId: String?,
userPw: String?,
userNick: String?,
id: String?,
pw: String?
) {
val message = when {
userId != id || userPw != pw -> R.string.login_error
else -> {
val intent = Intent(context, MainActivity::class.java).apply {
putExtra("userId", userId)
putExtra("userPw", userPw)
putExtra("userNick", userNick)
}
context.startActivity(intent)
R.string.login_success
}
}
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview2() {
NOWSOPTAndroidTheme {
LoginUI()
LoginUI("아이디", "비밀번호", "닉네임")
}
}
Loading