Browse Source

update post

master
osman160128 2 weeks ago
parent
commit
cd2c343ca1
  1. 3
      app/src/main/java/com/example/dattingapp/LikeANdMatchActivity.kt
  2. 128
      app/src/main/java/com/example/dattingapp/ShowPostingActivity.kt
  3. 6
      app/src/main/java/com/example/dattingapp/dataclass/DataClass.kt
  4. 48
      app/src/main/java/com/example/dattingapp/homes/CreatePostScreen.kt
  5. 7
      app/src/main/java/com/example/dattingapp/homes/networkandapi/HomeViewModelClass.kt

3
app/src/main/java/com/example/dattingapp/LikeANdMatchActivity.kt

@ -3,6 +3,7 @@ package com.example.dattingapp
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge 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 val nameAndAge = if (age != null) "$displayName, $age" else displayName
Log.d("user","$likedProfile.id")
Text( Text(
text = nameAndAge, text = nameAndAge,
color = Color.White, color = Color.White,

128
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.CommentResponse
import com.example.dattingapp.dataclass.Location 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 AccentPink = Color(0xFFD81B60)
val CommentBubbleBg = Color(0xFFF6F6F6) val CommentBubbleBg = Color(0xFFF6F6F6)
@ -97,15 +94,6 @@ class ShowPostingActivity : ComponentActivity() {
PostCard( PostCard(
post = state.post, post = state.post,
comments = comments, 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( fun PostCard(
post: ShowPostResponse, post: ShowPostResponse,
comments: List<CommentResponse>, comments: List<CommentResponse>,
onAddComment: (String) -> Unit = {},
modifier: Modifier = Modifier modifier: Modifier = Modifier
) { ) {
Column( Column(
@ -223,12 +210,12 @@ fun PostCard(
) { ) {
IconButton(onClick = { /* Handle like action */ }) { IconButton(onClick = { /* Handle like action */ }) {
Icon( 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", 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)) Spacer(modifier = Modifier.width(16.dp))
@ -238,13 +225,14 @@ fun PostCard(
contentDescription = "Comments" contentDescription = "Comments"
) )
} }
Text(text = "${post.commentCount}") Text(text = "${comments.size}")
} }
// --- 5. Comment Section UI --- // --- 5. Comment Section UI ---
CommentSection( CommentSection(
comments = comments, comments = comments,
onAddCommentClick = onAddComment postId = post.id,
currentUserName = post.author?.full_name // see note below
) )
} }
} }
@ -252,10 +240,14 @@ fun PostCard(
@Composable @Composable
fun CommentSection( fun CommentSection(
comments: List<CommentResponse>, comments: List<CommentResponse>,
onAddCommentClick: (String) -> Unit postId: Int,
currentUserName: String?,
viewModel: ShowPostViewModel = viewModel()
) { ) {
val context = LocalContext.current
var newCommentText by remember { mutableStateOf("") } var newCommentText by remember { mutableStateOf("") }
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -267,7 +259,54 @@ fun CommentSection(
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
modifier = Modifier.padding(bottom = 8.dp) 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 // List of fetched comments
comments.reversed().forEach { comment -> comments.reversed().forEach { comment ->
Row( Row(
@ -314,49 +353,7 @@ fun CommentSection(
Spacer(modifier = Modifier.height(8.dp)) 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) @Preview(showBackground = true, backgroundColor = 0xFFFFFFFF)
@ -382,9 +379,9 @@ fun ShowPostScreenPreview() {
country = "China", country = "China",
compatibilityPercentage = 95 compatibilityPercentage = 95
), ),
likeCount = 12, like_count = 12,
commentCount = 2, comment_count = 2,
likedByMe = true, liked_by_me = true,
media = listOf( media = listOf(
com.example.dattingapp.dataclass.MediaItem( com.example.dattingapp.dataclass.MediaItem(
id = 5, id = 5,
@ -438,9 +435,6 @@ fun ShowPostScreenPreview() {
PostCard( PostCard(
post = mockPost, post = mockPost,
comments = mockComments, comments = mockComments,
onAddComment = { newComment ->
// Preview action handler
}
) )
} }
} }

6
app/src/main/java/com/example/dattingapp/dataclass/DataClass.kt

@ -12,9 +12,9 @@ data class ShowPostResponse(
val feeling: String?, val feeling: String?,
@SerialName("location") val location: Location?, @SerialName("location") val location: Location?,
@SerialName("author") val author: Author? = null, @SerialName("author") val author: Author? = null,
@SerialName("like_count") val likeCount: Int = 0, @SerialName("like_count") val like_count: Int,
@SerialName("comment_count") val commentCount: Int = 0, @SerialName("comment_count") val comment_count: Int = 0,
@SerialName("liked_by_me") val likedByMe: Boolean = false, @SerialName("liked_by_me") val liked_by_me: Boolean = false,
val media: List<MediaItem> = emptyList(), val media: List<MediaItem> = emptyList(),
@SerialName("created_at") val createdAt: String? @SerialName("created_at") val createdAt: String?
) )

48
app/src/main/java/com/example/dattingapp/homes/CreatePostScreen.kt

@ -65,7 +65,9 @@ import android.util.Log
import android.content.Context import android.content.Context
import androidx.compose.ui.text.TextStyle
import com.example.dattingapp.homes.networkandapi.PostMediaViewModel import com.example.dattingapp.homes.networkandapi.PostMediaViewModel
import com.example.dattingapp.ui.theme.DattingAPPTheme
import java.io.File import java.io.File
@ -75,6 +77,8 @@ sealed class MediaContentItem(val uri: Uri) {
class Video(uri: Uri) : MediaContentItem(uri) class Video(uri: Uri) : MediaContentItem(uri)
} }
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
fun CreateVibePostScreen( fun CreateVibePostScreen(
@ -484,11 +488,19 @@ fun CreateVibePostScreen(
TextField( TextField(
value = textState, value = textState,
onValueChange = { if (it.length <= maxChar) textState = it }, 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 = { placeholder = {
Text( Text(
"What's your vibe today? Share a moment, date idea, or story...", "What's your vibe today? Share a moment, date idea, or story...",
color = Color.Gray, color = Color(0xFFA0A0A8),
fontSize = 15.sp fontSize = 20.sp,
lineHeight = 28.sp
) )
}, },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@ -496,24 +508,13 @@ fun CreateVibePostScreen(
focusedContainerColor = Color.Transparent, focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent, unfocusedContainerColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent, focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent unfocusedIndicatorColor = Color.Transparent,
cursorColor = Color(0xFFE91E63)
) )
) )
Spacer(modifier = Modifier.height(8.dp)) 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)) Spacer(modifier = Modifier.height(16.dp))
// Horizontal Scrollable Media Row (Contains Photos and Videos) // Horizontal Scrollable Media Row (Contains Photos and Videos)
@ -841,21 +842,10 @@ fun FeelingPickerBottomSheet(
} }
} }
} }
@Preview(showBackground = true, showSystemUi = true, backgroundColor = 0xFFFFFFFF)
@Preview(
name = "Create Vibe Post Screen",
showBackground = true,
showSystemUi = true
)
@Composable @Composable
fun CreateVibePostScreenPreview() { fun CreateVibePostScreenPreview() {
MaterialTheme { DattingAPPTheme {
CreateVibePostScreen( CreateVibePostScreen()
onCloseClick = {},
onShareClick = {}
)
} }
} }

7
app/src/main/java/com/example/dattingapp/homes/networkandapi/HomeViewModelClass.kt

@ -595,12 +595,14 @@ class ShowPostViewModel : ViewModel() {
val showPostUiState: StateFlow<ShowPostUiState> = _showPostUiState.asStateFlow() val showPostUiState: StateFlow<ShowPostUiState> = _showPostUiState.asStateFlow()
fun fetchPostById(context: Context, postId: Int) { fun fetchPostById(context: Context, postId: Int) {
if (_showPostUiState.value is ShowPostUiState.Loading) return if (_showPostUiState.value is ShowPostUiState.Loading) return
val appContext = context.applicationContext val appContext = context.applicationContext
viewModelScope.launch { viewModelScope.launch {
_showPostUiState.value = ShowPostUiState.Loading
_showPostUiState.value = ShowPostUiState.Loading
// Token check // Token check
if (TokenManager.getInstance(appContext).getAccessToken().isNullOrBlank()) { if (TokenManager.getInstance(appContext).getAccessToken().isNullOrBlank()) {
@ -637,7 +639,6 @@ class ShowPostViewModel : ViewModel() {
} }
} }
} }
fun addCommentLocallyAndServer(context: Context, postId: Int, content: String, currentUserName: String?) { fun addCommentLocallyAndServer(context: Context, postId: Int, content: String, currentUserName: String?) {
val appContext = context.applicationContext val appContext = context.applicationContext

Loading…
Cancel
Save