1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Improve code organization

This commit is contained in:
Isira Seneviratne 2024-06-28 07:57:25 +05:30
parent 909d214002
commit 369a46f8fe
10 changed files with 43 additions and 32 deletions

View File

@ -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.Column
@ -27,8 +27,8 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import org.schabi.newpipe.R
import org.schabi.newpipe.ui.theme.AppTheme
import org.schabi.newpipe.ui.theme.SizeTokens
import org.schabi.newpipe.compose.theme.AppTheme
import org.schabi.newpipe.compose.theme.SizeTokens
@Composable
fun TextAction(text: String, modifier: Modifier = Modifier) {

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.fragments.list.comments
package org.schabi.newpipe.compose.comment
import android.content.res.Configuration
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.pluralStringResource
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.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
@ -42,26 +39,16 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import coil.compose.AsyncImage
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.comments.CommentsInfoItem
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.NavigationHelper
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)
@Composable
fun Comment(comment: CommentsInfoItem) {
@ -112,7 +99,7 @@ fun Comment(comment: CommentsInfoItem) {
}
Text(
text = rememberParsedText(comment.commentText),
text = rememberParsedDescription(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,

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.fragments.list.comments
package org.schabi.newpipe.compose.comment
import android.content.res.Configuration
import androidx.compose.foundation.Image
@ -25,9 +25,10 @@ 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.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.ui.theme.AppTheme
import org.schabi.newpipe.util.Localization
import org.schabi.newpipe.util.NavigationHelper
import org.schabi.newpipe.util.image.ImageStrategy
@ -106,7 +107,7 @@ fun CommentRepliesHeader(comment: CommentsInfoItem) {
}
Text(
text = rememberParsedText(comment.commentText),
text = rememberParsedDescription(comment.commentText),
style = MaterialTheme.typography.bodyMedium
)
}

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.fragments.list.comments
package org.schabi.newpipe.compose.comment
import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
@ -28,14 +28,15 @@ import kotlinx.coroutines.flow.flowOf
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings
import org.schabi.newpipe.R
import org.schabi.newpipe.compose.theme.AppTheme
import org.schabi.newpipe.extractor.comments.CommentsInfoItem
import org.schabi.newpipe.extractor.stream.Description
import org.schabi.newpipe.ui.theme.AppTheme
import org.schabi.newpipe.paging.CommentsDisabledException
@Composable
fun CommentSection(
flow: Flow<PagingData<CommentsInfoItem>>,
parentComment: CommentsInfoItem? = null,
flow: Flow<PagingData<CommentsInfoItem>>
) {
val replies = flow.collectAsLazyPagingItems()
val itemCount by remember { derivedStateOf { replies.itemCount } }

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.ui.theme
package org.schabi.newpipe.compose.theme
import androidx.compose.ui.graphics.Color

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.ui.theme
package org.schabi.newpipe.compose.theme
import androidx.compose.ui.unit.dp

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.ui.theme
package org.schabi.newpipe.compose.theme
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme

View File

@ -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())
}
}
}

View File

@ -11,7 +11,9 @@ import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.paging.Pager
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
class CommentsFragment : Fragment() {

View File

@ -1,4 +1,4 @@
package org.schabi.newpipe.fragments.list.comments
package org.schabi.newpipe.paging
import androidx.paging.PagingState
import androidx.paging.rxjava3.RxPagingSource