Skip to content

Commit

Permalink
Better handle unknown values for comment & like count
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Nov 10, 2024
1 parent 802a094 commit 412e1d6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ 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
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
Expand Down Expand Up @@ -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)
)
}

Expand All @@ -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]!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 412e1d6

Please sign in to comment.