11package org.schabi.newpipe.ui.components.video.comment
22
33import android.content.res.Configuration
4+ import android.os.Build
5+ import android.widget.Toast
46import androidx.compose.animation.animateContentSize
7+ import androidx.compose.foundation.ExperimentalFoundationApi
58import androidx.compose.foundation.Image
69import androidx.compose.foundation.clickable
10+ import androidx.compose.foundation.combinedClickable
711import androidx.compose.foundation.layout.Arrangement
812import androidx.compose.foundation.layout.Column
913import androidx.compose.foundation.layout.Row
@@ -27,6 +31,7 @@ import androidx.compose.runtime.setValue
2731import androidx.compose.ui.Alignment
2832import androidx.compose.ui.Modifier
2933import androidx.compose.ui.draw.clip
34+ import androidx.compose.ui.platform.LocalClipboardManager
3035import androidx.compose.ui.platform.LocalContext
3136import androidx.compose.ui.res.painterResource
3237import androidx.compose.ui.res.pluralStringResource
@@ -46,23 +51,34 @@ import org.schabi.newpipe.extractor.Page
4651import org.schabi.newpipe.extractor.comments.CommentsInfoItem
4752import org.schabi.newpipe.extractor.stream.Description
4853import org.schabi.newpipe.paging.CommentsSource
49- import org.schabi.newpipe.ui.components.common.DescriptionText
54+ import org.schabi.newpipe.ui.components.common.rememberParsedDescription
5055import org.schabi.newpipe.ui.theme.AppTheme
5156import org.schabi.newpipe.util.Localization
5257import org.schabi.newpipe.util.NavigationHelper
5358import org.schabi.newpipe.util.image.ImageStrategy
5459
55- @OptIn(ExperimentalMaterial3Api ::class )
60+ @OptIn(ExperimentalMaterial3Api ::class , ExperimentalFoundationApi :: class )
5661@Composable
5762fun Comment (comment : CommentsInfoItem ) {
63+ val clipboardManager = LocalClipboardManager .current
5864 val context = LocalContext .current
5965 var isExpanded by rememberSaveable { mutableStateOf(false ) }
6066 var showReplies by rememberSaveable { mutableStateOf(false ) }
67+ val parsedDescription = rememberParsedDescription(comment.commentText)
6168
6269 Row (
6370 modifier = Modifier
6471 .animateContentSize()
65- .clickable { isExpanded = ! isExpanded }
72+ .combinedClickable(
73+ onLongClick = {
74+ clipboardManager.setText(parsedDescription)
75+ if (Build .VERSION .SDK_INT < 33 ) {
76+ // Android 13 has its own "copied to clipboard" dialog
77+ Toast .makeText(context, R .string.msg_copied, Toast .LENGTH_SHORT ).show()
78+ }
79+ },
80+ onClick = { isExpanded = ! isExpanded }
81+ )
6682 .padding(8 .dp),
6783 horizontalArrangement = Arrangement .spacedBy(8 .dp)
6884 ) {
@@ -99,13 +115,13 @@ fun Comment(comment: CommentsInfoItem) {
99115 Text (text = nameAndDate, color = MaterialTheme .colorScheme.secondary)
100116 }
101117
102- DescriptionText (
103- description = comment.commentText ,
118+ Text (
119+ text = parsedDescription ,
104120 // If the comment is expanded, we display all its content
105121 // otherwise we only display the first two lines
106122 maxLines = if (isExpanded) Int .MAX_VALUE else 2 ,
107123 overflow = TextOverflow .Ellipsis ,
108- style = MaterialTheme .typography.bodyMedium,
124+ style = MaterialTheme .typography.bodyMedium
109125 )
110126
111127 Row (
0 commit comments