11package com.paw.key.core.designsystem.component
22
3- import android.util.Log
43import androidx.compose.foundation.Image
54import androidx.compose.foundation.background
65import androidx.compose.foundation.clickable
@@ -16,7 +15,6 @@ import androidx.compose.foundation.layout.padding
1615import androidx.compose.foundation.layout.size
1716import androidx.compose.foundation.layout.width
1817import androidx.compose.foundation.shape.CircleShape
19- import com.paw.key.R
2018import androidx.compose.foundation.shape.RoundedCornerShape
2119import androidx.compose.material3.HorizontalDivider
2220import androidx.compose.material3.Icon
@@ -39,25 +37,39 @@ import androidx.compose.ui.tooling.preview.Preview
3937import androidx.compose.ui.unit.dp
4038import coil.compose.AsyncImage
4139import coil.request.ImageRequest
40+ import com.paw.key.R
4241import com.paw.key.core.designsystem.theme.PawKeyTheme
4342import com.paw.key.core.util.noRippleClickable
44- import kotlin.String
4543
4644@Composable
4745fun CourseCard (
4846 title : String ,
49- petName : String ,
47+ petName : String ,
5048 date : String ,
51- onCLickItem : () -> Unit ,
49+ representativeImageUrl : String? = null, // 추가
50+ petProfileImageUrl : String? = null, // 추가
51+ descriptionTags : List <String > = emptyList(), // 추가
52+ onCLickItem : () -> Unit ,
5253 modifier : Modifier = Modifier ,
53- isShared : Boolean = false, // true면 떠진거 false면 닫은거
54- isRecord : Boolean = false // 기록한 아이템 - true면 하트, false면 공유 아이콘
54+ isShared : Boolean = false,
55+ isRecord : Boolean = false
5556) {
57+ // 날짜 포맷 변환 함수
58+ fun formatDate (dateString : String ): String {
59+ return try {
60+ // "2025-07-15T21:27:03.54498" -> "2025/07/15"
61+ val datePart = dateString.split(" T" )[0 ] // "2025-07-15"
62+ datePart.replace(" -" , " /" ) // "2025/07/15"
63+ } catch (e: Exception ) {
64+ dateString // 실패하면 원본 반환
65+ }
66+ }
67+
5668 Column (
5769 modifier = modifier
5870 .padding(8 .dp)
5971 .fillMaxWidth()
60- .size(width = 328 .dp , height = 240 .dp)
72+ .size(width = 328 .dp, height = 240 .dp)
6173 .background(Color .White , shape = RoundedCornerShape (20 .dp))
6274 .noRippleClickable {
6375 onCLickItem()
@@ -70,32 +82,38 @@ fun CourseCard(
7082 .aspectRatio(343f / 172f )
7183 .clip(RoundedCornerShape (10 .dp))
7284 ) {
73- // 지도 이미지 Todo : 테스트용
74- Image (
75- painter = painterResource(id = R .drawable.dummy_map),
76- contentDescription = null ,
77- modifier = Modifier
78- .fillMaxSize()
79- .padding(start = 8 .dp, end = 8 .dp, top = 8 .dp)
80- .clip(RoundedCornerShape (8 .dp)),
81- contentScale = ContentScale .Crop
82- )
83-
84- /* AsyncImage(
85- model = ImageRequest.Builder(LocalContext.current)
86- .data("https://pawkey-server.com/image.jpg") // ← 서버에서 받은 이미지 URL 넣깅
87- .crossfade(true)
88- .build(),
89- contentDescription = null,
90- modifier = Modifier.fillMaxSize(),
91- contentScale = ContentScale.Crop
92- )*/
85+ // 서버 이미지 또는 기본 이미지
86+ if (representativeImageUrl != null ) {
87+ AsyncImage (
88+ model = ImageRequest .Builder (LocalContext .current)
89+ .data(representativeImageUrl)
90+ .crossfade(true )
91+ .build(),
92+ contentDescription = null ,
93+ modifier = Modifier
94+ .fillMaxSize()
95+ .padding(start = 8 .dp, end = 8 .dp, top = 8 .dp)
96+ .clip(RoundedCornerShape (8 .dp)),
97+ contentScale = ContentScale .Crop
98+ )
99+ } else {
100+ // 기본 이미지
101+ Image (
102+ painter = painterResource(id = R .drawable.dummy_map),
103+ contentDescription = null ,
104+ modifier = Modifier
105+ .fillMaxSize()
106+ .padding(start = 8 .dp, end = 8 .dp, top = 8 .dp)
107+ .clip(RoundedCornerShape (8 .dp)),
108+ contentScale = ContentScale .Crop
109+ )
110+ }
93111
94112 // 하단 그라데이션 오버레이
95113 Box (
96114 modifier = Modifier
97115 .fillMaxWidth()
98- .height(LocalConfiguration .current.screenHeightDp.dp * 0.6f ) // 높이 조절 가능
116+ .height(LocalConfiguration .current.screenHeightDp.dp * 0.6f )
99117 .padding(start = 8 .dp, end = 8 .dp, top = 8 .dp)
100118 .align(Alignment .BottomCenter )
101119 .background(
@@ -115,19 +133,39 @@ fun CourseCard(
115133 verticalAlignment = Alignment .CenterVertically ,
116134 modifier = Modifier
117135 .align(Alignment .BottomStart )
118- .padding(start = 16 .dp, end = 16 .dp,bottom = 16 .dp)
136+ .padding(start = 16 .dp, end = 16 .dp, bottom = 16 .dp)
119137 ) {
120- AsyncImage (
121- model = ImageRequest .Builder (LocalContext .current)
122- .data(" https://pawkey-server.com/image.jpg" ) // ← 서버에서 받은 이미지 URL 넣깅
123- .crossfade(true )
124- .build(),
125- contentDescription = null ,
126- modifier = Modifier
127- .size(40 .dp)
128- .clip(CircleShape ), // 원형 크롭
129- contentScale = ContentScale .Crop
130- )
138+ // 반려견 프로필 이미지
139+ if (petProfileImageUrl != null ) {
140+ AsyncImage (
141+ model = ImageRequest .Builder (LocalContext .current)
142+ .data(petProfileImageUrl)
143+ .crossfade(true )
144+ .build(),
145+ contentDescription = null ,
146+ modifier = Modifier
147+ .size(40 .dp)
148+ .clip(CircleShape ),
149+ contentScale = ContentScale .Crop
150+ )
151+ } else {
152+ // 기본 프로필 이미지
153+ Box (
154+ modifier = Modifier
155+ .size(40 .dp)
156+ .clip(CircleShape )
157+ .background(PawKeyTheme .colors.gray200),
158+ contentAlignment = Alignment .Center
159+ ) {
160+ Icon (
161+ imageVector = ImageVector .vectorResource(id = R .drawable.ic_heart_default),
162+ contentDescription = null ,
163+ tint = PawKeyTheme .colors.gray400,
164+ modifier = Modifier .size(20 .dp)
165+ )
166+ }
167+ }
168+
131169 Spacer (modifier = Modifier .width(10 .dp))
132170 Column {
133171 Text (
@@ -144,7 +182,7 @@ fun CourseCard(
144182 )
145183 Spacer (modifier = Modifier .width(8 .dp))
146184 Text (
147- text = date,
185+ text = formatDate( date), // 포맷된 날짜 사용
148186 style = PawKeyTheme .typography.caption12R,
149187 color = PawKeyTheme .colors.gray100
150188 )
@@ -189,16 +227,9 @@ fun CourseCard(
189227
190228 Spacer (modifier = Modifier .height(12 .dp))
191229
192-
230+ // 서버에서 받은 태그들 사용
193231 ChipRow (
194- tags = listOf (
195- " 이륜차 거의 없음" ,
196- " 배변 쓰레기통" ,
197- " 쉼터" ,
198- " CCTV 있음" ,
199- " 물그릇 비치" ," 이륜차 거의 없음" ,
200- " 배변 쓰레기통" ,
201- " 쉼터" ,),
232+ tags = descriptionTags,
202233 modifier = Modifier
203234 .padding(start = 16 .dp, end = 16 .dp)
204235 )
0 commit comments