1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-21 18:42:35 +01:00

Clean up unnecessary manual color specification in Compose code

This commit is contained in:
Isira Seneviratne 2024-11-16 16:09:10 +05:30
parent a56debfce6
commit 6ea715a18d
9 changed files with 63 additions and 85 deletions

View File

@ -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
@ -20,7 +19,7 @@ class CommentsFragment : Fragment() {
savedInstanceState: Bundle?
) = content {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
CommentSection()
}
}

View File

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

View File

@ -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
@ -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,

View File

@ -16,16 +16,15 @@ import androidx.compose.ui.platform.rememberNestedScrollInteropConnection
import androidx.compose.ui.res.stringResource
import androidx.preference.PreferenceManager
import androidx.window.core.layout.WindowWidthSizeClass
import my.nanihadesuka.compose.LazyColumnScrollbar
import org.schabi.newpipe.R
import org.schabi.newpipe.extractor.InfoItem
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem
import org.schabi.newpipe.extractor.stream.StreamInfoItem
import org.schabi.newpipe.info_list.ItemViewMode
import org.schabi.newpipe.ktx.findFragmentActivity
import org.schabi.newpipe.ui.components.common.LazyColumnThemedScrollbar
import org.schabi.newpipe.ui.components.items.playlist.PlaylistListItem
import org.schabi.newpipe.ui.components.items.stream.StreamListItem
import org.schabi.newpipe.ui.theme.NewPipeScrollbarSettings
import org.schabi.newpipe.util.DependentPreferenceHelper
import org.schabi.newpipe.util.NavigationHelper
@ -73,7 +72,7 @@ fun ItemList(
} else {
val state = rememberLazyListState()
LazyColumnScrollbar(state = state, settings = NewPipeScrollbarSettings) {
LazyColumnThemedScrollbar(state = state) {
LazyColumn(modifier = nestedScrollModifier, state = state) {
listHeader()

View File

@ -257,7 +257,7 @@ private fun CommentPreview(
@PreviewParameter(CommentPreviewProvider::class) commentsInfoItem: CommentsInfoItem
) {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
Comment(commentsInfoItem) {}
}
}
@ -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) {}

View File

@ -6,14 +6,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Text
import androidx.compose.material3.contentColorFor
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
@ -84,12 +81,6 @@ private fun CommentRepliesDialog(
ModalBottomSheet(
sheetState = sheetState,
onDismissRequest = onDismissRequest,
) {
CompositionLocalProvider(
// contentColorFor(MaterialTheme.colorScheme.containerColor), i.e. ModalBottomSheet's
// default background color, does not resolve correctly, so need to manually set the
// content color for MaterialTheme.colorScheme.background instead
LocalContentColor provides contentColorFor(MaterialTheme.colorScheme.background)
) {
LazyColumnThemedScrollbar(state = listState) {
LazyColumn(
@ -151,7 +142,6 @@ private fun CommentRepliesDialog(
}
}
}
}
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)

View File

@ -143,7 +143,7 @@ fun CommentRepliesHeaderPreview() {
)
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
CommentRepliesHeader(comment) {}
}
}

View File

@ -123,7 +123,7 @@ private fun CommentSection(
@Composable
private fun CommentSectionLoadingPreview() {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
CommentSection(uiState = Resource.Loading, commentsFlow = flowOf())
}
}
@ -151,7 +151,7 @@ private fun CommentSectionSuccessPreview() {
}
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
CommentSection(
uiState = Resource.Success(
CommentInfo(
@ -170,7 +170,7 @@ private fun CommentSectionSuccessPreview() {
@Composable
private fun CommentSectionErrorPreview() {
AppTheme {
Surface(color = MaterialTheme.colorScheme.background) {
Surface {
CommentSection(uiState = Resource.Error(RuntimeException()), commentsFlow = flowOf())
}
}

View File

@ -8,7 +8,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.preference.PreferenceManager
import my.nanihadesuka.compose.ScrollbarSettings
private val lightScheme = lightColorScheme(
primary = primaryLight,
@ -88,11 +87,6 @@ private val darkScheme = darkColorScheme(
private val blackScheme = darkScheme.copy(surface = Color.Black)
val NewPipeScrollbarSettings = ScrollbarSettings(
thumbSelectedColor = primaryDark,
thumbUnselectedColor = primaryLight
)
@Composable
fun AppTheme(useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LocalContext.current)