1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-25 00:16:56 +00:00

Fixed some comment issues

This commit is contained in:
Isira Seneviratne 2024-06-18 16:13:20 +05:30
parent f056edd7ae
commit e75eb2d544
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,12 +70,15 @@ 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(
modifier = Modifier.clickable { isExpanded = !isExpanded },
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
val date = Localization.relativeTimeOrTextual( val date = Localization.relativeTimeOrTextual(
context, comment.uploadDate, comment.textualUploadDate context, comment.uploadDate, comment.textualUploadDate
) )
@ -76,6 +86,7 @@ fun Comment(comment: CommentsInfoItem) {
text = Localization.concatenateStrings(comment.uploaderName, date), text = Localization.concatenateStrings(comment.uploaderName, date),
color = MaterialTheme.colorScheme.secondary 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,16 +23,17 @@ fun CommentReplies(
) { ) {
val replies = flow.collectAsLazyPagingItems() val replies = flow.collectAsLazyPagingItems()
Column { LazyColumn {
item {
CommentRepliesHeader(comment = comment, disposables = disposables) CommentRepliesHeader(comment = comment, disposables = disposables)
HorizontalDivider(thickness = 1.dp) HorizontalDivider(thickness = 1.dp)
LazyColumn { }
items(replies.itemCount) { items(replies.itemCount) {
Comment(comment = replies[it]!!) Comment(comment = replies[it]!!)
} }
} }
} }
}
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO) @Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES) @Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)