Fixed some comment issues

This commit is contained in:
Isira Seneviratne 2024-06-18 16:13:20 +05:30
parent 11bb2495ba
commit e30d5e4305
2 changed files with 32 additions and 28 deletions

View File

@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.width
@ -40,9 +41,15 @@ import org.schabi.newpipe.util.image.ImageStrategy
@Composable @Composable
fun Comment(comment: CommentsInfoItem) { fun Comment(comment: CommentsInfoItem) {
val context = LocalContext.current val context = LocalContext.current
var isExpanded by rememberSaveable { mutableStateOf(false) }
Surface(color = MaterialTheme.colorScheme.background) { 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()) { if (ImageStrategy.shouldLoadImages()) {
AsyncImage( AsyncImage(
model = ImageStrategy.choosePreferredImage(comment.uploaderAvatars), model = ImageStrategy.choosePreferredImage(comment.uploaderAvatars),
@ -63,19 +70,23 @@ fun Comment(comment: CommentsInfoItem) {
Spacer(modifier = Modifier.width(8.dp)) 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( val date = Localization.relativeTimeOrTextual(
modifier = Modifier.clickable { isExpanded = !isExpanded }, context, comment.uploadDate, comment.textualUploadDate
verticalArrangement = Arrangement.spacedBy(4.dp) )
) { Text(
val date = Localization.relativeTimeOrTextual( text = Localization.concatenateStrings(comment.uploaderName, date),
context, comment.uploadDate, comment.textualUploadDate color = MaterialTheme.colorScheme.secondary
) )
Text( }
text = Localization.concatenateStrings(comment.uploaderName, date),
color = MaterialTheme.colorScheme.secondary
)
// TODO: Handle HTML and Markdown formats. // TODO: Handle HTML and Markdown formats.
Text( Text(
@ -100,13 +111,6 @@ fun Comment(comment: CommentsInfoItem) {
contentDescription = stringResource(R.string.detail_heart_img_view_description) 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)
)
}
} }
} }
} }

View File

@ -1,7 +1,6 @@
package org.schabi.newpipe.fragments.list.comments package org.schabi.newpipe.fragments.list.comments
import android.content.res.Configuration import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -24,13 +23,14 @@ fun CommentReplies(
) { ) {
val replies = flow.collectAsLazyPagingItems() val replies = flow.collectAsLazyPagingItems()
Column { LazyColumn {
CommentRepliesHeader(comment = comment, disposables = disposables) item {
HorizontalDivider(thickness = 1.dp) CommentRepliesHeader(comment = comment, disposables = disposables)
LazyColumn { HorizontalDivider(thickness = 1.dp)
items(replies.itemCount) { }
Comment(comment = replies[it]!!)
} items(replies.itemCount) {
Comment(comment = replies[it]!!)
} }
} }
} }