From cd2c343ca1eaab0db71be50d389e7e1fede56d82 Mon Sep 17 00:00:00 2001 From: osman160128 Date: Tue, 13 Oct 2026 18:59:46 +0600 Subject: [PATCH] update post --- .../dattingapp/LikeANdMatchActivity.kt | 3 + .../example/dattingapp/ShowPostingActivity.kt | 128 +++++++++--------- .../example/dattingapp/dataclass/DataClass.kt | 6 +- .../dattingapp/homes/CreatePostScreen.kt | 50 +++---- .../homes/networkandapi/HomeViewModelClass.kt | 7 +- 5 files changed, 91 insertions(+), 103 deletions(-) diff --git a/app/src/main/java/com/example/dattingapp/LikeANdMatchActivity.kt b/app/src/main/java/com/example/dattingapp/LikeANdMatchActivity.kt index b0d29fc..931d878 100644 --- a/app/src/main/java/com/example/dattingapp/LikeANdMatchActivity.kt +++ b/app/src/main/java/com/example/dattingapp/LikeANdMatchActivity.kt @@ -3,6 +3,7 @@ package com.example.dattingapp import android.content.Context import android.content.Intent import android.os.Bundle +import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge @@ -197,6 +198,8 @@ fun ProfileCard(context: Context, likedProfile: LikedUserResponse, modifier: Mod } val nameAndAge = if (age != null) "$displayName, $age" else displayName + Log.d("user","$likedProfile.id") + Text( text = nameAndAge, color = Color.White, diff --git a/app/src/main/java/com/example/dattingapp/ShowPostingActivity.kt b/app/src/main/java/com/example/dattingapp/ShowPostingActivity.kt index b3e79ee..2a35d91 100644 --- a/app/src/main/java/com/example/dattingapp/ShowPostingActivity.kt +++ b/app/src/main/java/com/example/dattingapp/ShowPostingActivity.kt @@ -47,9 +47,6 @@ import androidx.compose.ui.tooling.preview.Preview import com.example.dattingapp.dataclass.CommentResponse import com.example.dattingapp.dataclass.Location -// Color definitions matching the design palette -val PrimaryDarkText = Color(0xFF1E1E1E) -val SecondaryGrayText = Color(0xFF757575) val AccentPink = Color(0xFFD81B60) val CommentBubbleBg = Color(0xFFF6F6F6) @@ -97,15 +94,6 @@ class ShowPostingActivity : ComponentActivity() { PostCard( post = state.post, comments = comments, - onAddComment = { commentText -> - val currentUserName = state.post.author?.full_name - showPostViewModel.addCommentLocallyAndServer( - context = context, - postId = postId, - content = commentText, - currentUserName = currentUserName - ) - } ) } } @@ -128,7 +116,6 @@ class ShowPostingActivity : ComponentActivity() { fun PostCard( post: ShowPostResponse, comments: List, - onAddComment: (String) -> Unit = {}, modifier: Modifier = Modifier ) { Column( @@ -223,12 +210,12 @@ fun PostCard( ) { IconButton(onClick = { /* Handle like action */ }) { Icon( - imageVector = if (post.likedByMe) Icons.Filled.Favorite else Icons.Default.FavoriteBorder, + imageVector = if (post.liked_by_me) Icons.Filled.Favorite else Icons.Default.FavoriteBorder, contentDescription = "Like", - tint = if (post.likedByMe) Color.Red else Color.Black + tint = if (post.liked_by_me) Color.Red else Color.Black ) } - Text(text = "${post.likeCount}") + Text(text = "${post.like_count}") Spacer(modifier = Modifier.width(16.dp)) @@ -238,13 +225,14 @@ fun PostCard( contentDescription = "Comments" ) } - Text(text = "${post.commentCount}") + Text(text = "${comments.size}") } // --- 5. Comment Section UI --- CommentSection( comments = comments, - onAddCommentClick = onAddComment + postId = post.id, + currentUserName = post.author?.full_name // see note below ) } } @@ -252,10 +240,14 @@ fun PostCard( @Composable fun CommentSection( comments: List, - onAddCommentClick: (String) -> Unit + postId: Int, + currentUserName: String?, + viewModel: ShowPostViewModel = viewModel() ) { + val context = LocalContext.current var newCommentText by remember { mutableStateOf("") } + Column( modifier = Modifier .fillMaxWidth() @@ -267,7 +259,54 @@ fun CommentSection( fontWeight = FontWeight.Bold, modifier = Modifier.padding(bottom = 8.dp) ) +// Bottom Comment Input Field Bar + Row( + modifier = Modifier + .fillMaxWidth() + .background(CommentBubbleBg, shape = RoundedCornerShape(24.dp)) + .padding(horizontal = 12.dp, vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically + ) { + BasicTextField( + value = newCommentText, + onValueChange = { newCommentText = it }, + modifier = Modifier + .weight(1f) + .padding(vertical = 8.dp), + decorationBox = { innerTextField -> + if (newCommentText.isEmpty()) { + Text( + text = "Add a comment...", + color = Color.Gray, + style = MaterialTheme.typography.bodyMedium + ) + } + innerTextField() + } + ) + IconButton( + onClick = { + if (newCommentText.isNotBlank()) { + viewModel.addCommentLocallyAndServer( + context = context, + postId = postId, + content = newCommentText, + currentUserName = currentUserName + ) + newCommentText = "" + } + }, + modifier = Modifier.size(32.dp) + ) { + Icon( + imageVector = Icons.Default.Send, + contentDescription = "Send Comment", + tint = AccentPink, + modifier = Modifier.size(16.dp) + ) + } + } // List of fetched comments comments.reversed().forEach { comment -> Row( @@ -314,49 +353,7 @@ fun CommentSection( Spacer(modifier = Modifier.height(8.dp)) - // Bottom Comment Input Field Bar - Row( - modifier = Modifier - .fillMaxWidth() - .background(CommentBubbleBg, shape = RoundedCornerShape(24.dp)) - .padding(horizontal = 12.dp, vertical = 4.dp), - verticalAlignment = Alignment.CenterVertically - ) { - BasicTextField( - value = newCommentText, - onValueChange = { newCommentText = it }, - modifier = Modifier - .weight(1f) - .padding(vertical = 8.dp), - decorationBox = { innerTextField -> - if (newCommentText.isEmpty()) { - Text( - text = "Add a comment...", - color = Color.Gray, - style = MaterialTheme.typography.bodyMedium - ) - } - innerTextField() - } - ) - IconButton( - onClick = { - if (newCommentText.isNotBlank()) { - onAddCommentClick(newCommentText) - newCommentText = "" - } - }, - modifier = Modifier.size(32.dp) - ) { - Icon( - imageVector = Icons.Default.Send, - contentDescription = "Send Comment", - tint = AccentPink, - modifier = Modifier.size(16.dp) - ) - } - } } } @Preview(showBackground = true, backgroundColor = 0xFFFFFFFF) @@ -382,9 +379,9 @@ fun ShowPostScreenPreview() { country = "China", compatibilityPercentage = 95 ), - likeCount = 12, - commentCount = 2, - likedByMe = true, + like_count = 12, + comment_count = 2, + liked_by_me = true, media = listOf( com.example.dattingapp.dataclass.MediaItem( id = 5, @@ -438,9 +435,6 @@ fun ShowPostScreenPreview() { PostCard( post = mockPost, comments = mockComments, - onAddComment = { newComment -> - // Preview action handler - } ) } } diff --git a/app/src/main/java/com/example/dattingapp/dataclass/DataClass.kt b/app/src/main/java/com/example/dattingapp/dataclass/DataClass.kt index 4850d47..8a82cb7 100644 --- a/app/src/main/java/com/example/dattingapp/dataclass/DataClass.kt +++ b/app/src/main/java/com/example/dattingapp/dataclass/DataClass.kt @@ -12,9 +12,9 @@ data class ShowPostResponse( val feeling: String?, @SerialName("location") val location: Location?, @SerialName("author") val author: Author? = null, - @SerialName("like_count") val likeCount: Int = 0, - @SerialName("comment_count") val commentCount: Int = 0, - @SerialName("liked_by_me") val likedByMe: Boolean = false, + @SerialName("like_count") val like_count: Int, + @SerialName("comment_count") val comment_count: Int = 0, + @SerialName("liked_by_me") val liked_by_me: Boolean = false, val media: List = emptyList(), @SerialName("created_at") val createdAt: String? ) diff --git a/app/src/main/java/com/example/dattingapp/homes/CreatePostScreen.kt b/app/src/main/java/com/example/dattingapp/homes/CreatePostScreen.kt index 1f97580..ccb4bdb 100644 --- a/app/src/main/java/com/example/dattingapp/homes/CreatePostScreen.kt +++ b/app/src/main/java/com/example/dattingapp/homes/CreatePostScreen.kt @@ -65,7 +65,9 @@ import android.util.Log import android.content.Context +import androidx.compose.ui.text.TextStyle import com.example.dattingapp.homes.networkandapi.PostMediaViewModel +import com.example.dattingapp.ui.theme.DattingAPPTheme import java.io.File @@ -75,6 +77,8 @@ sealed class MediaContentItem(val uri: Uri) { class Video(uri: Uri) : MediaContentItem(uri) } + + @OptIn(ExperimentalMaterial3Api::class) @Composable fun CreateVibePostScreen( @@ -484,11 +488,19 @@ fun CreateVibePostScreen( TextField( value = textState, onValueChange = { if (it.length <= maxChar) textState = it }, + textStyle = TextStyle( + fontSize = 20.sp, + lineHeight = 28.sp, + fontWeight = FontWeight.Medium, + color = Color(0xFF1E1E1E), + letterSpacing = 0.2.sp + ), placeholder = { Text( "What's your vibe today? Share a moment, date idea, or story...", - color = Color.Gray, - fontSize = 15.sp + color = Color(0xFFA0A0A8), + fontSize = 20.sp, + lineHeight = 28.sp ) }, modifier = Modifier.fillMaxWidth(), @@ -496,24 +508,13 @@ fun CreateVibePostScreen( focusedContainerColor = Color.Transparent, unfocusedContainerColor = Color.Transparent, focusedIndicatorColor = Color.Transparent, - unfocusedIndicatorColor = Color.Transparent + unfocusedIndicatorColor = Color.Transparent, + cursorColor = Color(0xFFE91E63) ) ) Spacer(modifier = Modifier.height(8.dp)) - // Formatting & Character Counter Bar - Row( - modifier = Modifier.fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically - ) { - Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) { - Text("B", fontWeight = FontWeight.Bold, fontSize = 16.sp, color = Color.Gray) - Text("I", fontWeight = FontWeight.Bold, fontSize = 16.sp, color = Color.Gray) - } - } - Spacer(modifier = Modifier.height(16.dp)) // Horizontal Scrollable Media Row (Contains Photos and Videos) @@ -841,21 +842,10 @@ fun FeelingPickerBottomSheet( } } } - - - - -@Preview( - name = "Create Vibe Post Screen", - showBackground = true, - showSystemUi = true -) +@Preview(showBackground = true, showSystemUi = true, backgroundColor = 0xFFFFFFFF) @Composable fun CreateVibePostScreenPreview() { - MaterialTheme { - CreateVibePostScreen( - onCloseClick = {}, - onShareClick = {} - ) + DattingAPPTheme { + CreateVibePostScreen() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/example/dattingapp/homes/networkandapi/HomeViewModelClass.kt b/app/src/main/java/com/example/dattingapp/homes/networkandapi/HomeViewModelClass.kt index a2d8ef1..de4e016 100644 --- a/app/src/main/java/com/example/dattingapp/homes/networkandapi/HomeViewModelClass.kt +++ b/app/src/main/java/com/example/dattingapp/homes/networkandapi/HomeViewModelClass.kt @@ -595,12 +595,14 @@ class ShowPostViewModel : ViewModel() { val showPostUiState: StateFlow = _showPostUiState.asStateFlow() fun fetchPostById(context: Context, postId: Int) { - if (_showPostUiState.value is ShowPostUiState.Loading) return + if (_showPostUiState.value is ShowPostUiState.Loading) return val appContext = context.applicationContext viewModelScope.launch { - _showPostUiState.value = ShowPostUiState.Loading + + _showPostUiState.value = ShowPostUiState.Loading + // Token check if (TokenManager.getInstance(appContext).getAccessToken().isNullOrBlank()) { @@ -637,7 +639,6 @@ class ShowPostViewModel : ViewModel() { } } } - fun addCommentLocallyAndServer(context: Context, postId: Int, content: String, currentUserName: String?) { val appContext = context.applicationContext