diff --git a/app/src/main/java/com/jerboa/datatypes/Utils.kt b/app/src/main/java/com/jerboa/datatypes/Utils.kt index bc3a00771..0d4bca8e6 100644 --- a/app/src/main/java/com/jerboa/datatypes/Utils.kt +++ b/app/src/main/java/com/jerboa/datatypes/Utils.kt @@ -1,5 +1,19 @@ package com.jerboa.datatypes +import androidx.compose.runtime.Composable +import androidx.compose.ui.res.stringResource +import com.jerboa.R +import it.vercruysse.lemmyapi.v0x19.datatypes.Comment import it.vercruysse.lemmyapi.v0x19.datatypes.Person fun Person.getDisplayName(): String = this.display_name ?: this.name + +@Composable +fun Comment.getContent(): String = + if (this.removed) { + stringResource(R.string.comment_body_removed) + } else if (this.deleted) { + stringResource(R.string.comment_body_deleted) + } else { + this.content + } diff --git a/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt b/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt index 69815d699..f815fdf29 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt @@ -51,6 +51,7 @@ import com.jerboa.border import com.jerboa.buildCommentsTree import com.jerboa.calculateCommentOffset import com.jerboa.datatypes.BanFromCommunityData +import com.jerboa.datatypes.getContent import com.jerboa.datatypes.sampleCommentView import com.jerboa.datatypes.sampleCommunity import com.jerboa.datatypes.samplePost @@ -151,25 +152,16 @@ fun CommentBody( onClick: () -> Unit, onLongClick: ((View) -> Boolean), ) { - val content = - if (comment.removed) { - stringResource(R.string.comment_body_removed) - } else if (comment.deleted) { - stringResource(R.string.comment_body_deleted) - } else { - comment.content - } - if (viewSource) { SelectionContainer { Text( - text = comment.content, + text = comment.getContent(), fontFamily = FontFamily.Monospace, ) } } else { MyMarkdownText( - markdown = content, + markdown = comment.getContent(), onClick = onClick, onLongClick = onLongClick, modifier = Modifier.padding(0.dp, 0.dp, 0.dp, MEDIUM_PADDING), diff --git a/app/src/main/java/com/jerboa/ui/components/comment/CommentOptionsDropdown.kt b/app/src/main/java/com/jerboa/ui/components/comment/CommentOptionsDropdown.kt index 91229a748..0e9c7fd5e 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/CommentOptionsDropdown.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/CommentOptionsDropdown.kt @@ -27,6 +27,7 @@ import com.jerboa.R import com.jerboa.api.API import com.jerboa.copyToClipboard import com.jerboa.datatypes.BanFromCommunityData +import com.jerboa.datatypes.getContent import com.jerboa.ui.components.common.BanFromCommunityPopupMenuItem import com.jerboa.ui.components.common.BanPersonPopupMenuItem import com.jerboa.ui.components.common.PopupMenuItem @@ -102,12 +103,13 @@ fun CommentOptionsDropdown( ).show() }, ) + val content = commentView.comment.getContent() PopupMenuItem( text = stringResource(R.string.comment_node_copy_comment), icon = Icons.Outlined.ContentCopy, onClick = { onDismissRequest() - if (copyToClipboard(ctx, commentView.comment.content, "comment")) { + if (copyToClipboard(ctx, content, "comment")) { Toast.makeText( ctx, ctx.getString(R.string.comment_node_comment_copied), diff --git a/app/src/main/java/com/jerboa/ui/components/comment/mentionnode/CommentMentionOptionsDropdown.kt b/app/src/main/java/com/jerboa/ui/components/comment/mentionnode/CommentMentionOptionsDropdown.kt index b74967a16..41d3a9a4b 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/mentionnode/CommentMentionOptionsDropdown.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/mentionnode/CommentMentionOptionsDropdown.kt @@ -20,6 +20,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import com.jerboa.R import com.jerboa.copyToClipboard +import com.jerboa.datatypes.getContent import com.jerboa.ui.components.common.PopupMenuItem import com.jerboa.util.cascade.CascadeCenteredDropdownMenu import it.vercruysse.lemmyapi.v0x19.datatypes.Person @@ -83,12 +84,13 @@ fun CommentMentionsOptionsDropdown( ).show() }, ) + val content = personMentionView.comment.getContent() PopupMenuItem( text = stringResource(R.string.comment_node_copy_comment), icon = Icons.Outlined.ContentCopy, onClick = { onDismissRequest() - if (copyToClipboard(ctx, personMentionView.comment.content, "comment")) { + if (copyToClipboard(ctx, content, "comment")) { Toast.makeText(ctx, ctx.getString(R.string.comment_node_comment_copied), Toast.LENGTH_SHORT).show() } else { Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show() diff --git a/app/src/main/java/com/jerboa/ui/components/comment/reply/CommentReply.kt b/app/src/main/java/com/jerboa/ui/components/comment/reply/CommentReply.kt index a01b771f8..d94736850 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/reply/CommentReply.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/reply/CommentReply.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.tooling.preview.Preview import com.jerboa.R +import com.jerboa.datatypes.getContent import com.jerboa.datatypes.sampleCommentView import com.jerboa.db.entity.Account import com.jerboa.ui.components.comment.CommentNodeHeader @@ -51,7 +52,7 @@ fun RepliedComment( showScores = showScores, ) SelectionContainer { - Text(text = commentView.comment.content) + Text(text = commentView.comment.getContent()) } } } @@ -75,7 +76,7 @@ fun RepliedCommentReply( showScores = showScores, ) SelectionContainer { - Text(text = commentReplyView.comment.content) + Text(text = commentReplyView.comment.getContent()) } } } @@ -99,7 +100,7 @@ fun RepliedMentionReply( showScores = showScores, ) SelectionContainer { - Text(text = personMentionView.comment.content) + Text(text = personMentionView.comment.getContent()) } } } diff --git a/app/src/main/java/com/jerboa/ui/components/comment/replynode/CommentReplyOptionsDropdown.kt b/app/src/main/java/com/jerboa/ui/components/comment/replynode/CommentReplyOptionsDropdown.kt index 3b18bf0b9..b3d8363d9 100644 --- a/app/src/main/java/com/jerboa/ui/components/comment/replynode/CommentReplyOptionsDropdown.kt +++ b/app/src/main/java/com/jerboa/ui/components/comment/replynode/CommentReplyOptionsDropdown.kt @@ -18,6 +18,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.AnnotatedString import com.jerboa.R import com.jerboa.copyToClipboard +import com.jerboa.datatypes.getContent import com.jerboa.ui.components.common.PopupMenuItem import com.jerboa.util.cascade.CascadeCenteredDropdownMenu import it.vercruysse.lemmyapi.v0x19.datatypes.CommentReplyView @@ -79,12 +80,13 @@ fun CommentReplyOptionsDropdown( ).show() }, ) + val content = commentReplyView.comment.getContent() PopupMenuItem( text = stringResource(R.string.comment_node_copy_comment), icon = Icons.Outlined.ContentCopy, onClick = { onDismissRequest() - if (copyToClipboard(ctx, commentReplyView.comment.content, "comment")) { + if (copyToClipboard(ctx, content, "comment")) { Toast.makeText(ctx, ctx.getString(R.string.comment_node_comment_copied), Toast.LENGTH_SHORT).show() } else { Toast.makeText(ctx, ctx.getString(R.string.generic_error), Toast.LENGTH_SHORT).show()