|
|
|
@ -51,6 +51,7 @@ import com.example.dattingapp.homes.profile.FrienPostMedia |
|
|
|
import com.example.dattingapp.homes.profile.FriendAuthor |
|
|
|
import com.example.dattingapp.homes.profile.FriendPost |
|
|
|
import com.example.dattingapp.homes.profile.FriendProfileResponse |
|
|
|
import com.example.dattingapp.homes.profile.LikedUserResponse |
|
|
|
import com.example.dattingapp.ui.theme.* |
|
|
|
import java.time.LocalDate |
|
|
|
import java.time.Period |
|
|
|
@ -82,6 +83,9 @@ class FriendProfile : ComponentActivity() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (val state = profileUiState) { |
|
|
|
is FriendProfileUiState.Loading -> { |
|
|
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { |
|
|
|
@ -120,6 +124,36 @@ fun FriendProfileScreen( |
|
|
|
onStarClick: () -> Unit = {}, |
|
|
|
onCancelClick: () -> Unit = {} |
|
|
|
) { |
|
|
|
|
|
|
|
val likedViewModel: LikedViewModel = viewModel() |
|
|
|
|
|
|
|
// ✅ collect each state separately |
|
|
|
val likesState by likedViewModel.likesUiState.collectAsState() // who liked me |
|
|
|
val likedState by likedViewModel.likedUiState.collectAsState() // I liked |
|
|
|
val matchesState by likedViewModel.matchesUiState.collectAsState() // matches |
|
|
|
|
|
|
|
// ✅ load all three lists once |
|
|
|
LaunchedEffect(Unit) { |
|
|
|
likedViewModel.likedResponse(context, "Likes") |
|
|
|
likedViewModel.likedResponse(context, "Liked") |
|
|
|
likedViewModel.likedResponse(context, "Matches") |
|
|
|
} |
|
|
|
|
|
|
|
// ✅ turn each into a set of ids |
|
|
|
val likedMeIds = (likesState as? LikedUiState.Success) |
|
|
|
?.LikeData?.map { it.id }?.toSet() ?: emptySet() |
|
|
|
|
|
|
|
val iLikedIds = (likedState as? LikedUiState.Success) |
|
|
|
?.LikeData?.map { it.id }?.toSet() ?: emptySet() |
|
|
|
|
|
|
|
val matchIds = (matchesState as? LikedUiState.Success) |
|
|
|
?.LikeData?.map { it.id }?.toSet() ?: emptySet() |
|
|
|
|
|
|
|
// ✅ the three booleans for the button row |
|
|
|
val isMatch = friendProfileData.id in matchIds |
|
|
|
val heLikedMe = friendProfileData.id in likedMeIds |
|
|
|
val iLikedHim = friendProfileData.id in iLikedIds |
|
|
|
|
|
|
|
val age = remember(friendProfileData.birth_date) { |
|
|
|
calculateAge(friendProfileData.birth_date) |
|
|
|
} |
|
|
|
@ -269,6 +303,7 @@ fun FriendProfileScreen( |
|
|
|
) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Action Buttons Row |
|
|
|
Row( |
|
|
|
modifier = Modifier |
|
|
|
@ -277,85 +312,109 @@ fun FriendProfileScreen( |
|
|
|
horizontalArrangement = Arrangement.spacedBy(10.dp), |
|
|
|
verticalAlignment = Alignment.CenterVertically |
|
|
|
) { |
|
|
|
Button( |
|
|
|
// Message — inside a card |
|
|
|
if (isMatch) { |
|
|
|
Card( |
|
|
|
onClick = onMessageClick, |
|
|
|
modifier = Modifier |
|
|
|
.weight(1f) |
|
|
|
.height(48.dp) |
|
|
|
.background( |
|
|
|
brush = gradientBrush, |
|
|
|
shape = RoundedCornerShape(10.dp) |
|
|
|
), |
|
|
|
colors = ButtonDefaults.buttonColors( |
|
|
|
containerColor = Color.Transparent, |
|
|
|
contentColor = Color.White |
|
|
|
), |
|
|
|
shape = RoundedCornerShape(10.dp) |
|
|
|
.height(48.dp), |
|
|
|
shape = RoundedCornerShape(10.dp), |
|
|
|
colors = CardDefaults.cardColors(containerColor = Color.White), |
|
|
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) |
|
|
|
) { |
|
|
|
Row( |
|
|
|
modifier = Modifier.fillMaxSize(), |
|
|
|
horizontalArrangement = Arrangement.Center, |
|
|
|
verticalAlignment = Alignment.CenterVertically |
|
|
|
) { |
|
|
|
Icon( |
|
|
|
imageVector = Icons.Default.ChatBubble, |
|
|
|
contentDescription = "Message", |
|
|
|
tint = textDark, |
|
|
|
modifier = Modifier.size(18.dp) |
|
|
|
) |
|
|
|
Spacer(modifier = Modifier.width(8.dp)) |
|
|
|
Text( |
|
|
|
text = "Message", |
|
|
|
fontSize = 16.sp, |
|
|
|
fontWeight = FontWeight.Bold |
|
|
|
fontWeight = FontWeight.Bold, |
|
|
|
color = textDark |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IconButton( |
|
|
|
// ❤️ Like — red ICON when the user liked ME, hidden when matched |
|
|
|
if (!isMatch) { |
|
|
|
Card( |
|
|
|
onClick = { |
|
|
|
onLikeClick() |
|
|
|
handleLikeAndDislikeAction(context, "right", friendProfileData, swipeViewModel) |
|
|
|
}, |
|
|
|
modifier = Modifier |
|
|
|
.size(48.dp) |
|
|
|
.background(color = purpleButtonColor, shape = RoundedCornerShape(10.dp)) |
|
|
|
modifier = Modifier.size(48.dp), |
|
|
|
shape = RoundedCornerShape(10.dp), |
|
|
|
colors = CardDefaults.cardColors(containerColor = Color.White), |
|
|
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) |
|
|
|
) { |
|
|
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { |
|
|
|
Icon( |
|
|
|
imageVector = Icons.Default.Favorite, |
|
|
|
contentDescription = "Like", |
|
|
|
tint = Color(0xFFE2C4FF), |
|
|
|
modifier = Modifier.size(20.dp) |
|
|
|
tint = when { |
|
|
|
heLikedMe -> Color(0xFFE53935) // 🔴 user liked me |
|
|
|
iLikedHim -> Color(0xFF1E88E5) // 🔵 I liked the user |
|
|
|
else -> textDark // ⚫ no relation yet |
|
|
|
}, |
|
|
|
modifier = Modifier.size(22.dp) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IconButton( |
|
|
|
// Super Like — inside a card |
|
|
|
Card( |
|
|
|
onClick = { |
|
|
|
onStarClick() |
|
|
|
handleLikeAndDislikeAction(context, "right", friendProfileData, swipeViewModel) |
|
|
|
}, |
|
|
|
modifier = Modifier |
|
|
|
.size(48.dp) |
|
|
|
.background(color = purpleButtonColor, shape = RoundedCornerShape(10.dp)) |
|
|
|
modifier = Modifier.size(48.dp), |
|
|
|
shape = RoundedCornerShape(10.dp), |
|
|
|
colors = CardDefaults.cardColors(containerColor = Color.White), |
|
|
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) |
|
|
|
) { |
|
|
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { |
|
|
|
Icon( |
|
|
|
imageVector = Icons.Default.Star, |
|
|
|
contentDescription = "Favorite", |
|
|
|
tint = Color(0xFFE2C4FF), |
|
|
|
modifier = Modifier.size(20.dp) |
|
|
|
tint = textDark, |
|
|
|
modifier = Modifier.size(22.dp) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IconButton( |
|
|
|
// Cancel — inside a card, always visible |
|
|
|
Card( |
|
|
|
onClick = { |
|
|
|
onCancelClick() |
|
|
|
handleLikeAndDislikeAction(context, "left", friendProfileData, swipeViewModel) |
|
|
|
}, |
|
|
|
modifier = Modifier |
|
|
|
.size(48.dp) |
|
|
|
.background(color = purpleButtonColor, shape = RoundedCornerShape(10.dp)) |
|
|
|
modifier = Modifier.size(48.dp), |
|
|
|
shape = RoundedCornerShape(10.dp), |
|
|
|
colors = CardDefaults.cardColors(containerColor = Color.White), |
|
|
|
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) |
|
|
|
) { |
|
|
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { |
|
|
|
Icon( |
|
|
|
imageVector = Icons.Default.Close, |
|
|
|
contentDescription = "Dislike", |
|
|
|
tint = Color(0xFFE2C4FF), |
|
|
|
modifier = Modifier.size(20.dp) |
|
|
|
tint = textDark, |
|
|
|
modifier = Modifier.size(22.dp) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(16.dp)) |
|
|
|
|
|
|
|
|