diff --git a/app/src/main/java/com/whyranoid/walkie/KoinModules.kt b/app/src/main/java/com/whyranoid/walkie/KoinModules.kt index d8e970e8..301e712a 100644 --- a/app/src/main/java/com/whyranoid/walkie/KoinModules.kt +++ b/app/src/main/java/com/whyranoid/walkie/KoinModules.kt @@ -167,7 +167,7 @@ val useCaseModule = single { GetTopRankChallengePreviewsUseCase(get()) } single { StartChallengeUseCase(get(), get()) } single { GetPostUseCase(get()) } - single { GetUserPostPreviewsUseCase(get(), get()) } + single { GetUserPostPreviewsUseCase(get()) } single { GetUserBadgesUseCase(get()) } single { GetUserDetailUseCase(get(), get()) } single { GetRunningFollowerUseCase(get(), get()) } diff --git a/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt b/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt index 5369e3d6..659f6ba1 100644 --- a/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt +++ b/data/src/main/java/com/whyranoid/data/model/post/PostResponse.kt @@ -37,6 +37,7 @@ data class PostResponse( } fun toPost(myUid: Long): Post { + val destructedHistoryContent = historyContent.split('_') return Post( id = this.postId, imageUrl = this.photo, @@ -45,6 +46,12 @@ data class PostResponse( author = this.poster.toUser(), isLiked = this.likers.firstOrNull { it.uid == myUid } != null, date = dateFormatter.parse(this.date.replace("T", " ")).time, + likers = this.likers.map { it.toUser() }, + textVisibleState = TextVisibleState.values()[this.colorMode.toInt()], + distanceText = destructedHistoryContent[2], + timeText = destructedHistoryContent[3], + paceText = destructedHistoryContent[4], + address = destructedHistoryContent[1], ) } diff --git a/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt b/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt index 23cff6e9..1c4bc3cf 100644 --- a/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt +++ b/domain/src/main/java/com/whyranoid/domain/model/post/Post.kt @@ -11,6 +11,13 @@ data class Post( val contents: String, val author: User, val date: Long = 0L, + + val likers: List = listOf(), + val textVisibleState: TextVisibleState = TextVisibleState.HIDE, + val distanceText: String = "", + val timeText: String = "", + val paceText: String = "", + val address: String = "", ) : Serializable { companion object { val DUMMY = @@ -24,3 +31,19 @@ data class Post( ) } } + +fun Post.toPostPreview(): PostPreview { + return PostPreview( + this.author, + this.id, + this.isLiked, + this.likers, + this.imageUrl, + this.date, + this.textVisibleState, + this.distanceText, + this.timeText, + this.paceText, + this.address, + ) +} diff --git a/domain/src/main/java/com/whyranoid/domain/usecase/GetUserPostPreviewsUseCase.kt b/domain/src/main/java/com/whyranoid/domain/usecase/GetUserPostPreviewsUseCase.kt index ba14e7f6..d538e70c 100644 --- a/domain/src/main/java/com/whyranoid/domain/usecase/GetUserPostPreviewsUseCase.kt +++ b/domain/src/main/java/com/whyranoid/domain/usecase/GetUserPostPreviewsUseCase.kt @@ -1,21 +1,13 @@ package com.whyranoid.domain.usecase import com.whyranoid.domain.model.post.PostPreview -import com.whyranoid.domain.repository.AccountRepository import com.whyranoid.domain.repository.PostRepository -import kotlinx.coroutines.flow.first class GetUserPostPreviewsUseCase( private val postRepository: PostRepository, - private val accountRepository: AccountRepository, ) { suspend operator fun invoke(uid: Long): Result> { - val myUid = accountRepository.uId.first() - return if (myUid == uid) { - postRepository.getMyPostPreviews(uid) - } else { - postRepository.getUserPostPreviews(uid) - } + return postRepository.getMyPostPreviews(uid) } suspend operator fun invoke( @@ -24,11 +16,6 @@ class GetUserPostPreviewsUseCase( month: Int, day: Int, ): Result> { - val myUid = accountRepository.uId.first() - return if (myUid == uid) { - postRepository.getMyPostPreviews(uid, year, month, day) - } else { - postRepository.getUserPostPreviews(uid, year, month, day) - } + return postRepository.getMyPostPreviews(uid, year, month, day) } } diff --git a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt index 6a92e434..1f67275c 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostContentItem.kt @@ -8,15 +8,21 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.Icon +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.FavoriteBorder import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import com.whyranoid.domain.model.post.Post -import com.whyranoid.presentation.icons.buttoniconpack.CommentButtonIcon -import com.whyranoid.presentation.icons.buttoniconpack.HeartButtonIcon +import com.whyranoid.presentation.R +import com.whyranoid.presentation.component.text.ExpandableText import com.whyranoid.presentation.theme.WalkieColor import com.whyranoid.presentation.theme.WalkieTypography @@ -39,7 +45,7 @@ fun PostContentItem( horizontalArrangement = Arrangement.SpaceBetween ) { Text( - text = "좋아요 ${post.likeCount}", + text = post.author.nickname, style = WalkieTypography.Body1 ) @@ -47,34 +53,57 @@ fun PostContentItem( Icon( modifier = Modifier - .size(20.dp) + .size(28.dp) + .clip(CircleShape) .clickable { onLikeClicked(post.id) - }, - imageVector = HeartButtonIcon, + } + .padding(2.dp), + imageVector = Icons.Outlined.FavoriteBorder, contentDescription = "좋아요 버튼", tint = if (post.isLiked) WalkieColor.Primary else WalkieColor.GrayBorder ) - Spacer(modifier = Modifier.size(16.dp)) + Spacer(modifier = Modifier.size(2.dp)) + + Text( + modifier = Modifier.align(Alignment.CenterVertically), + text = post.likeCount.toString(), + style = WalkieTypography.Body1_Normal, + color = WalkieColor.GrayBorder + ) + + + Spacer(modifier = Modifier.size(4.dp)) Icon( modifier = Modifier - .size(20.dp) + .graphicsLayer(scaleX = -1f) + .size(28.dp) + .clip(CircleShape) .clickable { onCommentClicked(post) - }, - imageVector = CommentButtonIcon, + } + .padding(3.dp), + painter = painterResource(id = R.drawable.ic_comment_outlined_button), contentDescription = "댓글 버튼", + tint = WalkieColor.GrayBorder + ) + + Spacer(modifier = Modifier.size(2.dp)) + + Text( + modifier = Modifier.align(Alignment.CenterVertically), + text = "?", // todo replace real count + style = WalkieTypography.Body1_Normal, + color = WalkieColor.GrayBorder ) } } Spacer(modifier = Modifier.size(13.dp)) - Text( - text = post.contents, - style = WalkieTypography.Body1_Normal - ) + ExpandableText(text = post.contents, style = WalkieTypography.Body1_Normal) } -} \ No newline at end of file +} + diff --git a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostItem.kt b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostItem.kt index 989898e3..fa38e1bc 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostItem.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostItem.kt @@ -12,7 +12,9 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import com.whyranoid.domain.model.post.Post +import com.whyranoid.domain.model.post.toPostPreview import com.whyranoid.domain.model.user.User +import com.whyranoid.presentation.screens.mypage.tabs.PostImagePreview @Composable fun PostItem( @@ -32,21 +34,20 @@ fun PostItem( PostProfileItem( post.author, + post.address, onProfileClicked, ) - AsyncImage( - model = post.imageUrl, - contentDescription = "게시글 사진", + PostImagePreview( + postPreview = post.toPostPreview(), modifier = Modifier .fillMaxWidth() - .aspectRatio(1f), - contentScale = ContentScale.Crop, + .aspectRatio(1f) ) PostContentItem( post = post, - onLikeClicked = { onLikeClicked(it) }, + onLikeClicked = { onLikeClicked(it) }, onCommentClicked = onCommentClicked ) } diff --git a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostProfileItem.kt b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostProfileItem.kt index 56f23a48..4857c7c2 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/component/community/PostProfileItem.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/component/community/PostProfileItem.kt @@ -25,6 +25,7 @@ import com.whyranoid.presentation.theme.WalkieTypography @Composable fun PostProfileItem( user: User, + address: String, onProfileClicked: (User) -> Unit = {}, ) { Row( @@ -57,7 +58,7 @@ fun PostProfileItem( style = WalkieTypography.Body1, ) Text( - "Seoul, park", + address, style = WalkieTypography.Body2, ) } diff --git a/presentation/src/main/java/com/whyranoid/presentation/component/text/ExpandableText.kt b/presentation/src/main/java/com/whyranoid/presentation/component/text/ExpandableText.kt new file mode 100644 index 00000000..8710e4bf --- /dev/null +++ b/presentation/src/main/java/com/whyranoid/presentation/component/text/ExpandableText.kt @@ -0,0 +1,58 @@ +package com.whyranoid.presentation.component.text + +import androidx.compose.foundation.layout.Column +import androidx.compose.material.LocalTextStyle +import androidx.compose.material.Text +import androidx.compose.material.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.tooling.preview.Preview +import com.whyranoid.presentation.theme.WalkieColor +import com.whyranoid.presentation.theme.WalkieTypography + +@Composable +fun ExpandableText( + modifier: Modifier = Modifier, + text: String, + style: TextStyle = LocalTextStyle.current, + maxLines: Int = 2 +) { + var isExpanded by remember { mutableStateOf(false) } + var needsButton by remember { mutableStateOf(false) } + val textLayoutResultState = remember { mutableStateOf(null) } + + Column { + Text( + modifier = modifier, + text = text, + style = style, + maxLines = if (isExpanded) Int.MAX_VALUE else maxLines, + onTextLayout = { textLayoutResult -> + if (!isExpanded && textLayoutResult.hasVisualOverflow) { + needsButton = true + } + textLayoutResultState.value = textLayoutResult + } + ) + + if (needsButton) { + TextButton( + onClick = { isExpanded = isExpanded.not() } + ) { + Text(if (isExpanded.not()) "더보기" else "접어두기", color = WalkieColor.GrayDefault) + } + } + } +} + +@Composable +@Preview +fun a() { + ExpandableText(text = "post.contents\npost.contents\npost.contents\npost.contents") +} \ No newline at end of file diff --git a/presentation/src/main/java/com/whyranoid/presentation/icons/buttoniconpack/CommentButtonIcon.kt b/presentation/src/main/java/com/whyranoid/presentation/icons/buttoniconpack/CommentButtonIcon.kt deleted file mode 100644 index 4548882d..00000000 --- a/presentation/src/main/java/com/whyranoid/presentation/icons/buttoniconpack/CommentButtonIcon.kt +++ /dev/null @@ -1,43 +0,0 @@ -package com.whyranoid.presentation.icons.buttoniconpack - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.PathFillType.Companion.NonZero -import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.graphics.StrokeCap.Companion.Butt -import androidx.compose.ui.graphics.StrokeJoin.Companion.Miter -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.graphics.vector.ImageVector.Builder -import androidx.compose.ui.graphics.vector.path -import androidx.compose.ui.unit.dp - -val CommentButtonIcon: ImageVector - get() { - if (_commentButtonIcon != null) { - return _commentButtonIcon!! - } - _commentButtonIcon = Builder(name = "CommentButtonIcon", defaultWidth = 20.0.dp, - defaultHeight = 19.0.dp, viewportWidth = 20.0f, viewportHeight = 19.0f).apply { - path(fill = SolidColor(Color(0xFFffffff)), stroke = SolidColor(Color(0xFF000000)), - strokeLineWidth = 2.0f, strokeLineCap = Butt, strokeLineJoin = Miter, - strokeLineMiter = 4.0f, pathFillType = NonZero) { - moveTo(13.2365f, 15.4052f) - lineTo(13.7792f, 15.2385f) - lineTo(14.2005f, 15.6192f) - curveTo(15.428f, 16.7285f, 16.7818f, 17.0892f, 17.8621f, 17.168f) - curveTo(17.6877f, 16.9747f, 17.5257f, 16.7887f, 17.3804f, 16.6101f) - curveTo(16.8621f, 15.9727f, 16.4395f, 15.2964f, 16.2694f, 14.4461f) - lineTo(16.1569f, 13.8833f) - lineTo(16.586f, 13.5022f) - curveTo(18.1042f, 12.1542f, 19.0f, 10.3669f, 19.0f, 8.4444f) - curveTo(19.0f, 4.4844f, 15.1146f, 1.0f, 10.0f, 1.0f) - curveTo(4.8854f, 1.0f, 1.0f, 4.4844f, 1.0f, 8.4444f) - curveTo(1.0f, 12.4045f, 4.8854f, 15.8889f, 10.0f, 15.8889f) - curveTo(11.1379f, 15.8889f, 12.229f, 15.7145f, 13.2365f, 15.4052f) - close() - } - } - .build() - return _commentButtonIcon!! - } - -private var _commentButtonIcon: ImageVector? = null diff --git a/presentation/src/main/java/com/whyranoid/presentation/icons/buttoniconpack/HeartButtonIcon.kt b/presentation/src/main/java/com/whyranoid/presentation/icons/buttoniconpack/HeartButtonIcon.kt deleted file mode 100644 index b6e8309f..00000000 --- a/presentation/src/main/java/com/whyranoid/presentation/icons/buttoniconpack/HeartButtonIcon.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.whyranoid.presentation.icons.buttoniconpack - -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.PathFillType.Companion.NonZero -import androidx.compose.ui.graphics.SolidColor -import androidx.compose.ui.graphics.StrokeCap.Companion.Butt -import androidx.compose.ui.graphics.StrokeJoin.Companion.Miter -import androidx.compose.ui.graphics.vector.ImageVector -import androidx.compose.ui.graphics.vector.ImageVector.Builder -import androidx.compose.ui.graphics.vector.path -import androidx.compose.ui.unit.dp - -val HeartButtonIcon: ImageVector - get() { - if (_heartButtonIcon != null) { - return _heartButtonIcon!! - } - _heartButtonIcon = Builder(name = "HeartButtonIcon", defaultWidth = 20.0.dp, defaultHeight = - 19.0.dp, viewportWidth = 20.0f, viewportHeight = 19.0f).apply { - path(fill = SolidColor(Color(0xFFffffff)), stroke = SolidColor(Color(0xFF000000)), - strokeLineWidth = 2.0f, strokeLineCap = Butt, strokeLineJoin = Miter, - strokeLineMiter = 4.0f, pathFillType = NonZero) { - moveTo(9.2232f, 16.2905f) - lineTo(9.2217f, 16.2892f) - curveTo(6.6271f, 13.9364f, 4.5541f, 12.0515f, 3.118f, 10.2946f) - curveTo(1.693f, 8.5512f, 1.0f, 7.0562f, 1.0f, 5.5f) - curveTo(1.0f, 2.9635f, 2.9711f, 1.0f, 5.5f, 1.0f) - curveTo(6.9377f, 1.0f, 8.3341f, 1.6745f, 9.2412f, 2.7313f) - lineTo(10.0f, 3.6154f) - lineTo(10.7588f, 2.7313f) - curveTo(11.6659f, 1.6745f, 13.0623f, 1.0f, 14.5f, 1.0f) - curveTo(17.0289f, 1.0f, 19.0f, 2.9635f, 19.0f, 5.5f) - curveTo(19.0f, 7.0562f, 18.307f, 8.5512f, 16.882f, 10.2946f) - curveTo(15.4459f, 12.0515f, 13.3729f, 13.9364f, 10.7783f, 16.2892f) - lineTo(10.7768f, 16.2905f) - lineTo(10.0f, 16.9977f) - lineTo(9.2232f, 16.2905f) - close() - } - } - .build() - return _heartButtonIcon!! - } - -private var _heartButtonIcon: ImageVector? = null diff --git a/presentation/src/main/res/drawable/ic_comment_outlined_button.xml b/presentation/src/main/res/drawable/ic_comment_outlined_button.xml new file mode 100644 index 00000000..91d5a017 --- /dev/null +++ b/presentation/src/main/res/drawable/ic_comment_outlined_button.xml @@ -0,0 +1,5 @@ + + + + +