|
1 | 1 | package com.apptive.japkor.ui.main.mypage |
2 | 2 |
|
3 | | -import androidx.compose.foundation.layout.Box |
4 | | -import androidx.compose.foundation.layout.fillMaxSize |
| 3 | +import androidx.compose.foundation.Image |
| 4 | +import androidx.compose.foundation.background |
| 5 | +import androidx.compose.foundation.layout.* |
| 6 | +import androidx.compose.foundation.rememberScrollState |
| 7 | +import androidx.compose.foundation.shape.CircleShape |
| 8 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 9 | +import androidx.compose.foundation.verticalScroll |
| 10 | +import androidx.compose.material3.HorizontalDivider |
| 11 | +import androidx.compose.material3.Surface |
5 | 12 | import androidx.compose.runtime.Composable |
| 13 | +import androidx.compose.runtime.collectAsState |
| 14 | +import androidx.compose.runtime.getValue |
6 | 15 | import androidx.compose.ui.Alignment |
7 | 16 | import androidx.compose.ui.Modifier |
| 17 | +import androidx.compose.ui.draw.clip |
| 18 | +import androidx.compose.ui.draw.drawBehind |
| 19 | +import androidx.compose.ui.geometry.CornerRadius |
| 20 | +import androidx.compose.ui.graphics.Color |
| 21 | +import androidx.compose.ui.graphics.PathEffect |
| 22 | +import androidx.compose.ui.graphics.drawscope.Stroke |
| 23 | +import androidx.compose.ui.layout.ContentScale |
| 24 | +import androidx.compose.ui.platform.LocalContext |
| 25 | +import androidx.compose.ui.unit.Dp |
| 26 | +import androidx.compose.ui.unit.dp |
| 27 | +import coil.compose.rememberAsyncImagePainter |
| 28 | +import com.apptive.japkor.data.local.DataStoreManager |
| 29 | +import com.apptive.japkor.data.local.DataStoreManager.MyProfileUiModel |
| 30 | +import com.apptive.japkor.ui.components.CommonHeader |
8 | 31 | import com.apptive.japkor.ui.components.CustomText |
9 | 32 | import com.apptive.japkor.ui.components.CustomTextType |
10 | 33 | import com.apptive.japkor.ui.theme.CustomColor |
11 | 34 |
|
12 | 35 | @Composable |
13 | | -fun MypageScreen(modifier: Modifier = Modifier) { |
14 | | - Box( |
15 | | - modifier = modifier.fillMaxSize(), |
16 | | - contentAlignment = Alignment.Center |
| 36 | +fun MypageScreen( |
| 37 | + modifier: Modifier = Modifier, |
| 38 | + showBackButton: Boolean = true, |
| 39 | + onBack: (() -> Unit)? = null, |
| 40 | +) { |
| 41 | + val context = LocalContext.current |
| 42 | + val dataStoreManager = DataStoreManager(context) |
| 43 | + |
| 44 | + val profile by dataStoreManager.getMyProfileUiModel() |
| 45 | + .collectAsState(initial = null) |
| 46 | + |
| 47 | + Column( |
| 48 | + modifier = modifier |
| 49 | + .fillMaxSize() |
| 50 | + .background(Color.White) |
| 51 | + ) { |
| 52 | + CommonHeader( |
| 53 | + title = "마이페이지", |
| 54 | + showBackButton = showBackButton, |
| 55 | + onBack = onBack |
| 56 | + ) |
| 57 | + |
| 58 | + Column( |
| 59 | + modifier = Modifier |
| 60 | + .fillMaxWidth() |
| 61 | + .verticalScroll(rememberScrollState()) |
| 62 | + .padding(horizontal = 16.dp) |
| 63 | + ) { |
| 64 | + Spacer(Modifier.height(16.dp)) |
| 65 | + |
| 66 | + MyProfileCard(profile = profile) |
| 67 | + |
| 68 | + Spacer(Modifier.height(24.dp)) |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +@Composable |
| 74 | +private fun MyProfileCard(profile: MyProfileUiModel?) { |
| 75 | + Column( |
| 76 | + modifier = Modifier |
| 77 | + .fillMaxWidth() |
| 78 | + .dashedBorder( |
| 79 | + color = Color(0xFFD7D7D7), |
| 80 | + strokeWidth = 1.dp, |
| 81 | + cornerRadius = 14.dp |
| 82 | + ) |
| 83 | + .padding(16.dp) |
| 84 | + ) { |
| 85 | + // My Profile pill |
| 86 | + Box( |
| 87 | + modifier = Modifier |
| 88 | + .fillMaxWidth(), |
| 89 | + contentAlignment = Alignment.Center |
| 90 | + ) { |
| 91 | + Surface( |
| 92 | + shape = RoundedCornerShape(999.dp), |
| 93 | + color = Color.White, |
| 94 | + shadowElevation = 0.dp, |
| 95 | + tonalElevation = 0.dp |
| 96 | + ) { |
| 97 | + Box( |
| 98 | + modifier = Modifier |
| 99 | + .background(Color.White, RoundedCornerShape(999.dp)) |
| 100 | + .drawBehind { } |
| 101 | + .padding(horizontal = 14.dp, vertical = 6.dp) |
| 102 | + ) { |
| 103 | + CustomText( |
| 104 | + text = "My Profile", |
| 105 | + type = CustomTextType.body, |
| 106 | + color = CustomColor.gray400 |
| 107 | + ) |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + Spacer(Modifier.height(12.dp)) |
| 113 | + |
| 114 | + Row(verticalAlignment = Alignment.CenterVertically) { |
| 115 | + //ProfileImageWithBadge(imageUrl = profile?.thumbnailImageUrl) // 돋보기 있는 버전 |
| 116 | + ProfileImage(imageUrl = profile?.thumbnailImageUrl) |
| 117 | + |
| 118 | + Spacer(Modifier.width(12.dp)) |
| 119 | + |
| 120 | + Column { |
| 121 | + CustomText( |
| 122 | + text = profile?.name?.ifBlank { "—" } ?: "—", |
| 123 | + type = CustomTextType.headline, |
| 124 | + color = CustomColor.black |
| 125 | + ) |
| 126 | + } |
| 127 | + } |
| 128 | + |
| 129 | + Spacer(Modifier.height(14.dp)) |
| 130 | + HorizontalDivider(color = CustomColor.gray100) |
| 131 | + Spacer(Modifier.height(10.dp)) |
| 132 | + |
| 133 | + InfoRow(label = "지역", value = profile?.residenceArea ?: "—") |
| 134 | + InfoRow(label = "흡연", value = profile?.smokingStatus ?: "—") |
| 135 | + InfoRow(label = "음주", value = profile?.drinkingFrequency ?: "—") |
| 136 | + InfoRow(label = "학력", value = profile?.education ?: "—") |
| 137 | + InfoRow( |
| 138 | + label = "종교", |
| 139 | + value = profile?.religion ?: "—" |
| 140 | + ) |
| 141 | + |
| 142 | + Spacer(Modifier.height(12.dp)) |
| 143 | + Box( |
| 144 | + modifier = Modifier |
| 145 | + .fillMaxWidth() |
| 146 | + .padding( |
| 147 | + horizontal = 13.dp, |
| 148 | + vertical = 12.dp |
| 149 | + ) |
| 150 | + ) { |
| 151 | + CustomText( |
| 152 | + text = "이미 심사 통과한 프로필은 수정이 어려워요.", |
| 153 | + type = CustomTextType.body, |
| 154 | + color = CustomColor.gray300 |
| 155 | + ) |
| 156 | + } |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +@Composable |
| 161 | +private fun ProfileImage(imageUrl: String?) { |
| 162 | + val painter = rememberAsyncImagePainter(model = imageUrl) |
| 163 | + |
| 164 | + Image( |
| 165 | + painter = painter, |
| 166 | + contentDescription = "profile", |
| 167 | + contentScale = ContentScale.Crop, |
| 168 | + modifier = Modifier |
| 169 | + .size(64.dp) |
| 170 | + .clip(CircleShape) // ✅ 원형 |
| 171 | + .background(Color(0xFFEDEDED)) // 로딩/빈값 배경 |
| 172 | + ) |
| 173 | +} |
| 174 | + |
| 175 | +//@Composable |
| 176 | +//private fun ProfileImageWithBadge(imageUrl: String?) { |
| 177 | +// Box(modifier = Modifier.size(70.dp)) { |
| 178 | +// val painter = rememberAsyncImagePainter(model = imageUrl) |
| 179 | +// |
| 180 | +// Image( |
| 181 | +// painter = painter, |
| 182 | +// contentDescription = "profile", |
| 183 | +// contentScale = ContentScale.Crop, |
| 184 | +// modifier = Modifier |
| 185 | +// .size(64.dp) |
| 186 | +// .background(Color(0xFFEDEDED), CircleShape) |
| 187 | +// ) |
| 188 | +// |
| 189 | +// Box( |
| 190 | +// modifier = Modifier |
| 191 | +// .size(24.dp) |
| 192 | +// .align(Alignment.BottomEnd) |
| 193 | +// .background(Color(0xFF7C8055), CircleShape), |
| 194 | +// contentAlignment = Alignment.Center |
| 195 | +// ) { |
| 196 | +// Icon( |
| 197 | +// imageVector = Icons.Default.Search, |
| 198 | +// contentDescription = "search", |
| 199 | +// tint = Color.White, |
| 200 | +// modifier = Modifier.size(16.dp) |
| 201 | +// ) |
| 202 | +// } |
| 203 | +// } |
| 204 | +//} |
| 205 | + |
| 206 | +@Composable |
| 207 | +private fun InfoRow(label: String, value: String) { |
| 208 | + Row( |
| 209 | + modifier = Modifier |
| 210 | + .fillMaxWidth() |
| 211 | + .padding( |
| 212 | + horizontal = 13.dp, |
| 213 | + vertical = 17.dp |
| 214 | + ), |
| 215 | + verticalAlignment = Alignment.CenterVertically |
17 | 216 | ) { |
18 | 217 | CustomText( |
19 | | - text = "내정보 페이지입니다.", |
| 218 | + text = label, |
20 | 219 | type = CustomTextType.body, |
21 | | - color = CustomColor.gray400 |
| 220 | + color = CustomColor.gray300, |
| 221 | + ) |
| 222 | + |
| 223 | + Spacer(modifier = Modifier.weight(1f)) |
| 224 | + |
| 225 | + CustomText( |
| 226 | + text = value, |
| 227 | + type = CustomTextType.title, |
| 228 | + color = CustomColor.black |
22 | 229 | ) |
23 | 230 | } |
| 231 | + HorizontalDivider( |
| 232 | + modifier = Modifier |
| 233 | + .padding( |
| 234 | + horizontal = 13.dp, |
| 235 | + vertical = 0.dp |
| 236 | + ), |
| 237 | + color = CustomColor.gray100, |
| 238 | + thickness = 1.dp |
| 239 | + ) |
| 240 | +} |
| 241 | + |
| 242 | +/** |
| 243 | + * ✅ 점선 테두리: "여기서만 쓸 거라" 파일 내부에 private로 둠 |
| 244 | + */ |
| 245 | +private fun Modifier.dashedBorder( |
| 246 | + color: Color, |
| 247 | + strokeWidth: Dp, |
| 248 | + cornerRadius: Dp, |
| 249 | + on: Dp = 6.dp, |
| 250 | + off: Dp = 6.dp, |
| 251 | +) = this.drawBehind { |
| 252 | + val stroke = Stroke( |
| 253 | + width = strokeWidth.toPx(), |
| 254 | + pathEffect = PathEffect.dashPathEffect( |
| 255 | + floatArrayOf(on.toPx(), off.toPx()), |
| 256 | + 0f |
| 257 | + ) |
| 258 | + ) |
| 259 | + drawRoundRect( |
| 260 | + color = color, |
| 261 | + style = stroke, |
| 262 | + cornerRadius = CornerRadius(cornerRadius.toPx()) |
| 263 | + ) |
24 | 264 | } |
0 commit comments