diff --git a/app/src/main/java/org/schabi/newpipe/compose/comment/Comment.kt b/app/src/main/java/org/schabi/newpipe/compose/comment/Comment.kt index a5bf00da5..00f07932f 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/comment/Comment.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/comment/Comment.kt @@ -42,8 +42,8 @@ import androidx.paging.PagingConfig import androidx.paging.cachedIn import coil.compose.AsyncImage import org.schabi.newpipe.R +import org.schabi.newpipe.compose.common.DescriptionText import org.schabi.newpipe.compose.theme.AppTheme -import org.schabi.newpipe.compose.util.rememberParsedDescription import org.schabi.newpipe.extractor.Page import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.stream.Description @@ -101,8 +101,8 @@ fun Comment(comment: CommentsInfoItem) { Text(text = nameAndDate, color = MaterialTheme.colorScheme.secondary) } - Text( - text = rememberParsedDescription(comment.commentText), + DescriptionText( + description = comment.commentText, // If the comment is expanded, we display all its content // otherwise we only display the first two lines maxLines = if (isExpanded) Int.MAX_VALUE else 2, diff --git a/app/src/main/java/org/schabi/newpipe/compose/comment/CommentRepliesHeader.kt b/app/src/main/java/org/schabi/newpipe/compose/comment/CommentRepliesHeader.kt index 52a360c0c..d4e4fd36c 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/comment/CommentRepliesHeader.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/comment/CommentRepliesHeader.kt @@ -25,8 +25,8 @@ import androidx.compose.ui.unit.dp import androidx.fragment.app.FragmentActivity import coil.compose.AsyncImage import org.schabi.newpipe.R +import org.schabi.newpipe.compose.common.DescriptionText import org.schabi.newpipe.compose.theme.AppTheme -import org.schabi.newpipe.compose.util.rememberParsedDescription import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.stream.Description import org.schabi.newpipe.util.Localization @@ -102,8 +102,8 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) { } } - Text( - text = rememberParsedDescription(comment.commentText), + DescriptionText( + description = comment.commentText, style = MaterialTheme.typography.bodyMedium ) } diff --git a/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt b/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt index 7a9579fb1..5d5ad3b76 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt @@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flowOf import my.nanihadesuka.compose.LazyColumnScrollbar import org.schabi.newpipe.R -import org.schabi.newpipe.compose.status.LoadingIndicator +import org.schabi.newpipe.compose.common.LoadingIndicator import org.schabi.newpipe.compose.theme.AppTheme import org.schabi.newpipe.extractor.comments.CommentsInfoItem import org.schabi.newpipe.extractor.stream.Description diff --git a/app/src/main/java/org/schabi/newpipe/compose/util/ParseDescription.kt b/app/src/main/java/org/schabi/newpipe/compose/common/DescriptionText.kt similarity index 53% rename from app/src/main/java/org/schabi/newpipe/compose/util/ParseDescription.kt rename to app/src/main/java/org/schabi/newpipe/compose/common/DescriptionText.kt index 3ffbac558..614a36cce 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/util/ParseDescription.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/common/DescriptionText.kt @@ -1,19 +1,30 @@ -package org.schabi.newpipe.compose.util +package org.schabi.newpipe.compose.common +import androidx.compose.material3.LocalTextStyle +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.ParagraphStyle import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.TextLinkStyles +import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.fromHtml import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.text.style.TextOverflow import org.schabi.newpipe.extractor.stream.Description @Composable -fun rememberParsedDescription(description: Description): AnnotatedString { +fun DescriptionText( + description: Description, + modifier: Modifier = Modifier, + overflow: TextOverflow = TextOverflow.Clip, + maxLines: Int = Int.MAX_VALUE, + style: TextStyle = LocalTextStyle.current +) { // TODO: Handle links and hashtags, Markdown. - return remember(description) { + val parsedDescription = remember(description) { if (description.type == Description.HTML) { val styles = TextLinkStyles(SpanStyle(textDecoration = TextDecoration.Underline)) AnnotatedString.fromHtml(description.content, styles) @@ -21,4 +32,12 @@ fun rememberParsedDescription(description: Description): AnnotatedString { AnnotatedString(description.content, ParagraphStyle()) } } + + Text( + modifier = modifier, + text = parsedDescription, + maxLines = maxLines, + style = style, + overflow = overflow + ) } diff --git a/app/src/main/java/org/schabi/newpipe/compose/status/LoadingIndicator.kt b/app/src/main/java/org/schabi/newpipe/compose/common/LoadingIndicator.kt similarity index 93% rename from app/src/main/java/org/schabi/newpipe/compose/status/LoadingIndicator.kt rename to app/src/main/java/org/schabi/newpipe/compose/common/LoadingIndicator.kt index 8bed6f8c8..6ddea9d7a 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/status/LoadingIndicator.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/common/LoadingIndicator.kt @@ -1,4 +1,4 @@ -package org.schabi.newpipe.compose.status +package org.schabi.newpipe.compose.common import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.wrapContentSize