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

Removing bars on non-top level comments. Fixes #1388 #1422

Merged
merged 2 commits into from Mar 4, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/java/com/jerboa/Utils.kt
Expand Up @@ -1221,12 +1221,12 @@ fun findAndUpdateCommentReply(

fun calculateCommentOffset(
depth: Int,
multiplier: Int,
padding: Dp = SMALL_PADDING,
): Dp {
return if (depth == 0) {
0.dp
} else {
(abs((depth.minus(1) * multiplier)).dp + SMALL_PADDING)
(abs((depth.minus(1) * padding.value.toInt())).dp + padding)
}
}

Expand Down
244 changes: 120 additions & 124 deletions app/src/main/java/com/jerboa/ui/components/comment/CommentNode.kt
Expand Up @@ -227,7 +227,7 @@ fun LazyListScope.commentNodeItem(
val commentView = node.commentView
val commentId = commentView.comment.id

val offset = calculateCommentOffset(node.depth, 4) // The ones with a border on
val offset = calculateCommentOffset(node.depth) // The ones with a border on
val offset2 =
if (node.depth == 0) {
MEDIUM_PADDING
Expand Down Expand Up @@ -293,7 +293,6 @@ fun LazyListScope.commentNodeItem(
}
}
}

val swipeableContent: @Composable RowScope.() -> Unit = {
AnimatedVisibility(
visible = !isCollapsedByParent,
Expand All @@ -305,113 +304,113 @@ fun LazyListScope.commentNodeItem(
Modifier
.padding(
start = offset,
),
)
.border(start = border)
.padding(bottom = MEDIUM_PADDING),
) {
if (node.depth == 0) {
HorizontalDivider()
}

Column(
modifier = Modifier.border(start = border)
.padding(bottom = LARGE_PADDING),
modifier =
Modifier.padding(
start = offset2,
end = MEDIUM_PADDING,
),
) {
HorizontalDivider(modifier = Modifier.padding(start = if (node.depth == 0) 0.dp else border.strokeWidth))
Column(
modifier =
Modifier.padding(
start = offset2,
end = MEDIUM_PADDING,
),
) {
if (showPostAndCommunityContext) {
PostAndCommunityContextHeader(
post = commentView.post,
community = commentView.community,
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
blurNSFW = blurNSFW,
showAvatar = showAvatar,
)
}
CommentNodeHeader(
commentView = commentView,
onPersonClick = onPersonClick,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
onClick = {
onHeaderClick(commentView)
},
onLongClick = {
onHeaderLongClick(commentView)
},
collapsedCommentsCount = commentView.counts.child_count,
isExpanded = isExpanded(commentId),
if (showPostAndCommunityContext) {
PostAndCommunityContextHeader(
post = commentView.post,
community = commentView.community,
onCommunityClick = onCommunityClick,
onPostClick = onPostClick,
blurNSFW = blurNSFW,
showAvatar = showAvatar,
)
AnimatedVisibility(
visible = isExpanded(commentId) || showCollapsedCommentContent,
enter = expandVertically(),
exit = shrinkVertically(),
) {
Column {
CommentBody(
comment = commentView.comment,
viewSource = viewSource,
onClick = { onCommentClick(commentView) },
onLongClick = { v ->
if (v is TextView) {
// Also triggers for long click on links, so we check if link was hit
// Can have selection in viewSource but there are no links there
if (viewSource || (v.selectionStart == -1 && v.selectionEnd == -1)) {
toggleActionBar(commentId)
}
}
CommentNodeHeader(
commentView = commentView,
onPersonClick = onPersonClick,
instantScores = instantScores,
voteDisplayMode = voteDisplayMode,
onClick = {
onHeaderClick(commentView)
},
onLongClick = {
onHeaderLongClick(commentView)
},
collapsedCommentsCount = commentView.counts.child_count,
isExpanded = isExpanded(commentId),
showAvatar = showAvatar,
)
AnimatedVisibility(
visible = isExpanded(commentId) || showCollapsedCommentContent,
enter = expandVertically(),
exit = shrinkVertically(),
) {
Column {
CommentBody(
comment = commentView.comment,
viewSource = viewSource,
onClick = { onCommentClick(commentView) },
onLongClick = { v ->
if (v is TextView) {
// Also triggers for long click on links, so we check if link was hit
// Can have selection in viewSource but there are no links there
if (viewSource || (v.selectionStart == -1 && v.selectionEnd == -1)) {
toggleActionBar(commentId)
}
true
}
true
},
)
AnimatedVisibility(
visible = showActionBar(commentId),
enter = expandVertically(),
exit = shrinkVertically(),
) {
CommentFooterLine(
commentView = commentView,
admins = admins,
moderators = moderators,
instantScores = instantScores,
onUpvoteClick = {
instantScores =
instantScores.update(VoteType.Upvote)
onUpvoteClick(commentView)
},
onDownvoteClick = {
instantScores =
instantScores.update(VoteType.Downvote)
onDownvoteClick(commentView)
},
onViewSourceClick = {
viewSource = !viewSource
},
onEditCommentClick = onEditCommentClick,
onDeleteCommentClick = onDeleteCommentClick,
onReplyClick = onReplyClick,
onSaveClick = onSaveClick,
onReportClick = onReportClick,
onRemoveClick = onRemoveClick,
onDistinguishClick = onDistinguishClick,
onBanPersonClick = onBanPersonClick,
onBanFromCommunityClick = onBanFromCommunityClick,
onCommentLinkClick = onCommentLinkClick,
onPersonClick = onPersonClick,
onViewVotesClick = onViewVotesClick,
onBlockCreatorClick = onBlockCreatorClick,
onClick = {
toggleExpanded(commentId)
},
onLongClick = {
toggleActionBar(commentId)
},
account = account,
enableDownVotes = enableDownVotes,
viewSource = viewSource,
)
AnimatedVisibility(
visible = showActionBar(commentId),
enter = expandVertically(),
exit = shrinkVertically(),
) {
CommentFooterLine(
commentView = commentView,
admins = admins,
moderators = moderators,
instantScores = instantScores,
onUpvoteClick = {
instantScores =
instantScores.update(VoteType.Upvote)
onUpvoteClick(commentView)
},
onDownvoteClick = {
instantScores =
instantScores.update(VoteType.Downvote)
onDownvoteClick(commentView)
},
onViewSourceClick = {
viewSource = !viewSource
},
onEditCommentClick = onEditCommentClick,
onDeleteCommentClick = onDeleteCommentClick,
onReplyClick = onReplyClick,
onSaveClick = onSaveClick,
onReportClick = onReportClick,
onRemoveClick = onRemoveClick,
onDistinguishClick = onDistinguishClick,
onBanPersonClick = onBanPersonClick,
onBanFromCommunityClick = onBanFromCommunityClick,
onCommentLinkClick = onCommentLinkClick,
onPersonClick = onPersonClick,
onViewVotesClick = onViewVotesClick,
onBlockCreatorClick = onBlockCreatorClick,
onClick = {
toggleExpanded(commentId)
},
onLongClick = {
toggleActionBar(commentId)
},
account = account,
enableDownVotes = enableDownVotes,
viewSource = viewSource,
)
}
}
}
}
Expand Down Expand Up @@ -535,7 +534,7 @@ fun LazyListScope.missingCommentNodeItem(
) {
val commentId = node.missingCommentView.commentId

val offset = calculateCommentOffset(node.depth, 4) // The ones with a border on
val offset = calculateCommentOffset(node.depth) // The ones with a border on
val offset2 =
if (node.depth == 0) {
MEDIUM_PADDING
Expand Down Expand Up @@ -565,30 +564,28 @@ fun LazyListScope.missingCommentNodeItem(
Modifier
.padding(
start = offset,
),
).border(start = border),
) {
if (node.depth == 0) {
HorizontalDivider()
}
Column(
modifier = Modifier.border(start = border),
modifier =
Modifier.padding(
start = offset2,
end = MEDIUM_PADDING,
),
) {
HorizontalDivider(modifier = Modifier.padding(start = if (node.depth == 0) 0.dp else border.strokeWidth))
Column(
modifier =
Modifier.padding(
start = offset2,
end = MEDIUM_PADDING,
),
AnimatedVisibility(
visible = isExpanded(commentId) || showCollapsedCommentContent,
enter = expandVertically(),
exit = shrinkVertically(),
) {
AnimatedVisibility(
visible = isExpanded(commentId) || showCollapsedCommentContent,
enter = expandVertically(),
exit = shrinkVertically(),
) {
Text(
text = stringResource(id = R.string.comment_gone),
fontStyle = FontStyle.Italic,
modifier = Modifier.padding(vertical = SMALL_PADDING),
)
}
Text(
text = stringResource(id = R.string.comment_gone),
fontStyle = FontStyle.Italic,
modifier = Modifier.padding(vertical = SMALL_PADDING),
)
}
}
}
Expand Down Expand Up @@ -651,7 +648,7 @@ private fun ShowMoreChildrenNode(
) {
val newDepth = depth + 1

val offset = calculateCommentOffset(newDepth, 4) // The ones with a border on
val offset = calculateCommentOffset(newDepth) // The ones with a border on
val offset2 =
if (newDepth == 0) {
MEDIUM_PADDING
Expand All @@ -675,7 +672,6 @@ private fun ShowMoreChildrenNode(
start = offset,
),
) {
HorizontalDivider()
Column(
modifier = Modifier.border(start = border),
) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/test/java/com/jerboa/UtilsKtTest.kt
Expand Up @@ -35,9 +35,9 @@ class UtilsKtTest {

@Test
fun testCalculateCommentOffset() {
assertEquals(0.dp, calculateCommentOffset(0, 0))
assertEquals(3.dp + SMALL_PADDING, calculateCommentOffset(2, 3))
assertEquals(6.dp + SMALL_PADDING, calculateCommentOffset(-1, 3))
assertEquals(0.dp, calculateCommentOffset(0))
assertEquals(4.dp + SMALL_PADDING, calculateCommentOffset(2))
assertEquals(8.dp + SMALL_PADDING, calculateCommentOffset(-1))
}

@Test
Expand Down