Skip to content

Commit ea414f5

Browse files
Added DescriptionText composable
1 parent f984b26 commit ea414f5

5 files changed

Lines changed: 30 additions & 11 deletions

File tree

app/src/main/java/org/schabi/newpipe/compose/comment/Comment.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import androidx.paging.PagingConfig
4242
import androidx.paging.cachedIn
4343
import coil.compose.AsyncImage
4444
import org.schabi.newpipe.R
45+
import org.schabi.newpipe.compose.common.DescriptionText
4546
import org.schabi.newpipe.compose.theme.AppTheme
46-
import org.schabi.newpipe.compose.util.rememberParsedDescription
4747
import org.schabi.newpipe.extractor.Page
4848
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
4949
import org.schabi.newpipe.extractor.stream.Description
@@ -101,8 +101,8 @@ fun Comment(comment: CommentsInfoItem) {
101101
Text(text = nameAndDate, color = MaterialTheme.colorScheme.secondary)
102102
}
103103

104-
Text(
105-
text = rememberParsedDescription(comment.commentText),
104+
DescriptionText(
105+
description = comment.commentText,
106106
// If the comment is expanded, we display all its content
107107
// otherwise we only display the first two lines
108108
maxLines = if (isExpanded) Int.MAX_VALUE else 2,

app/src/main/java/org/schabi/newpipe/compose/comment/CommentRepliesHeader.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import androidx.compose.ui.unit.dp
2525
import androidx.fragment.app.FragmentActivity
2626
import coil.compose.AsyncImage
2727
import org.schabi.newpipe.R
28+
import org.schabi.newpipe.compose.common.DescriptionText
2829
import org.schabi.newpipe.compose.theme.AppTheme
29-
import org.schabi.newpipe.compose.util.rememberParsedDescription
3030
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
3131
import org.schabi.newpipe.extractor.stream.Description
3232
import org.schabi.newpipe.util.Localization
@@ -102,8 +102,8 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
102102
}
103103
}
104104

105-
Text(
106-
text = rememberParsedDescription(comment.commentText),
105+
DescriptionText(
106+
description = comment.commentText,
107107
style = MaterialTheme.typography.bodyMedium
108108
)
109109
}

app/src/main/java/org/schabi/newpipe/compose/comment/CommentSection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.Flow
3131
import kotlinx.coroutines.flow.flowOf
3232
import my.nanihadesuka.compose.LazyColumnScrollbar
3333
import org.schabi.newpipe.R
34-
import org.schabi.newpipe.compose.status.LoadingIndicator
34+
import org.schabi.newpipe.compose.common.LoadingIndicator
3535
import org.schabi.newpipe.compose.theme.AppTheme
3636
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
3737
import org.schabi.newpipe.extractor.stream.Description

app/src/main/java/org/schabi/newpipe/compose/util/ParseDescription.kt renamed to app/src/main/java/org/schabi/newpipe/compose/common/DescriptionText.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
package org.schabi.newpipe.compose.util
1+
package org.schabi.newpipe.compose.common
22

3+
import androidx.compose.material3.LocalTextStyle
4+
import androidx.compose.material3.Text
35
import androidx.compose.runtime.Composable
46
import androidx.compose.runtime.remember
7+
import androidx.compose.ui.Modifier
58
import androidx.compose.ui.text.AnnotatedString
69
import androidx.compose.ui.text.ParagraphStyle
710
import androidx.compose.ui.text.SpanStyle
811
import androidx.compose.ui.text.TextLinkStyles
12+
import androidx.compose.ui.text.TextStyle
913
import androidx.compose.ui.text.fromHtml
1014
import androidx.compose.ui.text.style.TextDecoration
15+
import androidx.compose.ui.text.style.TextOverflow
1116
import org.schabi.newpipe.extractor.stream.Description
1217

1318
@Composable
14-
fun rememberParsedDescription(description: Description): AnnotatedString {
19+
fun DescriptionText(
20+
description: Description,
21+
modifier: Modifier = Modifier,
22+
overflow: TextOverflow = TextOverflow.Clip,
23+
maxLines: Int = Int.MAX_VALUE,
24+
style: TextStyle = LocalTextStyle.current
25+
) {
1526
// TODO: Handle links and hashtags, Markdown.
16-
return remember(description) {
27+
val parsedDescription = remember(description) {
1728
if (description.type == Description.HTML) {
1829
val styles = TextLinkStyles(SpanStyle(textDecoration = TextDecoration.Underline))
1930
AnnotatedString.fromHtml(description.content, styles)
2031
} else {
2132
AnnotatedString(description.content, ParagraphStyle())
2233
}
2334
}
35+
36+
Text(
37+
modifier = modifier,
38+
text = parsedDescription,
39+
maxLines = maxLines,
40+
style = style,
41+
overflow = overflow
42+
)
2443
}

app/src/main/java/org/schabi/newpipe/compose/status/LoadingIndicator.kt renamed to app/src/main/java/org/schabi/newpipe/compose/common/LoadingIndicator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.schabi.newpipe.compose.status
1+
package org.schabi.newpipe.compose.common
22

33
import androidx.compose.foundation.layout.fillMaxSize
44
import androidx.compose.foundation.layout.wrapContentSize

0 commit comments

Comments
 (0)