1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 12:32:31 +01:00

Better handle unknown values for comment & like count

This commit is contained in:
Stypox 2024-11-10 23:45:10 +01:00
parent 802a094154
commit 412e1d602a
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
4 changed files with 55 additions and 31 deletions

View File

@ -135,6 +135,8 @@ fun Comment(comment: CommentsInfoItem) {
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(start = 1.dp, top = 6.dp, end = 4.dp, bottom = 6.dp) modifier = Modifier.padding(start = 1.dp, top = 6.dp, end = 4.dp, bottom = 6.dp)
) { ) {
// do not show anything if the like count is unknown
if (comment.likeCount >= 0) {
Image( Image(
painter = painterResource(R.drawable.ic_thumb_up), painter = painterResource(R.drawable.ic_thumb_up),
contentDescription = stringResource(R.string.detail_likes_img_view_description), contentDescription = stringResource(R.string.detail_likes_img_view_description),
@ -146,15 +148,15 @@ fun Comment(comment: CommentsInfoItem) {
text = Localization.likeCount(context, comment.likeCount), text = Localization.likeCount(context, comment.likeCount),
maxLines = 1, maxLines = 1,
style = MaterialTheme.typography.labelMedium, style = MaterialTheme.typography.labelMedium,
modifier = Modifier.padding(end = 8.dp)
) )
}
if (comment.isHeartedByUploader) { if (comment.isHeartedByUploader) {
Image( Image(
painter = painterResource(R.drawable.ic_heart), painter = painterResource(R.drawable.ic_heart),
contentDescription = stringResource(R.string.detail_heart_img_view_description), contentDescription = stringResource(R.string.detail_heart_img_view_description),
modifier = Modifier modifier = Modifier.size(20.dp),
.padding(start = 8.dp)
.size(20.dp),
) )
} }
} }

View File

@ -6,7 +6,9 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
@ -14,6 +16,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.paging.LoadState import androidx.paging.LoadState
@ -78,7 +81,7 @@ private fun CommentRepliesDialog(
CommentRepliesHeader(comment = parentComment) CommentRepliesHeader(comment = parentComment)
HorizontalDivider( HorizontalDivider(
thickness = 1.dp, 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 { } 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) { items(comments.itemCount) {
Comment(comment = comments[it]!!) Comment(comment = comments[it]!!)
} }

View File

@ -83,6 +83,8 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
horizontalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
// do not show anything if the like count is unknown
if (comment.likeCount >= 0) {
Image( Image(
painter = painterResource(R.drawable.ic_thumb_up), painter = painterResource(R.drawable.ic_thumb_up),
contentDescription = stringResource(R.string.detail_likes_img_view_description) contentDescription = stringResource(R.string.detail_likes_img_view_description)
@ -91,6 +93,7 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
text = Localization.likeCount(context, comment.likeCount), text = Localization.likeCount(context, comment.likeCount),
maxLines = 1, maxLines = 1,
) )
}
if (comment.isHeartedByUploader) { if (comment.isHeartedByUploader) {
Image( Image(

View File

@ -14,7 +14,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.rememberNestedScrollInteropConnection import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.lifecycle.compose.collectAsStateWithLifecycle
@ -84,13 +83,18 @@ private fun CommentSection(
NoItemsMessage(R.string.no_comments) NoItemsMessage(R.string.no_comments)
} }
} else { } else {
// do not show anything if the comment count is unknown
if (count >= 0) {
item { item {
Text( Text(
modifier = Modifier.padding(start = 8.dp), modifier = Modifier
.padding(start = 12.dp, end = 12.dp, bottom = 4.dp),
text = pluralStringResource(R.plurals.comments, count, count), text = pluralStringResource(R.plurals.comments, count, count),
fontWeight = FontWeight.Bold maxLines = 1,
style = MaterialTheme.typography.titleMedium
) )
} }
}
when (comments.loadState.refresh) { when (comments.loadState.refresh) {
is LoadState.Loading -> { is LoadState.Loading -> {