mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Improve code organization
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.ui | package org.schabi.newpipe.compose | ||||||
| 
 | 
 | ||||||
| import androidx.compose.foundation.layout.Box | import androidx.compose.foundation.layout.Box | ||||||
| import androidx.compose.foundation.layout.Column | import androidx.compose.foundation.layout.Column | ||||||
| @@ -27,8 +27,8 @@ import androidx.compose.ui.res.painterResource | |||||||
| import androidx.compose.ui.res.stringResource | import androidx.compose.ui.res.stringResource | ||||||
| import androidx.compose.ui.tooling.preview.Preview | import androidx.compose.ui.tooling.preview.Preview | ||||||
| import org.schabi.newpipe.R | import org.schabi.newpipe.R | ||||||
| import org.schabi.newpipe.ui.theme.AppTheme | import org.schabi.newpipe.compose.theme.AppTheme | ||||||
| import org.schabi.newpipe.ui.theme.SizeTokens | import org.schabi.newpipe.compose.theme.SizeTokens | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun TextAction(text: String, modifier: Modifier = Modifier) { | fun TextAction(text: String, modifier: Modifier = Modifier) { | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.fragments.list.comments | package org.schabi.newpipe.compose.comment | ||||||
| 
 | 
 | ||||||
| import android.content.res.Configuration | import android.content.res.Configuration | ||||||
| import androidx.compose.foundation.Image | import androidx.compose.foundation.Image | ||||||
| @@ -29,9 +29,6 @@ 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.pluralStringResource | ||||||
| import androidx.compose.ui.res.stringResource | import androidx.compose.ui.res.stringResource | ||||||
| import androidx.compose.ui.text.AnnotatedString |  | ||||||
| import androidx.compose.ui.text.ParagraphStyle |  | ||||||
| import androidx.compose.ui.text.fromHtml |  | ||||||
| import androidx.compose.ui.text.style.TextOverflow | import androidx.compose.ui.text.style.TextOverflow | ||||||
| import androidx.compose.ui.tooling.preview.Preview | import androidx.compose.ui.tooling.preview.Preview | ||||||
| import androidx.compose.ui.tooling.preview.PreviewParameter | import androidx.compose.ui.tooling.preview.PreviewParameter | ||||||
| @@ -42,26 +39,16 @@ import androidx.paging.Pager | |||||||
| import androidx.paging.PagingConfig | import androidx.paging.PagingConfig | ||||||
| import coil.compose.AsyncImage | import coil.compose.AsyncImage | ||||||
| import org.schabi.newpipe.R | import org.schabi.newpipe.R | ||||||
|  | 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 | ||||||
| import org.schabi.newpipe.ui.theme.AppTheme | import org.schabi.newpipe.paging.CommentsSource | ||||||
| import org.schabi.newpipe.util.Localization | import org.schabi.newpipe.util.Localization | ||||||
| import org.schabi.newpipe.util.NavigationHelper | import org.schabi.newpipe.util.NavigationHelper | ||||||
| import org.schabi.newpipe.util.image.ImageStrategy | import org.schabi.newpipe.util.image.ImageStrategy | ||||||
| 
 | 
 | ||||||
| @Composable |  | ||||||
| fun rememberParsedText(commentText: Description): AnnotatedString { |  | ||||||
|     // TODO: Handle links and hashtags, Markdown. |  | ||||||
|     return remember(commentText) { |  | ||||||
|         if (commentText.type == Description.HTML) { |  | ||||||
|             AnnotatedString.fromHtml(commentText.content) |  | ||||||
|         } else { |  | ||||||
|             AnnotatedString(commentText.content, ParagraphStyle()) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| @OptIn(ExperimentalMaterial3Api::class) | @OptIn(ExperimentalMaterial3Api::class) | ||||||
| @Composable | @Composable | ||||||
| fun Comment(comment: CommentsInfoItem) { | fun Comment(comment: CommentsInfoItem) { | ||||||
| @@ -112,7 +99,7 @@ fun Comment(comment: CommentsInfoItem) { | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             Text( |             Text( | ||||||
|                 text = rememberParsedText(comment.commentText), |                 text = rememberParsedDescription(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, | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.fragments.list.comments | package org.schabi.newpipe.compose.comment | ||||||
| 
 | 
 | ||||||
| import android.content.res.Configuration | import android.content.res.Configuration | ||||||
| import androidx.compose.foundation.Image | import androidx.compose.foundation.Image | ||||||
| @@ -25,9 +25,10 @@ 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.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.ui.theme.AppTheme |  | ||||||
| import org.schabi.newpipe.util.Localization | import org.schabi.newpipe.util.Localization | ||||||
| import org.schabi.newpipe.util.NavigationHelper | import org.schabi.newpipe.util.NavigationHelper | ||||||
| import org.schabi.newpipe.util.image.ImageStrategy | import org.schabi.newpipe.util.image.ImageStrategy | ||||||
| @@ -106,7 +107,7 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         Text( |         Text( | ||||||
|             text = rememberParsedText(comment.commentText), |             text = rememberParsedDescription(comment.commentText), | ||||||
|             style = MaterialTheme.typography.bodyMedium |             style = MaterialTheme.typography.bodyMedium | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.fragments.list.comments | package org.schabi.newpipe.compose.comment | ||||||
| 
 | 
 | ||||||
| import android.content.res.Configuration | import android.content.res.Configuration | ||||||
| import androidx.compose.foundation.layout.Column | import androidx.compose.foundation.layout.Column | ||||||
| @@ -28,14 +28,15 @@ import kotlinx.coroutines.flow.flowOf | |||||||
| import my.nanihadesuka.compose.LazyColumnScrollbar | import my.nanihadesuka.compose.LazyColumnScrollbar | ||||||
| import my.nanihadesuka.compose.ScrollbarSettings | import my.nanihadesuka.compose.ScrollbarSettings | ||||||
| import org.schabi.newpipe.R | import org.schabi.newpipe.R | ||||||
|  | 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 | ||||||
| import org.schabi.newpipe.ui.theme.AppTheme | import org.schabi.newpipe.paging.CommentsDisabledException | ||||||
| 
 | 
 | ||||||
| @Composable | @Composable | ||||||
| fun CommentSection( | fun CommentSection( | ||||||
|     flow: Flow<PagingData<CommentsInfoItem>>, |  | ||||||
|     parentComment: CommentsInfoItem? = null, |     parentComment: CommentsInfoItem? = null, | ||||||
|  |     flow: Flow<PagingData<CommentsInfoItem>> | ||||||
| ) { | ) { | ||||||
|     val replies = flow.collectAsLazyPagingItems() |     val replies = flow.collectAsLazyPagingItems() | ||||||
|     val itemCount by remember { derivedStateOf { replies.itemCount } } |     val itemCount by remember { derivedStateOf { replies.itemCount } } | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.ui.theme | package org.schabi.newpipe.compose.theme | ||||||
| 
 | 
 | ||||||
| import androidx.compose.ui.graphics.Color | import androidx.compose.ui.graphics.Color | ||||||
| 
 | 
 | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.ui.theme | package org.schabi.newpipe.compose.theme | ||||||
| 
 | 
 | ||||||
| import androidx.compose.ui.unit.dp | import androidx.compose.ui.unit.dp | ||||||
| 
 | 
 | ||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.ui.theme | package org.schabi.newpipe.compose.theme | ||||||
| 
 | 
 | ||||||
| import androidx.compose.foundation.isSystemInDarkTheme | import androidx.compose.foundation.isSystemInDarkTheme | ||||||
| import androidx.compose.material3.MaterialTheme | import androidx.compose.material3.MaterialTheme | ||||||
| @@ -0,0 +1,20 @@ | |||||||
|  | package org.schabi.newpipe.compose.util | ||||||
|  |  | ||||||
|  | import androidx.compose.runtime.Composable | ||||||
|  | import androidx.compose.runtime.remember | ||||||
|  | import androidx.compose.ui.text.AnnotatedString | ||||||
|  | import androidx.compose.ui.text.ParagraphStyle | ||||||
|  | import androidx.compose.ui.text.fromHtml | ||||||
|  | import org.schabi.newpipe.extractor.stream.Description | ||||||
|  |  | ||||||
|  | @Composable | ||||||
|  | fun rememberParsedDescription(description: Description): AnnotatedString { | ||||||
|  |     // TODO: Handle links and hashtags, Markdown. | ||||||
|  |     return remember(description) { | ||||||
|  |         if (description.type == Description.HTML) { | ||||||
|  |             AnnotatedString.fromHtml(description.content) | ||||||
|  |         } else { | ||||||
|  |             AnnotatedString(description.content, ParagraphStyle()) | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -11,7 +11,9 @@ import androidx.core.os.bundleOf | |||||||
| import androidx.fragment.app.Fragment | import androidx.fragment.app.Fragment | ||||||
| import androidx.paging.Pager | import androidx.paging.Pager | ||||||
| import androidx.paging.PagingConfig | import androidx.paging.PagingConfig | ||||||
| import org.schabi.newpipe.ui.theme.AppTheme | import org.schabi.newpipe.compose.comment.CommentSection | ||||||
|  | import org.schabi.newpipe.compose.theme.AppTheme | ||||||
|  | import org.schabi.newpipe.paging.CommentsSource | ||||||
| import org.schabi.newpipe.util.NO_SERVICE_ID | import org.schabi.newpipe.util.NO_SERVICE_ID | ||||||
|  |  | ||||||
| class CommentsFragment : Fragment() { | class CommentsFragment : Fragment() { | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| package org.schabi.newpipe.fragments.list.comments | package org.schabi.newpipe.paging | ||||||
| 
 | 
 | ||||||
| import androidx.paging.PagingState | import androidx.paging.PagingState | ||||||
| import androidx.paging.rxjava3.RxPagingSource | import androidx.paging.rxjava3.RxPagingSource | ||||||
		Reference in New Issue
	
	Block a user
	 Isira Seneviratne
					Isira Seneviratne