-
Notifications
You must be signed in to change notification settings - Fork 35
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
Step4 - 페이먼츠(카드 수정) #53
base: oyj7677
Are you sure you want to change the base?
Changes from 13 commits
9ef8565
2343f5c
3cbdfb5
af3e538
366b597
9a10420
9e3eaa0
d319fbb
c577a00
73c0d77
b328592
9fcbb3d
8a81524
aa82010
1b91e7f
12b22a6
4a39882
656f36a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
package nextstep.payments.data | ||
|
||
import androidx.compose.ui.graphics.Color | ||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class Card( | ||
val id: Int, | ||
val cardNumber: String, | ||
val expiredDate: String, | ||
val ownerName: String, | ||
val password: String, | ||
val brandColor: Color | ||
) | ||
val bankType: BankType | ||
) : Parcelable |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,13 @@ object PaymentCardsRepository { | |
fun removeAllCard() { | ||
_cards.clear() | ||
} | ||
|
||
fun editCard(oldCard: Card?, newCard: Card) { | ||
val index = _cards.indexOfFirst { it.id == oldCard!!.id } | ||
_cards[index] = newCard | ||
} | ||
|
||
fun createId(): Int { | ||
return _cards.maxOfOrNull { it.id }?.plus(1) ?: 1 | ||
} | ||
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. 도메인에 너무 많은 신경을 쓰지 않고 학습 목표에 집중한 구현을 해주셨네요! (선택사항) 그래도 혹시 구조를 개선하고 싶으시다면 다음 변경사항을 만들어 유지보수성을 높여보시는건 어떨까요?
마지막 단계이니까 편하게 도전해보시죠! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
package nextstep.payments.ui | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
|
@@ -26,12 +28,14 @@ import nextstep.payments.ui.card.list.component.card.CardOwnerName | |
|
||
@Composable | ||
fun PaymentCard( | ||
brandColor: Color, | ||
modifier: Modifier = Modifier, | ||
brandColor: Color = Color(0xFF333333) | ||
content: @Composable () -> Unit = {} | ||
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. 의도대로 리뷰를 넘 잘 반영해주셨습니다 👍 |
||
) { | ||
Box( | ||
contentAlignment = Alignment.CenterStart, | ||
modifier = modifier | ||
.padding(top = 10.dp) | ||
.shadow(8.dp) | ||
.size(width = 208.dp, height = 124.dp) | ||
.background( | ||
|
@@ -49,19 +53,25 @@ fun PaymentCard( | |
shape = RoundedCornerShape(4.dp), | ||
) | ||
) | ||
content() | ||
} | ||
} | ||
|
||
@Composable | ||
fun PaymentCard( | ||
fun PaymentCardContents( | ||
card: Card, | ||
modifier: Modifier = Modifier, | ||
content: @Composable () -> Unit = {} | ||
onClick: (Card) -> Unit = {} | ||
) { | ||
Box( | ||
modifier = Modifier.padding(top = 10.dp) | ||
modifier = Modifier | ||
.clickable { onClick(card) } | ||
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. 혹시 modifier 파라미터는 왜 사라졌을까요? 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. |
||
) { | ||
content() | ||
Text( | ||
text = card.bankType.name, | ||
color = Color.White, | ||
modifier = Modifier | ||
.padding(start = 14.dp, top = 10.dp) | ||
) | ||
|
||
CardNumber( | ||
cardNumber = card.cardNumber, | ||
|
@@ -90,24 +100,20 @@ fun PaymentCard( | |
|
||
@Preview | ||
@Composable | ||
private fun PaymentCardPreview() { | ||
PaymentCard( | ||
brandColor = colorResource(id = BankType.BC.brandColor) | ||
private fun NewPaymentCardPreview() { | ||
val card = Card( | ||
id = 1, | ||
cardNumber = "1234-5678-1234-5678", | ||
ownerName = "홍길동", | ||
expiredDate = "12/34", | ||
password = "123", | ||
bankType = BankType.BC | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun NewPaymentCardPreview() { | ||
PaymentCard( | ||
card = Card( | ||
cardNumber = "1234-5678-1234-5678", | ||
ownerName = "홍길동", | ||
expiredDate = "12/34", | ||
password = "123", | ||
brandColor = colorResource(id = BankType.BC.brandColor) | ||
), | ||
modifier = Modifier.size(width = 208.dp, height = 124.dp), | ||
content = { PaymentCard() } | ||
brandColor = colorResource(id = BankType.BC.brandColor), | ||
content = { | ||
PaymentCardContents(card = card) | ||
} | ||
) | ||
} |
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.
혹시 어떤 이유로 추가된걸까요~?