Skip to content

Commit

Permalink
Add nsfw tag to nsfw posts (#786)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Phoenix <[email protected]>
  • Loading branch information
Chris-Kropp and twizmwazin authored Jun 21, 2023
1 parent 30aa860 commit 1e804e4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
32 changes: 32 additions & 0 deletions app/src/main/java/com/jerboa/ui/components/common/TimeAgo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ fun ScoreAndTime(
updated: String?,
isExpanded: Boolean = true,
collapsedCommentsCount: Int = 0,
isNsfw: Boolean = false,
) {
Row(
horizontalArrangement = Arrangement.spacedBy(SMALL_PADDING),
verticalAlignment = Alignment.CenterVertically,
) {
NsfwBadge(isNsfw)
CollapsedIndicator(visible = !isExpanded, descendants = collapsedCommentsCount)
Spacer(modifier = Modifier.padding(end = SMALL_PADDING))
Text(
Expand Down Expand Up @@ -144,3 +146,33 @@ fun CollapsedIndicator(visible: Boolean, descendants: Int) {
fun CollapsedIndicatorPreview() {
CollapsedIndicator(visible = true, descendants = 23)
}

@Composable
fun NsfwBadge(visible: Boolean) {
AnimatedVisibility(
visible = visible,
enter = fadeIn(),
exit = fadeOut(),
) {
Column(modifier = Modifier.wrapContentSize(Alignment.Center)) {
Box(
modifier = Modifier
.clip(RoundedCornerShape(2.dp))
.background(MaterialTheme.colorScheme.secondary)
.padding(horizontal = SMALL_PADDING),
) {
Text(
text = "NSFW",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSecondary,
)
}
}
}
}

@Preview
@Composable
fun NsfwBadgePreview() {
NsfwBadge(visible = true)
}
13 changes: 9 additions & 4 deletions app/src/main/java/com/jerboa/ui/components/post/PostListing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import com.jerboa.ui.components.common.DotSpacer
import com.jerboa.ui.components.common.IconAndTextDrawerItem
import com.jerboa.ui.components.common.ImageViewerDialog
import com.jerboa.ui.components.common.MyMarkdownText
import com.jerboa.ui.components.common.NsfwBadge
import com.jerboa.ui.components.common.PictrsThumbnailImage
import com.jerboa.ui.components.common.PictrsUrlImage
import com.jerboa.ui.components.common.PreviewLines
Expand Down Expand Up @@ -196,6 +197,7 @@ fun PostHeaderLine(
myVote = myVote,
published = postView.post.published,
updated = postView.post.updated,
isNsfw = nsfwCheck(postView),
)
}
Row {
Expand Down Expand Up @@ -983,10 +985,12 @@ fun PostListingList(
showAvatar: Boolean,
) {
Column(
modifier = Modifier.padding(
horizontal = MEDIUM_PADDING,
vertical = MEDIUM_PADDING,
).testTag("jerboa:post"),
modifier = Modifier
.padding(
horizontal = MEDIUM_PADDING,
vertical = MEDIUM_PADDING,
)
.testTag("jerboa:post"),
) {
Row(
modifier = Modifier.fillMaxWidth(),
Expand Down Expand Up @@ -1072,6 +1076,7 @@ fun PostListingList(
unreadCount = postView.unread_comments,
style = MaterialTheme.typography.bodyMedium,
)
NsfwBadge(nsfwCheck(postView))
}
}
ThumbnailTile(postView)
Expand Down

0 comments on commit 1e804e4

Please sign in to comment.