From e75eb2d5449119e1aa5ab7996678bc39abe971c2 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 18 Jun 2024 16:13:20 +0530 Subject: [PATCH] Fixed some comment issues --- .../fragments/list/comments/Comment.kt | 44 ++++++++++--------- .../fragments/list/comments/CommentReplies.kt | 16 +++---- 2 files changed, 32 insertions(+), 28 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/Comment.kt b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/Comment.kt index 78c9f88f4..bde37ac95 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/Comment.kt +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/Comment.kt @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width @@ -40,9 +41,15 @@ import org.schabi.newpipe.util.image.ImageStrategy @Composable fun Comment(comment: CommentsInfoItem) { val context = LocalContext.current + var isExpanded by rememberSaveable { mutableStateOf(false) } Surface(color = MaterialTheme.colorScheme.background) { - Row(modifier = Modifier.padding(all = 8.dp)) { + Row( + modifier = Modifier + .fillMaxWidth() + .clickable { isExpanded = !isExpanded } + .padding(all = 8.dp) + ) { if (ImageStrategy.shouldLoadImages()) { AsyncImage( model = ImageStrategy.choosePreferredImage(comment.uploaderAvatars), @@ -63,19 +70,23 @@ fun Comment(comment: CommentsInfoItem) { Spacer(modifier = Modifier.width(8.dp)) - var isExpanded by rememberSaveable { mutableStateOf(false) } + Column(verticalArrangement = Arrangement.spacedBy(4.dp)) { + Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) { + if (comment.isPinned) { + Image( + painter = painterResource(R.drawable.ic_pin), + contentDescription = stringResource(R.string.detail_pinned_comment_view_description) + ) + } - Column( - modifier = Modifier.clickable { isExpanded = !isExpanded }, - verticalArrangement = Arrangement.spacedBy(4.dp) - ) { - val date = Localization.relativeTimeOrTextual( - context, comment.uploadDate, comment.textualUploadDate - ) - Text( - text = Localization.concatenateStrings(comment.uploaderName, date), - color = MaterialTheme.colorScheme.secondary - ) + val date = Localization.relativeTimeOrTextual( + context, comment.uploadDate, comment.textualUploadDate + ) + Text( + text = Localization.concatenateStrings(comment.uploaderName, date), + color = MaterialTheme.colorScheme.secondary + ) + } // TODO: Handle HTML and Markdown formats. Text( @@ -100,13 +111,6 @@ fun Comment(comment: CommentsInfoItem) { contentDescription = stringResource(R.string.detail_heart_img_view_description) ) } - - if (comment.isPinned) { - Image( - painter = painterResource(R.drawable.ic_pin), - contentDescription = stringResource(R.string.detail_pinned_comment_view_description) - ) - } } } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentReplies.kt b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentReplies.kt index 42813f087..dcabedb48 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentReplies.kt +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentReplies.kt @@ -1,7 +1,6 @@ package org.schabi.newpipe.fragments.list.comments import android.content.res.Configuration -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.HorizontalDivider import androidx.compose.runtime.Composable @@ -24,13 +23,14 @@ fun CommentReplies( ) { val replies = flow.collectAsLazyPagingItems() - Column { - CommentRepliesHeader(comment = comment, disposables = disposables) - HorizontalDivider(thickness = 1.dp) - LazyColumn { - items(replies.itemCount) { - Comment(comment = replies[it]!!) - } + LazyColumn { + item { + CommentRepliesHeader(comment = comment, disposables = disposables) + HorizontalDivider(thickness = 1.dp) + } + + items(replies.itemCount) { + Comment(comment = replies[it]!!) } } }