1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-02-02 12:19:16 +00:00

Add replies button

This commit is contained in:
Isira Seneviratne 2024-06-19 12:59:19 +05:30
parent 1908e18dc4
commit e92ba8f5d1

View File

@ -15,16 +15,19 @@ import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface import androidx.compose.material3.Surface
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ParagraphStyle import androidx.compose.ui.text.ParagraphStyle
@ -37,6 +40,7 @@ import androidx.compose.ui.unit.dp
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import coil.compose.AsyncImage import coil.compose.AsyncImage
import org.schabi.newpipe.R import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.Page
import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.comments.CommentsInfoItem
import org.schabi.newpipe.extractor.stream.Description import org.schabi.newpipe.extractor.stream.Description
import org.schabi.newpipe.ui.theme.AppTheme import org.schabi.newpipe.ui.theme.AppTheme
@ -115,24 +119,38 @@ fun Comment(comment: CommentsInfoItem) {
style = MaterialTheme.typography.bodyMedium, style = MaterialTheme.typography.bodyMedium,
) )
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { Row(
Image( modifier = Modifier.fillMaxWidth(),
painter = painterResource(R.drawable.ic_thumb_up), horizontalArrangement = Arrangement.SpaceBetween,
contentDescription = stringResource(R.string.detail_likes_img_view_description) verticalAlignment = Alignment.CenterVertically
) ) {
Text(text = comment.likeCount.toString()) Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (comment.isHeartedByUploader) {
Image( Image(
painter = painterResource(R.drawable.ic_heart), painter = painterResource(R.drawable.ic_thumb_up),
contentDescription = stringResource(R.string.detail_heart_img_view_description) contentDescription = stringResource(R.string.detail_likes_img_view_description)
) )
Text(text = comment.likeCount.toString())
if (comment.isHeartedByUploader) {
Image(
painter = painterResource(R.drawable.ic_heart),
contentDescription = stringResource(R.string.detail_heart_img_view_description)
)
}
}
if (comment.replies != null) {
TextButton(onClick = { /*TODO*/ }) {
Text(
text = pluralStringResource(
R.plurals.replies, comment.replyCount, comment.replyCount.toString()
)
)
}
} }
} }
} }
} }
// TODO: Add support for comment replies
} }
} }
@ -146,6 +164,8 @@ fun CommentsInfoItem(
likeCount: Int = 0, likeCount: Int = 0,
isHeartedByUploader: Boolean = false, isHeartedByUploader: Boolean = false,
isPinned: Boolean = false, isPinned: Boolean = false,
replies: Page? = null,
replyCount: Int = 0,
) = CommentsInfoItem(serviceId, url, name).apply { ) = CommentsInfoItem(serviceId, url, name).apply {
this.commentText = commentText this.commentText = commentText
this.uploaderName = uploaderName this.uploaderName = uploaderName
@ -153,6 +173,8 @@ fun CommentsInfoItem(
this.likeCount = likeCount this.likeCount = likeCount
this.isHeartedByUploader = isHeartedByUploader this.isHeartedByUploader = isHeartedByUploader
this.isPinned = isPinned this.isPinned = isPinned
this.replies = replies
this.replyCount = replyCount
} }
class DescriptionPreviewProvider : PreviewParameterProvider<Description> { class DescriptionPreviewProvider : PreviewParameterProvider<Description> {
@ -173,7 +195,9 @@ private fun CommentPreview(
uploaderName = "Test", uploaderName = "Test",
likeCount = 100, likeCount = 100,
isPinned = true, isPinned = true,
isHeartedByUploader = true isHeartedByUploader = true,
replies = Page(""),
replyCount = 10
) )
AppTheme { AppTheme {