Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

커뮤니티 게시글 디자인 최신화 적용 및 버그 수정 #80

Merged
merged 5 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data class PostResponse(
}

fun toPost(myUid: Long): Post {
val destructedHistoryContent = historyContent.split('_')
return Post(
id = this.postId,
imageUrl = this.photo,
Expand All @@ -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],
)
}

Expand Down
23 changes: 23 additions & 0 deletions domain/src/main/java/com/whyranoid/domain/model/post/Post.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ data class Post(
val contents: String,
val author: User,
val date: Long = 0L,

val likers: List<User> = listOf(),
val textVisibleState: TextVisibleState = TextVisibleState.HIDE,
val distanceText: String = "",
val timeText: String = "",
val paceText: String = "",
val address: String = "",
) : Serializable {
companion object {
val DUMMY =
Expand All @@ -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,
)
}
Original file line number Diff line number Diff line change
@@ -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<List<PostPreview>> {
val myUid = accountRepository.uId.first()
return if (myUid == uid) {
postRepository.getMyPostPreviews(uid)
} else {
postRepository.getUserPostPreviews(uid)
}
return postRepository.getMyPostPreviews(uid)
}

suspend operator fun invoke(
Expand All @@ -24,11 +16,6 @@ class GetUserPostPreviewsUseCase(
month: Int,
day: Int,
): Result<List<PostPreview>> {
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -39,42 +45,65 @@ fun PostContentItem(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = "좋아요 ${post.likeCount}",
text = post.author.nickname,
style = WalkieTypography.Body1
)

Row {

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)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.whyranoid.presentation.theme.WalkieTypography
@Composable
fun PostProfileItem(
user: User,
address: String,
onProfileClicked: (User) -> Unit = {},
) {
Row(
Expand Down Expand Up @@ -57,7 +58,7 @@ fun PostProfileItem(
style = WalkieTypography.Body1,
)
Text(
"Seoul, park",
address,
style = WalkieTypography.Body2,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<TextLayoutResult?>(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")
}

This file was deleted.

Loading
Loading