Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compose theme improvements #11539

Open
wants to merge 8 commits into
base: refactor
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.schabi.newpipe.fragments.list.comments
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
Expand All @@ -20,7 +19,7 @@ class CommentsFragment : Fragment() {
savedInstanceState: Bundle?
) = content {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
CommentSection()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.schabi.newpipe.fragments.list.videos
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
Expand All @@ -21,7 +20,7 @@ class RelatedItemsFragment : Fragment() {
savedInstanceState: Bundle?
) = content {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
RelatedItems(requireArguments().serializable<StreamInfo>(KEY_INFO)!!)
}
}
Expand Down
10 changes: 1 addition & 9 deletions app/src/main/java/org/schabi/newpipe/ui/Toolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SearchBar
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -91,14 +90,7 @@ fun Toolbar(
active = true,
onActiveChange = {
isSearchActive = it
},
colors = SearchBarDefaults.colors(
containerColor = MaterialTheme.colorScheme.background,
inputFieldColors = SearchBarDefaults.inputFieldColors(
focusedTextColor = MaterialTheme.colorScheme.onBackground,
unfocusedTextColor = MaterialTheme.colorScheme.onBackground
)
)
}
) {
onSearchQueryChange?.invoke(query)?.takeIf { it.isNotEmpty() }
?.map { suggestionText -> SearchSuggestionItem(text = suggestionText) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@ package org.schabi.newpipe.ui.components.common
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun LoadingIndicator(modifier: Modifier = Modifier) {
CircularProgressIndicator(
modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center),
color = MaterialTheme.colorScheme.primary,
trackColor = MaterialTheme.colorScheme.surfaceVariant,
)
CircularProgressIndicator(modifier = modifier.fillMaxSize().wrapContentSize(Alignment.Center))
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import my.nanihadesuka.compose.LazyColumnScrollbar
import my.nanihadesuka.compose.ScrollbarSettings

@Composable
Expand All @@ -20,7 +21,7 @@ fun LazyColumnThemedScrollbar(
indicatorContent: (@Composable (index: Int, isThumbSelected: Boolean) -> Unit)? = null,
content: @Composable () -> Unit
) {
my.nanihadesuka.compose.LazyColumnScrollbar(
LazyColumnScrollbar(
state = state,
modifier = modifier,
settings = settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private fun PlaylistListItemPreview() {
playlist.uploaderName = "Uploader"

AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
PlaylistListItem(playlist)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private fun StreamListItemPreview(
@PreviewParameter(StreamItemPreviewProvider::class) stream: StreamInfoItem
) {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
StreamListItem(stream, showProgress = false, isSelected = false)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package org.schabi.newpipe.ui.components.items.stream

import androidx.annotation.StringRes
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -34,8 +32,8 @@ fun StreamMenu(

DropdownMenu(expanded = expanded, onDismissRequest = onDismissRequest) {
if (playerHolder.isPlayQueueReady) {
StreamMenuItem(
text = R.string.enqueue_stream,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.enqueue_stream)) },
onClick = {
onDismissRequest()
SparseItemUtil.fetchItemInfoIfSparse(context, stream) {
Expand All @@ -45,8 +43,8 @@ fun StreamMenu(
)

if (playerHolder.queuePosition < playerHolder.queueSize - 1) {
StreamMenuItem(
text = R.string.enqueue_next_stream,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.enqueue_next_stream)) },
onClick = {
onDismissRequest()
SparseItemUtil.fetchItemInfoIfSparse(context, stream) {
Expand All @@ -57,26 +55,26 @@ fun StreamMenu(
}
}

StreamMenuItem(
text = R.string.start_here_on_background,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.start_here_on_background)) },
onClick = {
onDismissRequest()
SparseItemUtil.fetchItemInfoIfSparse(context, stream) {
NavigationHelper.playOnBackgroundPlayer(context, it, true)
}
}
)
StreamMenuItem(
text = R.string.start_here_on_popup,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.start_here_on_popup)) },
onClick = {
onDismissRequest()
SparseItemUtil.fetchItemInfoIfSparse(context, stream) {
NavigationHelper.playOnPopupPlayer(context, it, true)
}
}
)
StreamMenuItem(
text = R.string.download,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.download)) },
onClick = {
onDismissRequest()
SparseItemUtil.fetchStreamInfoAndSaveToDatabase(
Expand All @@ -89,8 +87,8 @@ fun StreamMenu(
}
}
)
StreamMenuItem(
text = R.string.add_to_playlist,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.add_to_playlist)) },
onClick = {
onDismissRequest()
val list = listOf(StreamEntity(stream))
Expand All @@ -103,29 +101,29 @@ fun StreamMenu(
}
}
)
StreamMenuItem(
text = R.string.share,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.share)) },
onClick = {
onDismissRequest()
ShareUtils.shareText(context, stream.name, stream.url, stream.thumbnails)
}
)
StreamMenuItem(
text = R.string.open_in_browser,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.open_in_browser)) },
onClick = {
onDismissRequest()
ShareUtils.openUrlInBrowser(context, stream.url)
}
)
StreamMenuItem(
text = R.string.mark_as_watched,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.mark_as_watched)) },
onClick = {
onDismissRequest()
streamViewModel.markAsWatched(stream)
}
)
StreamMenuItem(
text = R.string.show_channel_details,
DropdownMenuItem(
text = { Text(text = stringResource(R.string.show_channel_details)) },
onClick = {
onDismissRequest()
SparseItemUtil.fetchUploaderUrlIfSparse(
Expand All @@ -138,16 +136,3 @@ fun StreamMenu(
)
}
}

@Composable
private fun StreamMenuItem(
@StringRes text: Int,
onClick: () -> Unit
) {
DropdownMenuItem(
text = {
Text(text = stringResource(text), color = MaterialTheme.colorScheme.onBackground)
},
onClick = onClick
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
Expand Down Expand Up @@ -94,7 +93,7 @@ private fun RelatedItemsPreview() {
)

AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
RelatedItems(info)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private fun CommentPreview(
@PreviewParameter(CommentPreviewProvider::class) commentsInfoItem: CommentsInfoItem
) {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
Comment(commentsInfoItem) {}
}
}
Expand All @@ -267,7 +267,7 @@ private fun CommentPreview(
@Composable
private fun CommentListPreview() {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
Column {
for (comment in CommentPreviewProvider().values) {
Comment(comment) {}
Expand Down
Loading