Skip to content

Commit 412e1d6

Browse files
committed
Better handle unknown values for comment & like count
1 parent 802a094 commit 412e1d6

4 files changed

Lines changed: 55 additions & 31 deletions

File tree

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/Comment.kt

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,28 @@ fun Comment(comment: CommentsInfoItem) {
135135
verticalAlignment = Alignment.CenterVertically,
136136
modifier = Modifier.padding(start = 1.dp, top = 6.dp, end = 4.dp, bottom = 6.dp)
137137
) {
138-
Image(
139-
painter = painterResource(R.drawable.ic_thumb_up),
140-
contentDescription = stringResource(R.string.detail_likes_img_view_description),
141-
modifier = Modifier
142-
.padding(end = 4.dp)
143-
.size(20.dp),
144-
)
145-
Text(
146-
text = Localization.likeCount(context, comment.likeCount),
147-
maxLines = 1,
148-
style = MaterialTheme.typography.labelMedium,
149-
)
138+
// do not show anything if the like count is unknown
139+
if (comment.likeCount >= 0) {
140+
Image(
141+
painter = painterResource(R.drawable.ic_thumb_up),
142+
contentDescription = stringResource(R.string.detail_likes_img_view_description),
143+
modifier = Modifier
144+
.padding(end = 4.dp)
145+
.size(20.dp),
146+
)
147+
Text(
148+
text = Localization.likeCount(context, comment.likeCount),
149+
maxLines = 1,
150+
style = MaterialTheme.typography.labelMedium,
151+
modifier = Modifier.padding(end = 8.dp)
152+
)
153+
}
150154

151155
if (comment.isHeartedByUploader) {
152156
Image(
153157
painter = painterResource(R.drawable.ic_heart),
154158
contentDescription = stringResource(R.string.detail_heart_img_view_description),
155-
modifier = Modifier
156-
.padding(start = 8.dp)
157-
.size(20.dp),
159+
modifier = Modifier.size(20.dp),
158160
)
159161
}
160162
}

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ import androidx.compose.foundation.lazy.LazyColumn
66
import androidx.compose.foundation.lazy.rememberLazyListState
77
import androidx.compose.material3.ExperimentalMaterial3Api
88
import androidx.compose.material3.HorizontalDivider
9+
import androidx.compose.material3.MaterialTheme
910
import androidx.compose.material3.ModalBottomSheet
11+
import androidx.compose.material3.Text
1012
import androidx.compose.runtime.Composable
1113
import androidx.compose.runtime.remember
1214
import androidx.compose.runtime.rememberCoroutineScope
1315
import androidx.compose.ui.Modifier
1416
import androidx.compose.ui.graphics.Color
1517
import androidx.compose.ui.input.nestedscroll.nestedScroll
1618
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
19+
import androidx.compose.ui.res.pluralStringResource
1720
import androidx.compose.ui.tooling.preview.Preview
1821
import androidx.compose.ui.unit.dp
1922
import androidx.paging.LoadState
@@ -78,7 +81,7 @@ private fun CommentRepliesDialog(
7881
CommentRepliesHeader(comment = parentComment)
7982
HorizontalDivider(
8083
thickness = 1.dp,
81-
modifier = Modifier.padding(start = 24.dp, end = 24.dp, bottom = 8.dp)
84+
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp)
8285
)
8386
}
8487

@@ -97,6 +100,18 @@ private fun CommentRepliesDialog(
97100
}
98101
}
99102
} else {
103+
if (comments.itemCount >= 0) {
104+
item {
105+
Text(
106+
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
107+
text = pluralStringResource(
108+
R.plurals.replies, comments.itemCount, comments.itemCount
109+
),
110+
maxLines = 1,
111+
style = MaterialTheme.typography.titleMedium
112+
)
113+
}
114+
}
100115
items(comments.itemCount) {
101116
Comment(comment = comments[it]!!)
102117
}

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesHeader.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
8383
horizontalArrangement = Arrangement.spacedBy(8.dp),
8484
verticalAlignment = Alignment.CenterVertically
8585
) {
86-
Image(
87-
painter = painterResource(R.drawable.ic_thumb_up),
88-
contentDescription = stringResource(R.string.detail_likes_img_view_description)
89-
)
90-
Text(
91-
text = Localization.likeCount(context, comment.likeCount),
92-
maxLines = 1,
93-
)
86+
// do not show anything if the like count is unknown
87+
if (comment.likeCount >= 0) {
88+
Image(
89+
painter = painterResource(R.drawable.ic_thumb_up),
90+
contentDescription = stringResource(R.string.detail_likes_img_view_description)
91+
)
92+
Text(
93+
text = Localization.likeCount(context, comment.likeCount),
94+
maxLines = 1,
95+
)
96+
}
9497

9598
if (comment.isHeartedByUploader) {
9699
Image(

app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import androidx.compose.ui.graphics.Color
1414
import androidx.compose.ui.input.nestedscroll.nestedScroll
1515
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
1616
import androidx.compose.ui.res.pluralStringResource
17-
import androidx.compose.ui.text.font.FontWeight
1817
import androidx.compose.ui.tooling.preview.Preview
1918
import androidx.compose.ui.unit.dp
2019
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@@ -84,12 +83,17 @@ private fun CommentSection(
8483
NoItemsMessage(R.string.no_comments)
8584
}
8685
} else {
87-
item {
88-
Text(
89-
modifier = Modifier.padding(start = 8.dp),
90-
text = pluralStringResource(R.plurals.comments, count, count),
91-
fontWeight = FontWeight.Bold
92-
)
86+
// do not show anything if the comment count is unknown
87+
if (count >= 0) {
88+
item {
89+
Text(
90+
modifier = Modifier
91+
.padding(start = 12.dp, end = 12.dp, bottom = 4.dp),
92+
text = pluralStringResource(R.plurals.comments, count, count),
93+
maxLines = 1,
94+
style = MaterialTheme.typography.titleMedium
95+
)
96+
}
9397
}
9498

9599
when (comments.loadState.refresh) {

0 commit comments

Comments
 (0)