generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 11 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7902a9f
feat/#6: 2주차 과제 (통짜 커밋 죄송합니다...)
hyeeum ef34ff3
chore/#6: 함수명 변경
hyeeum fab60f3
del/#6: 사용하지 않는 import 제거
hyeeum ecae46e
mod/#6: 마이페이지(프로필) 분리
hyeeum ea1f004
del/#6: 사용하지 않는 import 제거
hyeeum 3de8f5c
rename/#6: 파일명 변경
hyeeum 807561c
mod/#6: 컴포저블 내 함수 분리
hyeeum 7ed99ae
mod/#6: 컴포저블 내 함수 분리(로그인)
hyeeum 1fbcccd
chore/#6: 함수 아래로 보내기
hyeeum b5228b0
chore/#6: scope 함수 사용해보기..
hyeeum 164ef70
chore/#6: 데이터 추가하기
hyeeum 04e32f5
ui/#6: 유저-친구 구분선 추가
hyeeum 13839c3
mod/#6: PR 적용 - companion object
hyeeum d61212e
mod/#6: PR 적용 - 함수 분리
hyeeum 8fa89cc
feat/#6: HOME 뷰모델 적용
hyeeum e8eb195
mod#6/:PR 적용
hyeeum b906358
del#6/: 잘못 올라간 파일 삭제
hyeeum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/sopt/now/compose/BottomNavigationItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
50
app/src/main/java/com/sopt/now/compose/FriendProfileItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
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 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "표정 풀자 ^^" | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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("") } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이름이 UI이기 때문에 id와 pw도 SatateHoisting을 활용해 값을 상단으로 빼는건 어떨까요?? |
||
|
@@ -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() | ||
) { | ||
|
@@ -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("아이디", "비밀번호", "닉네임") | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 등등.. 나눠서 넣어주는걸 선호합니다