mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-01-11 09:50:32 +00:00
Added DescriptionText composable
This commit is contained in:
parent
f984b26626
commit
ea414f57d4
@ -42,8 +42,8 @@ import androidx.paging.PagingConfig
|
|||||||
import androidx.paging.cachedIn
|
import androidx.paging.cachedIn
|
||||||
import coil.compose.AsyncImage
|
import coil.compose.AsyncImage
|
||||||
import org.schabi.newpipe.R
|
import org.schabi.newpipe.R
|
||||||
|
import org.schabi.newpipe.compose.common.DescriptionText
|
||||||
import org.schabi.newpipe.compose.theme.AppTheme
|
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.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
|
||||||
@ -101,8 +101,8 @@ fun Comment(comment: CommentsInfoItem) {
|
|||||||
Text(text = nameAndDate, color = MaterialTheme.colorScheme.secondary)
|
Text(text = nameAndDate, color = MaterialTheme.colorScheme.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
DescriptionText(
|
||||||
text = rememberParsedDescription(comment.commentText),
|
description = comment.commentText,
|
||||||
// If the comment is expanded, we display all its content
|
// If the comment is expanded, we display all its content
|
||||||
// otherwise we only display the first two lines
|
// otherwise we only display the first two lines
|
||||||
maxLines = if (isExpanded) Int.MAX_VALUE else 2,
|
maxLines = if (isExpanded) Int.MAX_VALUE else 2,
|
||||||
|
@ -25,8 +25,8 @@ 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.compose.common.DescriptionText
|
||||||
import org.schabi.newpipe.compose.theme.AppTheme
|
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.comments.CommentsInfoItem
|
||||||
import org.schabi.newpipe.extractor.stream.Description
|
import org.schabi.newpipe.extractor.stream.Description
|
||||||
import org.schabi.newpipe.util.Localization
|
import org.schabi.newpipe.util.Localization
|
||||||
@ -102,8 +102,8 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
DescriptionText(
|
||||||
text = rememberParsedDescription(comment.commentText),
|
description = comment.commentText,
|
||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
import my.nanihadesuka.compose.LazyColumnScrollbar
|
import my.nanihadesuka.compose.LazyColumnScrollbar
|
||||||
import org.schabi.newpipe.R
|
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.compose.theme.AppTheme
|
||||||
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
|
||||||
|
@ -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.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.AnnotatedString
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.ParagraphStyle
|
import androidx.compose.ui.text.ParagraphStyle
|
||||||
import androidx.compose.ui.text.SpanStyle
|
import androidx.compose.ui.text.SpanStyle
|
||||||
import androidx.compose.ui.text.TextLinkStyles
|
import androidx.compose.ui.text.TextLinkStyles
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.fromHtml
|
import androidx.compose.ui.text.fromHtml
|
||||||
import androidx.compose.ui.text.style.TextDecoration
|
import androidx.compose.ui.text.style.TextDecoration
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import org.schabi.newpipe.extractor.stream.Description
|
import org.schabi.newpipe.extractor.stream.Description
|
||||||
|
|
||||||
@Composable
|
@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.
|
// TODO: Handle links and hashtags, Markdown.
|
||||||
return remember(description) {
|
val parsedDescription = remember(description) {
|
||||||
if (description.type == Description.HTML) {
|
if (description.type == Description.HTML) {
|
||||||
val styles = TextLinkStyles(SpanStyle(textDecoration = TextDecoration.Underline))
|
val styles = TextLinkStyles(SpanStyle(textDecoration = TextDecoration.Underline))
|
||||||
AnnotatedString.fromHtml(description.content, styles)
|
AnnotatedString.fromHtml(description.content, styles)
|
||||||
@ -21,4 +32,12 @@ fun rememberParsedDescription(description: Description): AnnotatedString {
|
|||||||
AnnotatedString(description.content, ParagraphStyle())
|
AnnotatedString(description.content, ParagraphStyle())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Text(
|
||||||
|
modifier = modifier,
|
||||||
|
text = parsedDescription,
|
||||||
|
maxLines = maxLines,
|
||||||
|
style = style,
|
||||||
|
overflow = overflow
|
||||||
|
)
|
||||||
}
|
}
|
@ -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.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.wrapContentSize
|
import androidx.compose.foundation.layout.wrapContentSize
|
Loading…
Reference in New Issue
Block a user