Skip to content

Commit 868b2df

Browse files
committed
feat: collapse expanded comments with show less
1 parent ff609aa commit 868b2df

3 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎app/src/androidTest/java/dev/typetype/android/feature/player/components/CommentBodyTest.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CommentBodyTest {
4747
}
4848

4949
composeRule.onNodeWithText("Read more").assertExists().performClick()
50-
composeRule.onNodeWithText("Long comment starts here$suffix").assertExists()
50+
composeRule.onNodeWithText("Show less").assertExists().performClick()
51+
composeRule.onNodeWithText("Read more").assertExists()
5152
}
5253
}

‎app/src/main/java/dev/typetype/android/feature/player/components/CommentListItems.kt‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,17 @@ private fun ExpandableCommentText(
139139
maxLines = if (expanded) Int.MAX_VALUE else COMMENT_COLLAPSE_LINE_LIMIT,
140140
overflow = if (expanded) TextOverflow.Clip else TextOverflow.Ellipsis,
141141
)
142-
if (needsTruncation && !expanded) {
142+
if (needsTruncation) {
143143
TextButton(
144-
onClick = { expanded = true },
144+
onClick = { expanded = !expanded },
145145
contentPadding = PaddingValues(horizontal = 4.dp),
146146
modifier = Modifier.padding(top = 2.dp),
147147
) {
148-
Text(stringResource(R.string.comments_read_more))
148+
Text(
149+
stringResource(
150+
if (expanded) R.string.comments_show_less else R.string.comments_read_more,
151+
)
152+
)
149153
}
150154
}
151155
}

‎app/src/main/res/values/strings.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@
497497
<string name="comments_title">Comments</string>
498498
<string name="comments_empty">No comments</string>
499499
<string name="comments_read_more">Read more</string>
500+
<string name="comments_show_less">Show less</string>
500501
<string name="comments_like_count">Likes: %1$s</string>
501502
<string name="comments_replies_failed">Couldn\'t load replies</string>
502503
<string name="comments_load_failed">Couldn\'t load comments</string>

0 commit comments

Comments
 (0)