From 412e1d602a03a17bbcc7c5fd1e89895a68293cd1 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 10 Nov 2024 23:45:10 +0100 Subject: [PATCH] Better handle unknown values for comment & like count --- .../ui/components/video/comment/Comment.kt | 32 ++++++++++--------- .../video/comment/CommentRepliesDialog.kt | 17 +++++++++- .../video/comment/CommentRepliesHeader.kt | 19 ++++++----- .../video/comment/CommentSection.kt | 18 +++++++---- 4 files changed, 55 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/Comment.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/Comment.kt index f4412ab23..498ee1898 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/Comment.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/Comment.kt @@ -135,26 +135,28 @@ fun Comment(comment: CommentsInfoItem) { verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(start = 1.dp, top = 6.dp, end = 4.dp, bottom = 6.dp) ) { - Image( - painter = painterResource(R.drawable.ic_thumb_up), - contentDescription = stringResource(R.string.detail_likes_img_view_description), - modifier = Modifier - .padding(end = 4.dp) - .size(20.dp), - ) - Text( - text = Localization.likeCount(context, comment.likeCount), - maxLines = 1, - style = MaterialTheme.typography.labelMedium, - ) + // do not show anything if the like count is unknown + if (comment.likeCount >= 0) { + Image( + painter = painterResource(R.drawable.ic_thumb_up), + contentDescription = stringResource(R.string.detail_likes_img_view_description), + modifier = Modifier + .padding(end = 4.dp) + .size(20.dp), + ) + Text( + text = Localization.likeCount(context, comment.likeCount), + maxLines = 1, + style = MaterialTheme.typography.labelMedium, + modifier = Modifier.padding(end = 8.dp) + ) + } if (comment.isHeartedByUploader) { Image( painter = painterResource(R.drawable.ic_heart), contentDescription = stringResource(R.string.detail_heart_img_view_description), - modifier = Modifier - .padding(start = 8.dp) - .size(20.dp), + modifier = Modifier.size(20.dp), ) } } diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt index 33eedd0b4..5e8ce1c4a 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesDialog.kt @@ -6,7 +6,9 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.ModalBottomSheet +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope @@ -14,6 +16,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.rememberNestedScrollInteropConnection +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.paging.LoadState @@ -78,7 +81,7 @@ private fun CommentRepliesDialog( CommentRepliesHeader(comment = parentComment) HorizontalDivider( thickness = 1.dp, - modifier = Modifier.padding(start = 24.dp, end = 24.dp, bottom = 8.dp) + modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 8.dp) ) } @@ -97,6 +100,18 @@ private fun CommentRepliesDialog( } } } else { + if (comments.itemCount >= 0) { + item { + Text( + modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp), + text = pluralStringResource( + R.plurals.replies, comments.itemCount, comments.itemCount + ), + maxLines = 1, + style = MaterialTheme.typography.titleMedium + ) + } + } items(comments.itemCount) { Comment(comment = comments[it]!!) } diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesHeader.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesHeader.kt index 6025a5df4..c987a774d 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesHeader.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentRepliesHeader.kt @@ -83,14 +83,17 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) { horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically ) { - Image( - painter = painterResource(R.drawable.ic_thumb_up), - contentDescription = stringResource(R.string.detail_likes_img_view_description) - ) - Text( - text = Localization.likeCount(context, comment.likeCount), - maxLines = 1, - ) + // do not show anything if the like count is unknown + if (comment.likeCount >= 0) { + Image( + painter = painterResource(R.drawable.ic_thumb_up), + contentDescription = stringResource(R.string.detail_likes_img_view_description) + ) + Text( + text = Localization.likeCount(context, comment.likeCount), + maxLines = 1, + ) + } if (comment.isHeartedByUploader) { Image( diff --git a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt index f643af69d..118231764 100644 --- a/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt +++ b/app/src/main/java/org/schabi/newpipe/ui/components/video/comment/CommentSection.kt @@ -14,7 +14,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.rememberNestedScrollInteropConnection import androidx.compose.ui.res.pluralStringResource -import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.lifecycle.compose.collectAsStateWithLifecycle @@ -84,12 +83,17 @@ private fun CommentSection( NoItemsMessage(R.string.no_comments) } } else { - item { - Text( - modifier = Modifier.padding(start = 8.dp), - text = pluralStringResource(R.plurals.comments, count, count), - fontWeight = FontWeight.Bold - ) + // do not show anything if the comment count is unknown + if (count >= 0) { + item { + Text( + modifier = Modifier + .padding(start = 12.dp, end = 12.dp, bottom = 4.dp), + text = pluralStringResource(R.plurals.comments, count, count), + maxLines = 1, + style = MaterialTheme.typography.titleMedium + ) + } } when (comments.loadState.refresh) {